@@ -140,12 +140,12 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
140
140
...options ?. publishDefaults ,
141
141
} ;
142
142
143
- this . createEngine ( ) ;
143
+ this . maybeCreateEngine ( ) ;
144
144
145
145
this . localParticipant = new LocalParticipant ( '' , '' , this . engine , this . options ) ;
146
146
}
147
147
148
- private createEngine ( ) {
148
+ private maybeCreateEngine ( ) {
149
149
if ( this . engine ) {
150
150
return ;
151
151
}
@@ -190,7 +190,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
190
190
. on ( EngineEvent . Restarted , this . handleRestarted ) ;
191
191
192
192
if ( this . localParticipant ) {
193
- this . localParticipant . engine = this . engine ;
193
+ this . localParticipant . setupEngine ( this . engine ) ;
194
194
}
195
195
}
196
196
@@ -231,17 +231,22 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
231
231
if ( this . connectFuture ) {
232
232
return this . connectFuture . promise ;
233
233
}
234
- if ( this . state === ConnectionState . Reconnecting ) {
235
- log . info ( 'Reconnection attempt replaced by new connection attempt' ) ;
236
- }
234
+
235
+ this . setAndEmitConnectionState ( ConnectionState . Connecting ) ;
236
+
237
237
const connectFn = async ( resolve : ( ) => void , reject : ( reason : any ) => void ) => {
238
- this . setAndEmitConnectionState ( ConnectionState . Connecting ) ;
239
238
if ( ! this . abortController || this . abortController . signal . aborted ) {
240
239
this . abortController = new AbortController ( ) ;
241
240
}
242
241
243
- // recreate engine if previously disconnected
244
- this . recreateEngine ( ) ;
242
+ if ( this . state === ConnectionState . Reconnecting ) {
243
+ log . info ( 'Reconnection attempt replaced by new connection attempt' ) ;
244
+ // make sure we close and recreate the existing engine in order to get rid of any potentially ongoing reconnection attempts
245
+ this . recreateEngine ( ) ;
246
+ } else {
247
+ // create engine if previously disconnected
248
+ this . maybeCreateEngine ( ) ;
249
+ }
245
250
246
251
this . acquireAudioContext ( ) ;
247
252
@@ -599,8 +604,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
599
604
// clear out existing remote participants, since they may have attached
600
605
// the old engine
601
606
this . participants . clear ( ) ;
602
-
603
- this . createEngine ( ) ;
607
+ this . maybeCreateEngine ( ) ;
604
608
}
605
609
606
610
private onTrackAdded (
0 commit comments