Skip to content

Commit

Permalink
Add RoomEvent.SignalReconnecting and ConnectionState.SignalReconnecti…
Browse files Browse the repository at this point in the history
…ng (#1158)

* Add RoomEvent.Resuming and ConnectionState.Resuming

* Create rude-hounds-worry.md

* Rename to RoomEvent.SignalReconnecting

* Rename to SignalReconnecting

* typo copy

* fix changeset
  • Loading branch information
lukasIO authored Jun 14, 2024
1 parent 161e98d commit b81b612
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rude-hounds-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': minor
---

Add RoomEvent.SignalReconnecting and ConnectionState.SignalReconnecting
10 changes: 9 additions & 1 deletion src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -340,13 +341,19 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
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();
this.isResuming = false;
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 = [];
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/room/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit b81b612

Please sign in to comment.