mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-12 12:47:45 +02:00
Fix race condition during lk connection (#9764)
Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user