Change lk connection options (#9757)

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
Anton Alexeyev
2025-09-02 13:01:10 +07:00
committed by GitHub
parent dca6af5a45
commit d48e8a657c
2 changed files with 18 additions and 33 deletions
+17 -10
View File
@@ -76,34 +76,40 @@ export class LiveKitClient {
async connect (wsURL: string, token: string, withVideo: boolean): Promise<void> {
this.currentSessionSupportsVideo = withVideo
try {
const [, session] = await Promise.all([
this.liveKitRoom.connect(wsURL, token, { maxRetries: 3 }),
useMedia({
const setupMediaSession = async (): Promise<void> => {
this.currentMediaSession = await useMedia({
state: {
camera: this.currentSessionSupportsVideo ? { enabled: $myPreferences?.camEnabled ?? true } : undefined,
microphone: { enabled: $myPreferences?.micEnabled ?? this.liveKitRoom.remoteParticipants.size < 16 }
},
autoDestroy: false
})
}
await Promise.all([
this.liveKitRoom.connect(wsURL, token, {
maxRetries: 1,
websocketTimeout: 10000,
peerConnectionTimeout: 10000
}),
setupMediaSession()
])
this.currentMediaSession = session
session?.on('camera', (enabled) => {
this.currentMediaSession?.on('camera', (enabled) => {
void this.setCameraEnabled(enabled)
})
session?.on('microphone', (enabled) => {
this.currentMediaSession?.on('microphone', (enabled) => {
void this.setMicrophoneEnabled(enabled)
})
session?.on('selected-camera', (deviceId) => {
this.currentMediaSession?.on('selected-camera', (deviceId) => {
void this.setActiveCamera(deviceId)
})
session?.on('selected-microphone', (deviceId) => {
this.currentMediaSession?.on('selected-microphone', (deviceId) => {
void this.setActiveMicrophone(deviceId)
})
session?.on('selected-speaker', (deviceId) => {
this.currentMediaSession?.on('selected-speaker', (deviceId) => {
void this.setActiveSpeaker(deviceId)
})
session?.on('feature', (feature, enabled) => {
this.currentMediaSession?.on('feature', (feature, enabled) => {
if (feature !== 'sharing') return
void this.setScreenShareEnabled(enabled, true)
})
@@ -111,6 +117,7 @@ export class LiveKitClient {
await this.updateActiveDevices()
} catch (error) {
this.currentMediaSession?.close()
this.currentMediaSession?.removeAllListeners()
this.currentMediaSession = undefined
throw error
}
+1 -23
View File
@@ -370,22 +370,6 @@ function parseMetadata (metadata: string | undefined): RoomMetadata {
}
}
async function withRetries (fn: () => Promise<void>, retries: number, delay: number): Promise<void> {
for (let attempt = 0; attempt < retries; attempt++) {
try {
await fn()
return
} catch (error) {
if (attempt >= retries - 1) {
throw error
}
console.error(error)
console.log(`Attempt ${attempt} failed. Retrying in ${delay}ms...`)
await new Promise((resolve) => setTimeout(resolve, delay))
}
}
}
export async function disconnect (): Promise<void> {
await liveKitClient.disconnect()
screenSharing.set(false)
@@ -536,13 +520,7 @@ export async function connectRoom (
await disconnect()
const token = await getToken(room.name, room._id, currentPerson._id, currentPerson.name)
try {
await withRetries(
async () => {
await connectLK(token, room)
},
3,
1000
)
await connectLK(token, room)
} catch (err) {
console.error(err)
await leaveRoom(currentInfo, get(myOffice))