Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/webrtc/whep.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func WHEPChangeLayer(whepSessionId, layer string) error {
if _, ok := streamMap[streamKey].whepSessions[whepSessionId]; ok {
streamMap[streamKey].whepSessions[whepSessionId].currentLayer.Store(layer)
streamMap[streamKey].whepSessions[whepSessionId].waitingForKeyframe.Store(true)
streamMap[streamKey].pliChan <- true
select {
case streamMap[streamKey].pliChan <- true:
default:
}
}
}

Expand Down
28 changes: 22 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func whipHandler(res http.ResponseWriter, r *http.Request) {
}

func whepHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != "POST" && req.Method != "PATCH" {
if req.Method != http.MethodPost {
return
}

Expand All @@ -145,11 +145,6 @@ func whepHandler(res http.ResponseWriter, req *http.Request) {
return
}

if req.Method == "PATCH" {
patchHandler(res, req, "TODO", string(body), true)
return
}

answer, whepSessionId, err := webrtc.WHEP(string(body), streamKey)
if err != nil {
logHTTPError(res, err.Error(), http.StatusBadRequest)
Expand All @@ -167,6 +162,26 @@ func whepHandler(res http.ResponseWriter, req *http.Request) {
}
}

func whepSessionPatchHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPatch {
return
}

whepSessionId := strings.TrimPrefix(req.URL.Path, "/api/whep/")
if whepSessionId == "" {
logHTTPError(res, "missing WHEP session id", http.StatusBadRequest)
return
}

body, err := io.ReadAll(req.Body)
if err != nil {
logHTTPError(res, err.Error(), http.StatusBadRequest)
return
}

patchHandler(res, req, whepSessionId, string(body), false)
}

func whepServerSentEventsHandler(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/event-stream")
res.Header().Set("Cache-Control", "no-cache")
Expand Down Expand Up @@ -320,6 +335,7 @@ func main() {
}
mux.HandleFunc("/api/whip", corsHandler(whipHandler))
mux.HandleFunc("/api/whep", corsHandler(whepHandler))
mux.HandleFunc("/api/whep/", corsHandler(whepSessionPatchHandler))
mux.HandleFunc("/api/sse/", corsHandler(whepServerSentEventsHandler))
mux.HandleFunc("/api/layer/", corsHandler(whepLayerHandler))
mux.HandleFunc("/api/status", corsHandler(statusHandler))
Expand Down