diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index 0e64d49465..0de10587ae 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -149,6 +149,13 @@ export class SignalClient { return this.state; } + get isDisconnected() { + return ( + this.state === SignalConnectionState.DISCONNECTING || + this.state === SignalConnectionState.DISCONNECTED + ); + } + private options?: SignalOptions; private pingTimeout: ReturnType | undefined; diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 494389e67d..242f7ff8ee 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -871,7 +871,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit log.info(`reconnecting, attempt: ${this.reconnectAttempts}`); this.emit(EngineEvent.Restarting); - if (this.client.currentState < SignalConnectionState.DISCONNECTING) { + if (!this.client.isDisconnected) { await this.client.sendLeave(); } await this.cleanupPeerConnections(); diff --git a/src/room/Room.ts b/src/room/Room.ts index 4e6268ce49..d600fdb58b 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -2,7 +2,6 @@ import { protoInt64 } from '@bufbuild/protobuf'; import { EventEmitter } from 'events'; import type TypedEmitter from 'typed-emitter'; import 'webrtc-adapter'; -import { SignalConnectionState } from '../api/SignalClient'; import { EncryptionEvent } from '../e2ee'; import { E2EEManager } from '../e2ee/E2eeManager'; import log from '../logger'; @@ -665,7 +664,7 @@ class Room extends (EventEmitter as new () => TypedEmitter) this.connectFuture = undefined; } // send leave - if (this.engine?.client.currentState < SignalConnectionState.DISCONNECTING) { + if (!this.engine?.client.isDisconnected) { await this.engine.client.sendLeave(); } // close engine (also closes client) diff --git a/src/room/participant/LocalParticipant.ts b/src/room/participant/LocalParticipant.ts index 93e909e5e6..938a172d01 100644 --- a/src/room/participant/LocalParticipant.ts +++ b/src/room/participant/LocalParticipant.ts @@ -1,4 +1,3 @@ -import { SignalConnectionState } from '../../api/SignalClient'; import log from '../../logger'; import type { InternalRoomOptions } from '../../options'; import { @@ -1130,7 +1129,7 @@ export default class LocalParticipant extends Participant { ) { this.participantTrackPermissions = participantTrackPermissions; this.allParticipantsAllowedToSubscribe = allParticipantsAllowed; - if (this.engine.client.currentState < SignalConnectionState.DISCONNECTING) { + if (!this.engine.client.isDisconnected) { this.updateTrackSubscriptionPermissions(); } }