Room.setAndEmitConnectionState rejects a promise with Error: "disconnected from Room" that cannot be handled
See original GitHub issueSummary
The method Room.setAndEmitConnectionState
rejects a promise with Error: “disconnected from Room” that cannot be handled, at least in the following scenarios, and possibly more:
- Reconnection fails and max attempts are exhausted
- When the room is in reconnecting state and I call disconnect
Details
1. Reconnection failed and max attempts exhausted
It would be nice to be able to handle this gracefully. For now I’m using a Custom reconnect policy:
import { DefaultReconnectPolicy } from "livekit-client";
export class CustomReconnectPolicy extends DefaultReconnectPolicy {
constructor({ handleGiveUp }) {
this.handleGiveUp = handleGiveUp;
}
nextRetryDelayInMs(context) {
const result = super.nextRetryDelayInMs(context);
if (result !== null) {
return result;
} else {
return this.handleGiveUp(context);
}
}
}
But that results in the following problem
2. When the room is in reconnecting state and I call disconnect
I handle reconnection failure by directing the user away from the conference page in my CustomReconnectPolicy.handleGiveUp
callback. But during clean up, when I call room.disconnect().catch(console.error)
, Room.setAndEmitConnectionState
rejects the connectFuture
that results in an unhandled rejection.
Solutions
Do not reject a promise that is not returned or is inaccessible via the public API.
1. Reconnection failed and max attempts exhausted
Additionally, emit the reason for disconnect here https://github.com/livekit/client-sdk-js/blob/9c999845a34984a24dc4b3b27a0c09746e2ba3c8/src/room/RTCEngine.ts#L469
2. When the room is in reconnecting state and I call disconnect
disconnect() should only reject a promise that was returned during a call to connect() and not reject a promise that was created on reconnection. https://github.com/livekit/client-sdk-js/blob/9c999845a34984a24dc4b3b27a0c09746e2ba3c8/src/room/Room.ts#L1040-L1044
Issue Analytics
- State:
- Created a year ago
- Comments:14
Top GitHub Comments
Haha yes I considered it, but decided against doing so. I’m not entirely familiar with the livekit client-server protocol yet - didn’t want to mess anything up. I started using livekit a little over a week ago. Once I have a little more experience with livekit, I’ll try and contribute for sure!
great, thank you for checking!