diff --git a/.changeset/rude-hounds-worry.md b/.changeset/rude-hounds-worry.md new file mode 100644 index 0000000000..45b5e9a214 --- /dev/null +++ b/.changeset/rude-hounds-worry.md @@ -0,0 +1,5 @@ +--- +'livekit-client': minor +--- + +Add RoomEvent.SignalReconnecting and ConnectionState.SignalReconnecting diff --git a/src/room/Room.ts b/src/room/Room.ts index 1dd05df90c..63d6bf5607 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -88,9 +88,10 @@ export enum ConnectionState { Connecting = 'connecting', Connected = 'connected', Reconnecting = 'reconnecting', + SignalReconnecting = 'signalReconnecting', } -const connectionReconcileFrequency = 2 * 1000; +const connectionReconcileFrequency = 4 * 1000; /** * In LiveKit, a room is the logical grouping for a list of participants. @@ -340,6 +341,9 @@ class Room extends (EventEmitter as new () => TypedEmitter) this.clearConnectionReconcile(); this.isResuming = true; this.log.info('Resuming signal connection', this.logContext); + if (this.setAndEmitConnectionState(ConnectionState.SignalReconnecting)) { + this.emit(RoomEvent.SignalReconnecting); + } }) .on(EngineEvent.Resumed, () => { this.registerConnectionReconcile(); @@ -347,6 +351,9 @@ class Room extends (EventEmitter as new () => TypedEmitter) this.log.info('Resumed signal connection', this.logContext); this.updateSubscriptions(); this.emitBufferedEvents(); + if (this.setAndEmitConnectionState(ConnectionState.Connected)) { + this.emit(RoomEvent.Reconnected); + } }) .on(EngineEvent.SignalResumed, () => { this.bufferedEvents = []; @@ -2079,6 +2086,7 @@ export default Room; export type RoomEventCallbacks = { connected: () => void; reconnecting: () => void; + signalReconnecting: () => void; reconnected: () => void; disconnected: (reason?: DisconnectReason) => void; connectionStateChanged: (state: ConnectionState) => void; diff --git a/src/room/events.ts b/src/room/events.ts index 5a13073b50..03062d2f0f 100644 --- a/src/room/events.ts +++ b/src/room/events.ts @@ -20,6 +20,13 @@ export enum RoomEvent { */ Reconnecting = 'reconnecting', + /** + * When the signal connection to the server has been interrupted. This isn't noticeable to users most of the time. + * It will resolve with a `RoomEvent.Reconnected` once the signal connection has been re-established. + * If media fails additionally it an additional `RoomEvent.Reconnecting` will be emitted. + */ + SignalReconnecting = 'signalReconnecting', + /** * Fires when a reconnection has been successful. */