@@ -17,7 +17,7 @@ import (
1717)
1818
1919func WhipHandler (responseWriter http.ResponseWriter , request * http.Request ) {
20- if request .Method != "POST" && request .Method != "PATCH" {
20+ if request .Method != "POST" && request .Method != "PATCH" && request . Method != "DELETE" {
2121 return
2222 }
2323
@@ -35,6 +35,24 @@ func WhipHandler(responseWriter http.ResponseWriter, request *http.Request) {
3535 return
3636 }
3737
38+ if request .Method == "DELETE" {
39+ sessionId := getSessionIdFromWhipPath (request .URL .Path )
40+
41+ if sessionId == "" {
42+ log .Println ("API.WHIP.Delete Error: Missing session id" )
43+ helpers .LogHttpError (responseWriter , "Missing session id" , http .StatusBadRequest )
44+ return
45+ }
46+
47+ log .Println ("API.WHIP.Delete: Removing session" , sessionId )
48+ if err := deleteHandler (responseWriter , sessionId ); err != nil {
49+ log .Println ("API.WHIP.Delete Error:" , err )
50+ helpers .LogHttpError (responseWriter , err .Error (), http .StatusBadRequest )
51+ }
52+
53+ return
54+ }
55+
3856 offer , err := io .ReadAll (request .Body )
3957 if err != nil || string (offer ) == "" {
4058 log .Println ("Error reading offer" )
@@ -106,9 +124,7 @@ func WhipHandler(responseWriter http.ResponseWriter, request *http.Request) {
106124 return
107125 }
108126
109- path := strings .Replace (request .URL .Path , "/api/whip" , "" , 1 )
110- segments := strings .Split (path , "/" )
111- sessionId := strings .TrimSpace (segments [len (segments )- 1 ])
127+ sessionId := getSessionIdFromWhipPath (request .URL .Path )
112128
113129 if sessionId == "" {
114130 log .Println ("API.WHIP.Patch Error: Missing session id" )
@@ -159,3 +175,19 @@ func patchHandler(res http.ResponseWriter, r *http.Request, sessionId, body stri
159175
160176 return nil
161177}
178+
179+ func deleteHandler (res http.ResponseWriter , sessionId string ) error {
180+ if err := webrtc .HandleWhipDelete (sessionId ); err != nil {
181+ return err
182+ }
183+
184+ res .WriteHeader (http .StatusNoContent )
185+
186+ return nil
187+ }
188+
189+ func getSessionIdFromWhipPath (path string ) string {
190+ path = strings .Replace (path , "/api/whip" , "" , 1 )
191+ segments := strings .Split (path , "/" )
192+ return strings .TrimSpace (segments [len (segments )- 1 ])
193+ }
0 commit comments