mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
open connection only once.
This commit is contained in:
parent
262ea3dd77
commit
3fa0831f43
@ -21,6 +21,7 @@ export interface NekoConnectionEvents {
|
|||||||
|
|
||||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||||
private _state: Connection
|
private _state: Connection
|
||||||
|
private _open = false
|
||||||
|
|
||||||
public websocket = new NekoWebSocket()
|
public websocket = new NekoWebSocket()
|
||||||
public webrtc = new NekoWebRTC()
|
public webrtc = new NekoWebRTC()
|
||||||
@ -161,6 +162,12 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public open(video?: string) {
|
public open(video?: string) {
|
||||||
|
if (this._open) {
|
||||||
|
throw new Error('connection already open')
|
||||||
|
}
|
||||||
|
|
||||||
|
this._open = true
|
||||||
|
|
||||||
if (video) {
|
if (video) {
|
||||||
if (!this._state.webrtc.videos.includes(video)) {
|
if (!this._state.webrtc.videos.includes(video)) {
|
||||||
throw new Error('video id not found')
|
throw new Error('video id not found')
|
||||||
@ -179,7 +186,9 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public close(error?: Error) {
|
public close(error?: Error) {
|
||||||
if (this.activated) {
|
if (this._open) {
|
||||||
|
this._open = false
|
||||||
|
|
||||||
Vue.set(this._state, 'type', 'none')
|
Vue.set(this._state, 'type', 'none')
|
||||||
Vue.set(this._state, 'status', 'disconnected')
|
Vue.set(this._state, 'status', 'disconnected')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user