@@ -30,12 +30,15 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
3030 public readonly events = mitt < CommsAdapterEvents > ( )
3131
3232 private disposed = false
33- private readonly room : Room
3433 private voiceHandler : VoiceHandler
3534
36- constructor ( private config : LivekitConfig ) {
37- this . room = new Room ( )
35+ static async init ( config : LivekitConfig ) {
36+ const room = new Room ( )
37+ const sid = await room . getSid ( )
38+ return new LivekitAdapter ( config , room , sid )
39+ }
3840
41+ private constructor ( private config : LivekitConfig , private readonly room : Room , private sid : string ) {
3942 this . voiceHandler = createLiveKitVoiceHandler ( this . room , this . config . globalAudioStream )
4043
4144 this . room
@@ -58,13 +61,13 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
5861
5962 this . config . logger . log ( this . room . name , 'disconnected from room' , reason , {
6063 liveKitParticipantSid : this . room . localParticipant . sid ,
61- liveKitRoomSid : this . room . sid
64+ liveKitRoomSid : this . sid
6265 } )
6366 trackEvent ( 'disconnection_cause' , {
6467 context : 'livekit-adapter' ,
6568 message : `Got RoomEvent.Disconnected. Reason: ${ reason } ` ,
6669 liveKitParticipantSid : this . room . localParticipant . sid ,
67- liveKitRoomSid : this . room . sid
70+ liveKitRoomSid : this . sid
6871 } )
6972 const kicked = reason === DisconnectReason . DUPLICATE_IDENTITY
7073 this . do_disconnect ( kicked ) . catch ( ( err ) => {
@@ -108,14 +111,14 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
108111 }
109112
110113 try {
111- await this . room . localParticipant . publishData ( data , reliable ? DataPacket_Kind . RELIABLE : DataPacket_Kind . LOSSY )
114+ await this . room . localParticipant . publishData ( data , { reliable } )
112115 } catch ( err : any ) {
113116 // NOTE: for tracking purposes only, this is not a "code" error, this is a failed connection or a problem with the livekit instance
114117 trackEvent ( 'error' , {
115118 context : 'livekit-adapter' ,
116119 message : `Error trying to send data. Reason: ${ err . message } ` ,
117120 stack : err . stack ,
118- saga_stack : `room session id: ${ this . room . sid } , participant id: ${ this . room . localParticipant . sid } , state: ${ state } `
121+ saga_stack : `room session id: ${ this . sid } , participant id: ${ this . room . localParticipant . sid } , state: ${ state } `
119122 } )
120123 await this . disconnect ( )
121124 }
@@ -144,12 +147,12 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
144147
145148 getActiveVideoStreams ( ) : Map < string , ActiveVideoStreams > {
146149 const result = new Map < string , ActiveVideoStreams > ( )
147- const participants = this . room . participants
150+ const participants = this . room . remoteParticipants
148151
149152 for ( const [ sid , participant ] of participants ) {
150- if ( participant . videoTracks . size > 0 ) {
153+ if ( participant . videoTrackPublications . size > 0 ) {
151154 const participantTracks = new Map < string , Track > ( )
152- for ( const [ videoSid , track ] of participant . videoTracks ) {
155+ for ( const [ videoSid , track ] of participant . videoTrackPublications ) {
153156 if ( track . videoTrack ?. mediaStream ) {
154157 participantTracks . set ( videoSid , track . videoTrack )
155158 }
0 commit comments