mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
autoplay video on reconnection.
This commit is contained in:
parent
a4a24a913b
commit
15cfe4c146
@ -15,11 +15,11 @@ export interface NekoConnectionEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||||
private _shouldReconnect = false
|
private _activated = false
|
||||||
private _url: string
|
private _url = ''
|
||||||
private _token: string
|
private _token = ''
|
||||||
|
private _log = new Logger('connection')
|
||||||
private _state: Connection
|
private _state: Connection
|
||||||
private _log: Logger
|
|
||||||
|
|
||||||
public websocket = new NekoWebSocket()
|
public websocket = new NekoWebSocket()
|
||||||
public webrtc = new NekoWebRTC()
|
public webrtc = new NekoWebRTC()
|
||||||
@ -27,9 +27,6 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
constructor(state: Connection) {
|
constructor(state: Connection) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this._url = ''
|
|
||||||
this._token = ''
|
|
||||||
this._log = new Logger('connection')
|
|
||||||
this._state = state
|
this._state = state
|
||||||
|
|
||||||
// initial state
|
// initial state
|
||||||
@ -125,7 +122,7 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
|
|
||||||
await this._webrtcConnect(video)
|
await this._webrtcConnect(video)
|
||||||
|
|
||||||
this._shouldReconnect = true
|
this._activated = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
throw e
|
throw e
|
||||||
@ -133,7 +130,7 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public disconnect() {
|
public disconnect() {
|
||||||
this._shouldReconnect = false
|
this._activated = false
|
||||||
|
|
||||||
this.webrtc.disconnect()
|
this.webrtc.disconnect()
|
||||||
this.websocket.disconnect()
|
this.websocket.disconnect()
|
||||||
@ -142,6 +139,10 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
this.emit('disconnect')
|
this.emit('disconnect')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get activated() {
|
||||||
|
return this._activated
|
||||||
|
}
|
||||||
|
|
||||||
async _websocketConnect() {
|
async _websocketConnect() {
|
||||||
Vue.set(this._state, 'status', 'connecting')
|
Vue.set(this._state, 'status', 'connecting')
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
this._log.debug(`starting websocket reconnection`)
|
this._log.debug(`starting websocket reconnection`)
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
while (this._shouldReconnect) {
|
while (this.activated) {
|
||||||
try {
|
try {
|
||||||
await this._websocketConnect()
|
await this._websocketConnect()
|
||||||
this._webrtcReconnect()
|
this._webrtcReconnect()
|
||||||
@ -228,7 +229,7 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
this._log.debug(`starting webrtc reconnection`)
|
this._log.debug(`starting webrtc reconnection`)
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
while (this._shouldReconnect && this.websocket.connected) {
|
while (this.activated && this.websocket.connected) {
|
||||||
try {
|
try {
|
||||||
await this._webrtcConnect(lastVideo)
|
await this._webrtcConnect(lastVideo)
|
||||||
break
|
break
|
||||||
|
@ -58,7 +58,6 @@
|
|||||||
|
|
||||||
import { NekoApi, MembersApi, RoomApi } from './internal/api'
|
import { NekoApi, MembersApi, RoomApi } from './internal/api'
|
||||||
import { NekoConnection } from './internal/connection'
|
import { NekoConnection } from './internal/connection'
|
||||||
import { WebRTCStats } from './internal/webrtc'
|
|
||||||
import { NekoMessages } from './internal/messages'
|
import { NekoMessages } from './internal/messages'
|
||||||
import { register as VideoRegister } from './internal/video'
|
import { register as VideoRegister } from './internal/video'
|
||||||
|
|
||||||
@ -377,7 +376,7 @@
|
|||||||
this._video.src = window.URL.createObjectURL(streams[0]) // for older browsers
|
this._video.src = window.URL.createObjectURL(streams[0]) // for older browsers
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.autoplay) {
|
if (this.autoplay || this.connection.activated) {
|
||||||
this._video.play()
|
this._video.play()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user