File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " livekit-client " : patch
3+ ---
4+
5+ Signal leave on failed connection attempts if signalling is connected
Original file line number Diff line number Diff line change @@ -740,7 +740,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
740740 `Initial connection failed with ConnectionError: ${ error . message } . Retrying with another region: ${ nextUrl } ` ,
741741 this . logContext ,
742742 ) ;
743- this . recreateEngine ( ) ;
743+ this . recreateEngine ( true ) ;
744744 await connectFn ( resolve , reject , nextUrl ) ;
745745 } else {
746746 this . handleDisconnect (
@@ -866,7 +866,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
866866 ) {
867867 this . log . info ( 'Reconnection attempt replaced by new connection attempt' , this . logContext ) ;
868868 // make sure we close and recreate the existing engine in order to get rid of any potentially ongoing reconnection attempts
869- this . recreateEngine ( ) ;
869+ this . recreateEngine ( true ) ;
870870 } else {
871871 // create engine if previously disconnected
872872 this . maybeCreateEngine ( ) ;
@@ -1380,8 +1380,14 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
13801380 ) ;
13811381 }
13821382
1383- private recreateEngine ( ) {
1384- this . engine ?. close ( ) ;
1383+ private recreateEngine ( sendLeave ?: boolean ) {
1384+ const oldEngine = this . engine ;
1385+
1386+ if ( sendLeave && oldEngine && ! oldEngine . client . isDisconnected ) {
1387+ oldEngine . client . sendLeave ( ) . finally ( ( ) => oldEngine . close ( ) ) ;
1388+ } else {
1389+ oldEngine ?. close ( ) ;
1390+ }
13851391 /* @ts -ignore */
13861392 this . engine = undefined ;
13871393 this . isResuming = false ;
You can’t perform that action at this time.
0 commit comments