Skip to content

Commit

Permalink
avoid enum math
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Nov 30, 2023
1 parent dd6e004 commit dc77f24
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout> | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -665,7 +664,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
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)
Expand Down
3 changes: 1 addition & 2 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SignalConnectionState } from '../../api/SignalClient';
import log from '../../logger';
import type { InternalRoomOptions } from '../../options';
import {
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit dc77f24

Please sign in to comment.