From 3ca8f9a71cc36268f15334f5c0ab40013b2f8fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 24 Jun 2021 15:15:47 +0200 Subject: [PATCH] fix webrtc last quality connection. --- src/component/internal/connection.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/component/internal/connection.ts b/src/component/internal/connection.ts index abf6c1bd..79e53c69 100644 --- a/src/component/internal/connection.ts +++ b/src/component/internal/connection.ts @@ -84,7 +84,7 @@ export class NekoConnection extends EventEmitter { webrtcCongestion = 0 // downgrade video quality - const quality = this._webrtcQualityDowngrade() + const quality = this._webrtcQualityDowngrade(this._state.webrtc.video) if (quality) this.setVideo(quality) } }) @@ -219,15 +219,17 @@ export class NekoConnection extends EventEmitter { return } - let lastQuality: string | undefined this._log.debug(`starting webrtc reconnection`) setTimeout(async () => { + let lastQuality: string | null = this._state.webrtc.video while (this.activated && this.websocket.connected) { try { - const quality = this._webrtcQualityDowngrade(lastQuality) - if (quality) lastQuality = quality - await this._webrtcConnect(lastQuality) + if (lastQuality != null) { + lastQuality = this._webrtcQualityDowngrade(lastQuality) || lastQuality + } + + await this._webrtcConnect(lastQuality || undefined) break } catch (e) { this._log.debug(`webrtc reconnection failed`, e) @@ -239,12 +241,9 @@ export class NekoConnection extends EventEmitter { }, 0) } - _webrtcQualityDowngrade(quality?: string): string | undefined { - // current quality is not known - if (typeof quality === 'undefined' || this._state.webrtc.video == null) return - + _webrtcQualityDowngrade(quality: string): string | undefined { // get index of selected or surrent quality - const index = this._state.webrtc.videos.indexOf(quality || this._state.webrtc.video) + const index = this._state.webrtc.videos.indexOf(quality) // edge case: current quality is not in qualities list if (index === -1) return