From bfa83fcd33401105646481e4daf7877141095dd0 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sat, 20 Apr 2024 23:55:35 +0200 Subject: [PATCH] webrtc: support WHIP/WHEP endpoints without PATCH support (#3273) (#3277) --- internal/protocols/webrtc/whip_client.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/protocols/webrtc/whip_client.go b/internal/protocols/webrtc/whip_client.go index 6feb51f2..04bc5757 100644 --- a/internal/protocols/webrtc/whip_client.go +++ b/internal/protocols/webrtc/whip_client.go @@ -23,7 +23,8 @@ type WHIPClient struct { URL *url.URL Log logger.Writer - pc *PeerConnection + pc *PeerConnection + patchIsSupported bool } // Publish publishes tracks. @@ -290,10 +291,7 @@ func (c *WHIPClient) postOffer( return nil, fmt.Errorf("bad Content-Type: expected 'application/sdp', got '%s'", contentType) } - acceptPatch := res.Header.Get("Accept-Patch") - if acceptPatch != "application/trickle-ice-sdpfrag" { - return nil, fmt.Errorf("wrong Accept-Patch: expected 'application/trickle-ice-sdpfrag', got '%s'", acceptPatch) - } + c.patchIsSupported = (res.Header.Get("Accept-Patch") == "application/trickle-ice-sdpfrag") Location := res.Header.Get("Location") @@ -325,6 +323,10 @@ func (c *WHIPClient) patchCandidate( etag string, candidate *webrtc.ICECandidateInit, ) error { + if !c.patchIsSupported { + return nil + } + frag, err := ICEFragmentMarshal(offer.SDP, []*webrtc.ICECandidateInit{candidate}) if err != nil { return err