autoplay video on reconnection.

This commit is contained in:
Miroslav Šedivý 2021-06-23 21:24:34 +02:00
parent a4a24a913b
commit 15cfe4c146
2 changed files with 13 additions and 13 deletions

View File

@ -15,11 +15,11 @@ export interface NekoConnectionEvents {
}
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
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<NekoConnectionEvents> {
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<NekoConnectionEvents> {
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<NekoConnectionEvents> {
}
public disconnect() {
this._shouldReconnect = false
this._activated = false
this.webrtc.disconnect()
this.websocket.disconnect()
@ -142,6 +139,10 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
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<NekoConnectionEvents> {
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<NekoConnectionEvents> {
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

View File

@ -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()
}
})