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:
parent
610805867b
commit
0d32a0592c
@ -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'))
|
||||
}
|
||||
|
@ -63,6 +63,7 @@
|
||||
import { NekoMessages } from './internal/messages'
|
||||
import { register as VideoRegister } from './internal/video'
|
||||
|
||||
import { ReconnectorConfig } from './types/reconnector'
|
||||
import NekoState from './types/state'
|
||||
import Overlay from './overlay.vue'
|
||||
import Screencast from './screencast.vue'
|
||||
@ -109,21 +110,20 @@
|
||||
status: 'disconnected',
|
||||
websocket: {
|
||||
config: {
|
||||
maxReconnects: 15,
|
||||
timeoutMs: 5000,
|
||||
backoffMs: 1500,
|
||||
max_reconnects: 15,
|
||||
timeout_ms: 5000,
|
||||
backoff_ms: 1500,
|
||||
},
|
||||
},
|
||||
webrtc: {
|
||||
config: {
|
||||
maxReconnects: 15,
|
||||
timeoutMs: 10000,
|
||||
backoffMs: 1500,
|
||||
max_reconnects: 15,
|
||||
timeout_ms: 10000,
|
||||
backoff_ms: 1500,
|
||||
},
|
||||
stats: null,
|
||||
video: null,
|
||||
videos: [],
|
||||
auto: true,
|
||||
},
|
||||
screencast: false,
|
||||
type: 'none',
|
||||
@ -292,6 +292,15 @@
|
||||
this.connection.close()
|
||||
}
|
||||
|
||||
public setReconnectorConfig(type: 'websocket' | 'webrtc', config: ReconnectorConfig) {
|
||||
if (type != 'websocket' && type != 'webrtc') {
|
||||
throw new Error('unknown reconnector type')
|
||||
}
|
||||
|
||||
Vue.set(this.state.connection[type], 'config', config)
|
||||
this.connection.reloadConfigs()
|
||||
}
|
||||
|
||||
public play() {
|
||||
this._video.play()
|
||||
}
|
||||
@ -337,10 +346,6 @@
|
||||
this.connection.setVideo(video)
|
||||
}
|
||||
|
||||
public setWebRTCAuto(auto: boolean = true) {
|
||||
Vue.set(this.state.connection.webrtc, 'auto', auto)
|
||||
}
|
||||
|
||||
public sendUnicast(receiver: string, subject: string, body: any) {
|
||||
this.connection.websocket.send(EVENT.SEND_UNICAST, { receiver, subject, body })
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
export interface ReconnectorConfig {
|
||||
maxReconnects: number
|
||||
timeoutMs: number
|
||||
backoffMs: number
|
||||
max_reconnects: number
|
||||
timeout_ms: number
|
||||
backoff_ms: number
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ export interface WebRTC {
|
||||
stats: WebRTCStats | null
|
||||
video: string | null
|
||||
videos: string[]
|
||||
auto: boolean
|
||||
}
|
||||
|
||||
export interface ReconnectorConfig extends reconnecterTypes.ReconnectorConfig {}
|
||||
|
Loading…
Reference in New Issue
Block a user