From 15cfe4c146fa5d2634ee5d730a900c141ff11a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 23 Jun 2021 21:24:34 +0200 Subject: [PATCH] autoplay video on reconnection. --- src/component/internal/connection.ts | 23 ++++++++++++----------- src/component/main.vue | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/component/internal/connection.ts b/src/component/internal/connection.ts index 1caf686d..754574b8 100644 --- a/src/component/internal/connection.ts +++ b/src/component/internal/connection.ts @@ -15,11 +15,11 @@ export interface NekoConnectionEvents { } export class NekoConnection extends EventEmitter { - private _shouldReconnect = false - private _url: string - private _token: string + private _activated = false + private _url = '' + private _token = '' + private _log = new Logger('connection') private _state: Connection - private _log: Logger public websocket = new NekoWebSocket() public webrtc = new NekoWebRTC() @@ -27,9 +27,6 @@ export class NekoConnection extends EventEmitter { constructor(state: Connection) { super() - this._url = '' - this._token = '' - this._log = new Logger('connection') this._state = state // initial state @@ -125,7 +122,7 @@ export class NekoConnection extends EventEmitter { await this._webrtcConnect(video) - this._shouldReconnect = true + this._activated = true } catch (e) { this.disconnect() throw e @@ -133,7 +130,7 @@ export class NekoConnection extends EventEmitter { } public disconnect() { - this._shouldReconnect = false + this._activated = false this.webrtc.disconnect() this.websocket.disconnect() @@ -142,6 +139,10 @@ export class NekoConnection extends EventEmitter { this.emit('disconnect') } + public get activated() { + return this._activated + } + async _websocketConnect() { Vue.set(this._state, 'status', 'connecting') @@ -178,7 +179,7 @@ export class NekoConnection extends EventEmitter { this._log.debug(`starting websocket reconnection`) setTimeout(async () => { - while (this._shouldReconnect) { + while (this.activated) { try { await this._websocketConnect() this._webrtcReconnect() @@ -228,7 +229,7 @@ export class NekoConnection extends EventEmitter { this._log.debug(`starting webrtc reconnection`) setTimeout(async () => { - while (this._shouldReconnect && this.websocket.connected) { + while (this.activated && this.websocket.connected) { try { await this._webrtcConnect(lastVideo) break diff --git a/src/component/main.vue b/src/component/main.vue index 0875652c..404f2865 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -58,7 +58,6 @@ import { NekoApi, MembersApi, RoomApi } from './internal/api' import { NekoConnection } from './internal/connection' - import { WebRTCStats } from './internal/webrtc' import { NekoMessages } from './internal/messages' import { register as VideoRegister } from './internal/video' @@ -377,7 +376,7 @@ this._video.src = window.URL.createObjectURL(streams[0]) // for older browsers } - if (this.autoplay) { + if (this.autoplay || this.connection.activated) { this._video.play() } })