@@ -24,7 +24,6 @@ import (
2424
2525 "github.com/pion/webrtc/v4"
2626 "go.uber.org/atomic"
27- "golang.org/x/mod/semver"
2827 "google.golang.org/protobuf/encoding/protojson"
2928 "google.golang.org/protobuf/proto"
3029
@@ -72,6 +71,7 @@ type engineHandler interface {
7271 OnStreamTrailer (* livekit.DataStream_Trailer )
7372 OnLocalTrackSubscribed (trackSubscribed * livekit.TrackSubscribed )
7473 OnSubscribedQualityUpdate (subscribedQualityUpdate * livekit.SubscribedQualityUpdate )
74+ OnMediaSectionsRequirement (mediaSectionsRequirement * livekit.MediaSectionsRequirement )
7575}
7676
7777type nullEngineHandler struct {}
@@ -103,6 +103,8 @@ func (n *nullEngineHandler) OnStreamTrailer(*livekit.DataStream_Trailer)
103103func (n * nullEngineHandler ) OnLocalTrackSubscribed (trackSubscribed * livekit.TrackSubscribed ) {}
104104func (n * nullEngineHandler ) OnSubscribedQualityUpdate (subscribedQualityUpdate * livekit.SubscribedQualityUpdate ) {
105105}
106+ func (n * nullEngineHandler ) OnMediaSectionsRequirement (mediaSectionsRequirement * livekit.MediaSectionsRequirement ) {
107+ }
106108
107109// -------------------------------------------
108110
@@ -125,6 +127,7 @@ const (
125127type RTCEngine struct {
126128 log protoLogger.Logger
127129
130+ useSinglePeerConnection bool
128131 engineHandler engineHandler
129132 cbGetLocalParticipantSID func () string
130133
@@ -166,18 +169,20 @@ type RTCEngine struct {
166169}
167170
168171func NewRTCEngine (
172+ useSinglePeerConnection bool ,
169173 engineHandler engineHandler ,
170174 getLocalParticipantSID func () string ,
171175) * RTCEngine {
172176 e := & RTCEngine {
173177 log : logger ,
178+ useSinglePeerConnection : useSinglePeerConnection ,
174179 engineHandler : engineHandler ,
175180 cbGetLocalParticipantSID : getLocalParticipantSID ,
176181 trackPublishedListeners : make (map [string ]chan * livekit.TrackPublishedResponse ),
177182 joinTimeout : 15 * time .Second ,
178183 reliableMsgSeq : 1 ,
179184 }
180- if semver . Compare ( "v" + Version , "v3.0.0" ) < 0 {
185+ if ! useSinglePeerConnection {
181186 e .signalling = signalling .NewSignalling (signalling.SignallingParams {
182187 Logger : e .log ,
183188 })
@@ -299,7 +304,7 @@ func (e *RTCEngine) IsConnected() bool {
299304 e .pclock .Lock ()
300305 defer e .pclock .Unlock ()
301306
302- if e .publisher == nil || e . subscriber == nil {
307+ if e .publisher == nil || ( ! e . useSinglePeerConnection && e . subscriber == nil ) {
303308 return false
304309 }
305310 if e .subscriberPrimary {
@@ -445,6 +450,10 @@ func (e *RTCEngine) createPublisherPCLocked(configuration webrtc.Configuration)
445450}
446451
447452func (e * RTCEngine ) createSubscriberPCLocked (configuration webrtc.Configuration ) error {
453+ if e .useSinglePeerConnection {
454+ return nil
455+ }
456+
448457 var err error
449458 if e .subscriber , err = NewPCTransport (PCTransportParams {
450459 Configuration : configuration ,
@@ -817,6 +826,7 @@ func (e *RTCEngine) createSubscriberPCAnswerAndSend() error {
817826 e .log .Errorw ("could not set subscriber local description" , err )
818827 return err
819828 }
829+ e .log .Debugw ("sending answer for subscriber" , "answer" , answer )
820830 if err := e .signalTransport .SendMessage (
821831 e .signalling .SignalSdpAnswer (
822832 protosignalling .ToProtoSessionDescription (answer , 0 ),
@@ -1242,14 +1252,18 @@ func (e *RTCEngine) OnReconnectResponse(res *livekit.ReconnectResponse) error {
12421252 e .pclock .Lock ()
12431253 defer e .pclock .Unlock ()
12441254
1245- if err := e .publisher .SetConfiguration (configuration ); err != nil {
1246- e .log .Errorw ("could not set rtc configuration for publisher" , err )
1247- return err
1255+ if e .publisher != nil {
1256+ if err := e .publisher .SetConfiguration (configuration ); err != nil {
1257+ e .log .Errorw ("could not set rtc configuration for publisher" , err )
1258+ return err
1259+ }
12481260 }
12491261
1250- if err := e .subscriber .SetConfiguration (configuration ); err != nil {
1251- e .log .Errorw ("could not set rtc configuration for subscriber" , err )
1252- return err
1262+ if e .subscriber != nil {
1263+ if err := e .subscriber .SetConfiguration (configuration ); err != nil {
1264+ e .log .Errorw ("could not set rtc configuration for subscriber" , err )
1265+ return err
1266+ }
12531267 }
12541268
12551269 return nil
@@ -1274,7 +1288,7 @@ func (e *RTCEngine) OnOffer(sd webrtc.SessionDescription, offerId uint32) {
12741288 return
12751289 }
12761290
1277- e .log .Debugw ("received offer for subscriber" )
1291+ e .log .Debugw ("received offer for subscriber" , "offer" , sd , "offerId" , offerId )
12781292 if err := e .subscriber .SetRemoteDescription (sd ); err != nil {
12791293 e .log .Errorw ("could not set remote description" , err )
12801294 return
@@ -1371,6 +1385,10 @@ func (e *RTCEngine) OnSubscribedQualityUpdate(subscribedQualityUpdate *livekit.S
13711385 e .engineHandler .OnSubscribedQualityUpdate (subscribedQualityUpdate )
13721386}
13731387
1388+ func (e * RTCEngine ) OnMediaSectionsRequirement (mediaSectionsRequirement * livekit.MediaSectionsRequirement ) {
1389+ e .engineHandler .OnMediaSectionsRequirement (mediaSectionsRequirement )
1390+ }
1391+
13741392// ------------------------------------
13751393
13761394func setConfiguration (pcTransport * PCTransport , configuration webrtc.Configuration ) {
0 commit comments