Skip to content

Commit f38174e

Browse files
authored
Wait for disconnect response on disconnect (#562)
* Wait for disconnect response on disconnect * Create serious-pumas-join.md * fix type
1 parent 049e0d2 commit f38174e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/serious-pumas-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/rtc-node": patch
3+
---
4+
5+
Wait for disconnect response on disconnect

packages/livekit-rtc/src/room.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { LocalParticipant, RemoteParticipant } from './participant.js';
2121
import { EncryptionState, EncryptionType } from './proto/e2ee_pb.js';
2222
import type { FfiEvent } from './proto/ffi_pb.js';
2323
import type { DisconnectReason, OwnedParticipant } from './proto/participant_pb.js';
24-
import type { DataStream_Trailer } from './proto/room_pb.js';
24+
import type { DataStream_Trailer, DisconnectCallback } from './proto/room_pb.js';
2525
import {
2626
type ConnectCallback,
2727
ConnectRequest,
@@ -248,7 +248,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
248248
return;
249249
}
250250

251-
FfiClient.instance.request<DisconnectResponse>({
251+
const res = FfiClient.instance.request<DisconnectResponse>({
252252
message: {
253253
case: 'disconnect',
254254
value: {
@@ -257,6 +257,10 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
257257
},
258258
});
259259

260+
await FfiClient.instance.waitFor<DisconnectCallback>((ev: FfiEvent) => {
261+
return ev.message.case == 'connect' && ev.message.value.asyncId == res.asyncId;
262+
});
263+
260264
FfiClient.instance.removeListener(FfiClientEvent.FfiEvent, this.onFfiEvent);
261265
this.removeAllListeners();
262266
}

0 commit comments

Comments
 (0)