Fix race condition during lk connection (#9764)

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
Anton Alexeyev
2025-09-03 10:58:53 +07:00
committed by GitHub
parent 567fd3b4dc
commit f0dd63e8a0
2 changed files with 6 additions and 0 deletions
@@ -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<void> {
this.isConnecting = true
this.currentSessionSupportsVideo = withVideo
try {
const setupMediaSession = async (): Promise<void> => {
@@ -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)
+2
View File
@@ -512,6 +512,7 @@ export async function connectRoom (
currentPerson: Person,
room: Room
): Promise<void> {
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<void> {
if (liveKitClient.isConnecting) return
const me = getCurrentEmployee()
const currentPerson = await getPersonByPersonRef(me)
if (currentPerson == null) return