Skip to content

Commit b1cd48c

Browse files
fix: emit ParticipantDisconnected before disposing handles
1 parent c0f7b3a commit b1cd48c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/livekit-rtc/src/room.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,15 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
382382
if (participant) {
383383
this.remoteParticipants.delete(participant.identity);
384384
participant.info.disconnectReason = ev.value.disconnectReason;
385+
// Emit before disposing so listeners can still access trackPublications.
386+
this.emit(RoomEvent.ParticipantDisconnected, participant);
385387
// Dispose each track publication's FfiHandle to prevent FD leaks.
386388
// Without this, rapid participant disconnections accumulate undisposed
387389
// native handles since nothing else triggers their cleanup.
388390
for (const [, publication] of participant.trackPublications) {
389391
publication.ffiHandle.dispose();
390392
}
391393
participant.trackPublications.clear();
392-
this.emit(RoomEvent.ParticipantDisconnected, participant);
393394
} else {
394395
log.warn(`RoomEvent.ParticipantDisconnected: Could not find participant`);
395396
}

0 commit comments

Comments
 (0)