@@ -4,10 +4,13 @@ import {
44 AudioTrackFeature ,
55 ClientInfo ,
66 ConnectionQualityUpdate ,
7+ ConnectionSettings ,
78 DisconnectReason ,
9+ JoinRequest ,
810 JoinResponse ,
911 LeaveRequest ,
1012 LeaveRequest_Action ,
13+ MediaSectionsRequirement ,
1114 MuteTrackRequest ,
1215 ParticipantInfo ,
1316 Ping ,
@@ -38,6 +41,7 @@ import {
3841 UpdateTrackSettings ,
3942 UpdateVideoLayers ,
4043 VideoLayer ,
44+ WrappedJoinRequest ,
4145 protoInt64 ,
4246} from '@livekit/protocol' ;
4347import log , { LoggerNames , getLogger } from '../logger' ;
@@ -66,6 +70,7 @@ export interface SignalOptions {
6670 maxRetries : number ;
6771 e2eeEnabled : boolean ;
6872 websocketTimeout : number ;
73+ singlePeerConnection : boolean ;
6974}
7075
7176type SignalMessage = SignalRequest [ 'message' ] ;
@@ -155,6 +160,8 @@ export class SignalClient {
155160
156161 onRoomMoved ?: ( res : RoomMovedResponse ) => void ;
157162
163+ onMediaSectionsRequirement ?: ( requirement : MediaSectionsRequirement ) => void ;
164+
158165 connectOptions ?: ConnectOpts ;
159166
160167 ws ?: WebSocketStream ;
@@ -271,7 +278,9 @@ export class SignalClient {
271278
272279 this . connectOptions = opts ;
273280 const clientInfo = getClientInfo ( ) ;
274- const params = createConnectionParams ( token , clientInfo , opts ) ;
281+ const params = opts . singlePeerConnection
282+ ? createJoinRequestConnectionParams ( token , clientInfo , opts )
283+ : createConnectionParams ( token , clientInfo , opts ) ;
275284 const rtcUrl = createRtcUrl ( url , params ) ;
276285 const validateUrl = createValidateUrl ( rtcUrl ) ;
277286
@@ -459,6 +468,7 @@ export class SignalClient {
459468 this . onTokenRefresh = undefined ;
460469 this . onTrickle = undefined ;
461470 this . onClose = undefined ;
471+ this . onMediaSectionsRequirement = undefined ;
462472 } ;
463473
464474 async close ( updateState : boolean = true ) {
@@ -772,6 +782,10 @@ export class SignalClient {
772782 if ( this . onRoomMoved ) {
773783 this . onRoomMoved ( msg . value ) ;
774784 }
785+ } else if ( msg . case === 'mediaSectionsRequirement' ) {
786+ if ( this . onMediaSectionsRequirement ) {
787+ this . onMediaSectionsRequirement ( msg . value ) ;
788+ }
775789 } else {
776790 this . log . debug ( 'unsupported message' , { ...this . logContext , msgCase : msg . case } ) ;
777791 }
@@ -1063,3 +1077,31 @@ function createConnectionParams(
10631077
10641078 return params ;
10651079}
1080+
1081+ function createJoinRequestConnectionParams (
1082+ token : string ,
1083+ info : ClientInfo ,
1084+ opts : ConnectOpts ,
1085+ ) : URLSearchParams {
1086+ const params = new URLSearchParams ( ) ;
1087+ params . set ( 'access_token' , token ) ;
1088+
1089+ const joinRequest = new JoinRequest ( {
1090+ clientInfo : info ,
1091+ connectionSettings : new ConnectionSettings ( {
1092+ autoSubscribe : ! ! opts . autoSubscribe ,
1093+ adaptiveStream : ! ! opts . adaptiveStream ,
1094+ } ) ,
1095+ reconnect : ! ! opts . reconnect ,
1096+ participantSid : opts . sid ? opts . sid : undefined ,
1097+ } ) ;
1098+ if ( opts . reconnectReason ) {
1099+ joinRequest . reconnectReason = opts . reconnectReason ;
1100+ }
1101+ const wrappedJoinRequest = new WrappedJoinRequest ( {
1102+ joinRequest : joinRequest . toBinary ( ) ,
1103+ } ) ;
1104+ params . set ( 'join_request' , btoa ( new TextDecoder ( 'utf-8' ) . decode ( wrappedJoinRequest . toBinary ( ) ) ) ) ;
1105+
1106+ return params ;
1107+ }
0 commit comments