From f0dd63e8a082a5a7cef94c1a6cc59ac28b5df99b Mon Sep 17 00:00:00 2001 From: Anton Alexeyev Date: Wed, 3 Sep 2025 10:58:53 +0700 Subject: [PATCH] Fix race condition during lk connection (#9764) Signed-off-by: Anton Alexeyev --- plugins/love-resources/src/liveKitClient.ts | 4 ++++ plugins/love-resources/src/utils.ts | 2 ++ 2 files changed, 6 insertions(+) diff --git a/plugins/love-resources/src/liveKitClient.ts b/plugins/love-resources/src/liveKitClient.ts index 680f2850a0..7840d2f85c 100644 --- a/plugins/love-resources/src/liveKitClient.ts +++ b/plugins/love-resources/src/liveKitClient.ts @@ -40,6 +40,7 @@ const defaultCaptureOptions: VideoCaptureOptions = { export class LiveKitClient { public readonly liveKitRoom: LKRoom + public isConnecting: boolean = false public currentMediaSession: MediaSession | undefined = undefined private currentSessionSupportsVideo: boolean = false private lastParticipantNotificationTimeout: number = -1 @@ -74,6 +75,7 @@ export class LiveKitClient { } async connect (wsURL: string, token: string, withVideo: boolean): Promise { + this.isConnecting = true this.currentSessionSupportsVideo = withVideo try { const setupMediaSession = async (): Promise => { @@ -116,6 +118,7 @@ export class LiveKitClient { await this.updateActiveDevices() } catch (error) { + this.isConnecting = false this.currentMediaSession?.close() this.currentMediaSession?.removeAllListeners() this.currentMediaSession = undefined @@ -146,6 +149,7 @@ export class LiveKitClient { } onConnected = (): void => { + this.isConnecting = false lkSessionConnected.set(true) this.liveKitRoom.on(RoomEvent.ParticipantConnected, this.onParticipantConnected) this.liveKitRoom.on(RoomEvent.ParticipantDisconnected, this.onParticipantDisconnected) diff --git a/plugins/love-resources/src/utils.ts b/plugins/love-resources/src/utils.ts index 1f7d64d762..9423067439 100644 --- a/plugins/love-resources/src/utils.ts +++ b/plugins/love-resources/src/utils.ts @@ -512,6 +512,7 @@ export async function connectRoom ( currentPerson: Person, room: Room ): Promise { + liveKitClient.isConnecting = true await moveToRoom(x, y, currentInfo, currentPerson, room, getMetadata(presentation.metadata.SessionId) ?? null) selectedRoomPlace.set(undefined) if (getCurrentAccount().role === AccountRole.ReadOnlyGuest) { @@ -580,6 +581,7 @@ export async function tryConnect ( currentInvites: Invite[], place?: { x: number, y: number } ): Promise { + if (liveKitClient.isConnecting) return const me = getCurrentEmployee() const currentPerson = await getPersonByPersonRef(me) if (currentPerson == null) return