diff --git a/src/component/internal/connection.ts b/src/component/internal/connection.ts index cb641f4d..bbda1164 100644 --- a/src/component/internal/connection.ts +++ b/src/component/internal/connection.ts @@ -101,9 +101,6 @@ export class NekoConnection extends EventEmitter { state.webrtc.config, ) - // initial state - Vue.set(this._state, 'type', 'screencast') - // websocket this._websocket_reconn.on('connect', () => { if (this.websocket.connected && this.webrtc.connected) { @@ -136,7 +133,7 @@ export class NekoConnection extends EventEmitter { Vue.set(this._state, 'status', 'connecting') } - Vue.set(this._state, 'type', 'screencast') + Vue.set(this._state, 'type', 'fallback') }) this._webrtc_reconn.on('close', (error) => { this.disconnect(error) @@ -157,10 +154,18 @@ export class NekoConnection extends EventEmitter { // check if video is not playing smoothly if (stats.fps && stats.packetLoss < WEBRTC_RECONN_MAX_LOSS && !stats.muted) { + if (this._state.type === 'fallback') { + Vue.set(this._state, 'type', 'webrtc') + } + webrtcCongestion = 0 return } + if (this._state.type === 'webrtc') { + Vue.set(this._state, 'type', 'fallback') + } + // try to downgrade quality if it happend many times if (++webrtcCongestion >= WEBRTC_RECONN_FAILED_ATTEMPTS) { webrtcCongestion = 0 @@ -205,7 +210,9 @@ export class NekoConnection extends EventEmitter { Vue.set(this._state.webrtc, 'video', video) } + Vue.set(this._state, 'type', 'fallback') Vue.set(this._state, 'status', 'connecting') + this._webrtc_reconn.open(true) this._websocket_reconn.open() } @@ -214,7 +221,9 @@ export class NekoConnection extends EventEmitter { this._websocket_reconn.close() this._webrtc_reconn.close() + Vue.set(this._state, 'type', 'none') Vue.set(this._state, 'status', 'disconnected') + this.emit('disconnect', error) } diff --git a/src/component/main.vue b/src/component/main.vue index a45a1707..b7afa6aa 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -1,14 +1,8 @@