bulky-animal-7027
10/27/2025, 7:41 PMtall-airline-16756
10/27/2025, 7:41 PMtall-airline-16756
10/27/2025, 7:42 PMroom.disconnect() in the JavaScript SDK, you can take a look at the reason property that comes with the Disconnected event. This property is part of the DisconnectReason enum and clearly tells you why the disconnection happened.
So, when you or a participant manually calls room.disconnect(), the Disconnected event will fire with the reason CLIENT_INITIATED. On the other hand, if the disconnection is due to server or system actions (like the room being deleted or a participant being removed), you’ll see other reasons such as ROOM_DELETED, PARTICIPANT_REMOVED, or DUPLICATE_IDENTITY.
Here’s a little example to guide you:
room.on(RoomEvent.Disconnected, (reason) => {
if (reason === DisconnectReason.CLIENT_INITIATED) {
console.log("User manually disconnected.");
} else {
console.log("Disconnected by system or server:", reason);
}
});
By checking the reason inside your Disconnected event handler, you’ll be able to easily tell manual disconnections apart from automatic ones. If you have any questions or need more help, feel free to ask—I’m here for you!
Sources: packages/livekit-rtc/src/proto/participant_pb.ts | livekit-android-test/src/test/java/io/livekit/android/room/RoomMockE2ETest.... | Connecting to LiveKit | LiveKit Docs | src/e2ee/worker/ParticipantKeyHandler.ts