mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add reconnecter config.
This commit is contained in:
@ -89,7 +89,7 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
Vue.set(this._state.webrtc, 'stats', stats)
|
||||
|
||||
// if automatic quality adjusting is turned off
|
||||
if (!this._state.webrtc.auto || !this._reconnector.webrtc.isOpen) return
|
||||
if (!this._reconnector.webrtc.isOpen) return
|
||||
|
||||
// if there are no or just one quality, no switching can be done
|
||||
if (this._state.webrtc.videos.length <= 1) return
|
||||
@ -147,6 +147,11 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
return Object.values(this._reconnector).every((r) => r.isOpen)
|
||||
}
|
||||
|
||||
public reloadConfigs() {
|
||||
this._reconnector.websocket.config = this._state.websocket.config
|
||||
this._reconnector.webrtc.config = this._state.webrtc.config
|
||||
}
|
||||
|
||||
public setVideo(video: string) {
|
||||
if (!this._state.webrtc.videos.includes(video)) {
|
||||
throw new Error('video id not found')
|
||||
|
@ -47,9 +47,9 @@ export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
|
||||
this._conn = conn
|
||||
this._config = {
|
||||
maxReconnects: 10,
|
||||
timeoutMs: 1500,
|
||||
backoffMs: 750,
|
||||
max_reconnects: 10,
|
||||
timeout_ms: 1500,
|
||||
backoff_ms: 750,
|
||||
...config,
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
public set config(conf: ReconnectorConfig) {
|
||||
this._config = { ...conf }
|
||||
|
||||
if (this._config.maxReconnects > this._total_reconnects) {
|
||||
if (this._config.max_reconnects > this._total_reconnects) {
|
||||
this.close(new Error('reconnection config changed'))
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
}
|
||||
|
||||
this._conn.connect()
|
||||
this._timeout = window.setTimeout(this.onDisconnect.bind(this), this._config.timeoutMs)
|
||||
this._timeout = window.setTimeout(this.onDisconnect.bind(this), this._config.timeout_ms)
|
||||
}
|
||||
|
||||
public reconnect(): void {
|
||||
@ -165,8 +165,8 @@ export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
|
||||
this._total_reconnects++
|
||||
|
||||
if (this._config.maxReconnects > this._total_reconnects || this._total_reconnects < 0) {
|
||||
this._timeout = window.setTimeout(this.connect.bind(this), this._config.backoffMs)
|
||||
if (this._config.max_reconnects > this._total_reconnects || this._total_reconnects < 0) {
|
||||
this._timeout = window.setTimeout(this.connect.bind(this), this._config.backoff_ms)
|
||||
} else {
|
||||
this.close(new Error('reconnection failed'))
|
||||
}
|
||||
|
Reference in New Issue
Block a user