@@ -32,6 +32,7 @@ import {
32
32
import { EngineEvent } from './events' ;
33
33
import PCTransport , { PCEvents } from './PCTransport' ;
34
34
import type { ReconnectContext , ReconnectPolicy } from './ReconnectPolicy' ;
35
+ import CriticalTimers from './timers' ;
35
36
import type LocalTrack from './track/LocalTrack' ;
36
37
import type LocalVideoTrack from './track/LocalVideoTrack' ;
37
38
import type { SimulcastTrackInfo } from './track/LocalVideoTrack' ;
@@ -710,10 +711,11 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
710
711
711
712
log . debug ( `reconnecting in ${ delay } ms` ) ;
712
713
713
- if ( this . reconnectTimeout ) {
714
- clearTimeout ( this . reconnectTimeout ) ;
715
- }
716
- this . reconnectTimeout = setTimeout ( ( ) => this . attemptReconnect ( signalEvents ) , delay ) ;
714
+ this . clearReconnectTimeout ( ) ;
715
+ this . reconnectTimeout = CriticalTimers . setTimeout (
716
+ ( ) => this . attemptReconnect ( signalEvents ) ,
717
+ delay ,
718
+ ) ;
717
719
} ;
718
720
719
721
private async attemptReconnect ( signalEvents : boolean = false ) {
@@ -740,11 +742,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
740
742
} else {
741
743
await this . resumeConnection ( signalEvents ) ;
742
744
}
743
- this . reconnectAttempts = 0 ;
745
+ this . clearPendingReconnect ( ) ;
744
746
this . fullReconnectOnNext = false ;
745
- if ( this . reconnectTimeout ) {
746
- clearTimeout ( this . reconnectTimeout ) ;
747
- }
748
747
} catch ( e ) {
749
748
this . reconnectAttempts += 1 ;
750
749
let reconnectRequired = false ;
@@ -1046,19 +1045,21 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1046
1045
}
1047
1046
}
1048
1047
1049
- private clearPendingReconnect ( ) {
1048
+ private clearReconnectTimeout ( ) {
1050
1049
if ( this . reconnectTimeout ) {
1051
- clearTimeout ( this . reconnectTimeout ) ;
1050
+ CriticalTimers . clearTimeout ( this . reconnectTimeout ) ;
1052
1051
}
1052
+ }
1053
+
1054
+ private clearPendingReconnect ( ) {
1055
+ this . clearReconnectTimeout ( ) ;
1053
1056
this . reconnectAttempts = 0 ;
1054
1057
}
1055
1058
1056
1059
private handleBrowserOnLine = ( ) => {
1057
1060
// in case the engine is currently reconnecting, attempt a reconnect immediately after the browser state has changed to 'onLine'
1058
1061
if ( this . client . isReconnecting ) {
1059
- if ( this . reconnectTimeout ) {
1060
- clearTimeout ( this . reconnectTimeout ) ;
1061
- }
1062
+ this . clearReconnectTimeout ( ) ;
1062
1063
this . attemptReconnect ( true ) ;
1063
1064
}
1064
1065
} ;
0 commit comments