Skip to content

Commit

Permalink
Make sure reconnect future is set to undefined when rejected (#463)
Browse files Browse the repository at this point in the history
* make sure reconnect future is set to undefined when rejected

* changeset

* always clear both futures
  • Loading branch information
lukasIO authored Oct 4, 2022
1 parent 5024e26 commit 90260b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-planets-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Fix: reset connect future to undefined when promise is rejected
15 changes: 12 additions & 3 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
.on(EngineEvent.DataPacketReceived, this.handleDataPacket)
.on(EngineEvent.Resuming, () => {
if (!this.reconnectFuture) {
this.reconnectFuture = new Future();
this.reconnectFuture = new Future(undefined, () => {
this.clearConnectionFutures();
});
}
if (this.setAndEmitConnectionState(ConnectionState.Reconnecting)) {
this.emit(RoomEvent.Reconnecting);
Expand Down Expand Up @@ -359,7 +361,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
});
};
this.connectFuture = new Future(connectFn, () => {
this.connectFuture = undefined;
this.clearConnectionFutures();
this.emit(RoomEvent.Connected);
});

Expand Down Expand Up @@ -407,6 +409,11 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
}
}

private clearConnectionFutures() {
this.connectFuture = undefined;
this.reconnectFuture = undefined;
}

/**
* @internal for testing
*/
Expand Down Expand Up @@ -627,7 +634,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)

private handleRestarting = () => {
if (!this.reconnectFuture) {
this.reconnectFuture = new Future();
this.reconnectFuture = new Future(undefined, () => {
this.clearConnectionFutures();
});
}
// also unwind existing participants & existing subscriptions
for (const p of this.participants.values()) {
Expand Down

0 comments on commit 90260b8

Please sign in to comment.