mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
webrtc quality downgrade on reconnect.
This commit is contained in:
parent
15cfe4c146
commit
fcae8156f5
@ -81,17 +81,11 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
|
|
||||||
// try to downgrade quality if it happend many times
|
// try to downgrade quality if it happend many times
|
||||||
if (++webrtcCongestion >= 3) {
|
if (++webrtcCongestion >= 3) {
|
||||||
const index = this._state.webrtc.videos.indexOf(this._state.webrtc.video)
|
webrtcCongestion = 0
|
||||||
|
|
||||||
// edge case: current quality is not in qualities list
|
|
||||||
if (index === -1) return
|
|
||||||
|
|
||||||
// current quality is the lowest one
|
|
||||||
if (index + 1 == this._state.webrtc.videos.length) return
|
|
||||||
|
|
||||||
// downgrade video quality
|
// downgrade video quality
|
||||||
this.setVideo(this._state.webrtc.videos[index + 1])
|
const quality = this._webrtcQualityDowngrade()
|
||||||
webrtcCongestion = 0
|
if (quality) this.setVideo(quality)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -225,13 +219,15 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastVideo = this._state.webrtc.video ?? undefined
|
let lastQuality: string | undefined
|
||||||
this._log.debug(`starting webrtc reconnection`)
|
this._log.debug(`starting webrtc reconnection`)
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
while (this.activated && this.websocket.connected) {
|
while (this.activated && this.websocket.connected) {
|
||||||
try {
|
try {
|
||||||
await this._webrtcConnect(lastVideo)
|
const quality = this._webrtcQualityDowngrade(lastQuality)
|
||||||
|
if (quality) lastQuality = quality
|
||||||
|
await this._webrtcConnect(lastQuality)
|
||||||
break
|
break
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._log.debug(`webrtc reconnection failed`, e)
|
this._log.debug(`webrtc reconnection failed`, e)
|
||||||
@ -242,4 +238,21 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
this._log.debug(`webrtc reconnection finished`)
|
this._log.debug(`webrtc reconnection finished`)
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_webrtcQualityDowngrade(quality?: string): string | undefined {
|
||||||
|
// current quality is not known
|
||||||
|
if (typeof quality === 'undefined' || this._state.webrtc.video == null) return
|
||||||
|
|
||||||
|
// get index of selected or surrent quality
|
||||||
|
const index = this._state.webrtc.videos.indexOf(quality || this._state.webrtc.video)
|
||||||
|
|
||||||
|
// edge case: current quality is not in qualities list
|
||||||
|
if (index === -1) return
|
||||||
|
|
||||||
|
// current quality is the lowest one
|
||||||
|
if (index + 1 == this._state.webrtc.videos.length) return
|
||||||
|
|
||||||
|
// downgrade video quality
|
||||||
|
return this._state.webrtc.videos[index + 1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user