livekit-rtc: set room state to disconnected on dc
while trying to reproduce another bug i found this: room.disconnect() does not set the room state to disconnected.
⚠️ No Changeset found
Latest commit: 5dabd533ed7a5b1f252787193874a6e0afc5c8e6
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
aha, i see. i'll change it so that event gets properly processed before the await resolves
diff --git a/packages/livekit-rtc/src/room.ts b/packages/livekit-rtc/src/room.ts
index 95f19ff..f9bebeb 100644
--- a/packages/livekit-rtc/src/room.ts
+++ b/packages/livekit-rtc/src/room.ts
@@ -148,7 +149,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
return;
}
- FfiClient.instance.request<DisconnectResponse>({
+ const res = FfiClient.instance.request<DisconnectResponse>({
message: {
case: 'disconnect',
value: {
@@ -157,9 +158,12 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
},
});
+ await FfiClient.instance.waitFor<DisconnectCallback>((ev: FfiEvent) => {
+ return ev.message.case == 'disconnect' && ev.message.value.asyncId == res.asyncId;
+ });
+
FfiClient.instance.removeAllListeners();
this.removeAllListeners();
- this.connectionState = ConnectionState.CONN_DISCONNECTED;
}
private onFfiEvent = (ffiEvent: FfiEvent) => {
this doesn't work, for some reason. neither RoomEvent.Disconnect or RoomEvent.ConnectionStateChanged fire here, and this goes on without changing anything
this doesn't work, for some reason. neither
RoomEvent.DisconnectorRoomEvent.ConnectionStateChangedfire here, and this goes on without changing anything
Mmh seems like an issue on the Rust side then?
diff --git a/packages/livekit-rtc/src/room.ts b/packages/livekit-rtc/src/room.ts index 95f19ff..f9bebeb 100644 --- a/packages/livekit-rtc/src/room.ts +++ b/packages/livekit-rtc/src/room.ts @@ -148,7 +149,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> return; } - FfiClient.instance.request<DisconnectResponse>({ + const res = FfiClient.instance.request<DisconnectResponse>({ message: { case: 'disconnect', value: { @@ -157,9 +158,12 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> }, }); + await FfiClient.instance.waitFor<DisconnectCallback>((ev: FfiEvent) => { + return ev.message.case == 'disconnect' && ev.message.value.asyncId == res.asyncId; + }); + FfiClient.instance.removeAllListeners(); this.removeAllListeners(); - this.connectionState = ConnectionState.CONN_DISCONNECTED; } private onFfiEvent = (ffiEvent: FfiEvent) => {this doesn't work, for some reason. neither
RoomEvent.DisconnectorRoomEvent.ConnectionStateChangedfire here, and this goes on without changing anything
looked into it a bit more, the DisconnectCallback does fire, but nothing else gets run because of it.
adding a manual RoomEvent.Disconnect hook to the callback might work, but i don't know if that's a hack, because iirc it should do it by itself?
sometimes it works? there's a race condition somewhere in here.
this is working now: the room state is set to disconnected manually, regardless of whether the ConnectionStateChange event fires on time before end-of-stream. merge livekit/rust-sdks#370 first, then i'll update this PR to use updated main with the necessary changes.
can we close this? Is there still an issue around room state when disconnecting?