diff --git a/packages/livekit-rtc/src/room.ts b/packages/livekit-rtc/src/room.ts index 143774f0..f9bebebb 100644 --- a/packages/livekit-rtc/src/room.ts +++ b/packages/livekit-rtc/src/room.ts @@ -16,6 +16,7 @@ import type { ConnectResponse, ConnectionQuality, DataPacketKind, + DisconnectCallback, DisconnectResponse, IceServer, RoomInfo, @@ -148,7 +149,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter return; } - FfiClient.instance.request({ + const res = FfiClient.instance.request({ message: { case: 'disconnect', value: { @@ -157,6 +158,10 @@ export class Room extends (EventEmitter as new () => TypedEmitter }, }); + await FfiClient.instance.waitFor((ev: FfiEvent) => { + return ev.message.case == 'disconnect' && ev.message.value.asyncId == res.asyncId; + }); + FfiClient.instance.removeAllListeners(); this.removeAllListeners(); }