webrtc: support WHIP/WHEP endpoints without PATCH support (#3273) (#3277)

This commit is contained in:
Alessandro Ros 2024-04-20 23:55:35 +02:00 committed by GitHub
parent 4ed1a39da2
commit bfa83fcd33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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