mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
reconnecter add destroy.
This commit is contained in:
@ -18,15 +18,20 @@ class WebsocketReconnecter extends ReconnecterAbstract {
|
||||
private _state: Connection
|
||||
private _websocket: NekoWebSocket
|
||||
|
||||
private _onConnectHandle: () => void
|
||||
private _onDisconnectHandle: (error?: Error) => void
|
||||
|
||||
constructor(state: Connection, websocket: NekoWebSocket) {
|
||||
super()
|
||||
|
||||
this._state = state
|
||||
|
||||
// TODO: Unmount.
|
||||
this._websocket = websocket
|
||||
this._websocket.on('connected', () => this.emit('connect'))
|
||||
this._websocket.on('disconnected', (error) => this.emit('disconnect', error))
|
||||
|
||||
this._onConnectHandle = () => this.emit('connect')
|
||||
this._websocket.on('connected', this._onConnectHandle)
|
||||
|
||||
this._onDisconnectHandle = (error?: Error) => this.emit('disconnect', error)
|
||||
this._websocket.on('disconnected', this._onDisconnectHandle)
|
||||
}
|
||||
|
||||
public get connected() {
|
||||
@ -48,6 +53,11 @@ class WebsocketReconnecter extends ReconnecterAbstract {
|
||||
public disconnect() {
|
||||
this._websocket.disconnect()
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this._websocket.off('connected', this._onConnectHandle)
|
||||
this._websocket.off('disconnected', this._onDisconnectHandle)
|
||||
}
|
||||
}
|
||||
|
||||
class WebrtcReconnecter extends ReconnecterAbstract {
|
||||
@ -55,16 +65,21 @@ class WebrtcReconnecter extends ReconnecterAbstract {
|
||||
private _websocket: NekoWebSocket
|
||||
private _webrtc: NekoWebRTC
|
||||
|
||||
private _onConnectHandle: () => void
|
||||
private _onDisconnectHandle: (error?: Error) => void
|
||||
|
||||
constructor(state: Connection, websocket: NekoWebSocket, webrtc: NekoWebRTC) {
|
||||
super()
|
||||
|
||||
this._state = state
|
||||
this._websocket = websocket
|
||||
|
||||
// TODO: Unmount.
|
||||
this._webrtc = webrtc
|
||||
this._webrtc.on('connected', () => this.emit('connect'))
|
||||
this._webrtc.on('disconnected', (error) => this.emit('disconnect', error))
|
||||
|
||||
this._onConnectHandle = () => this.emit('connect')
|
||||
this._webrtc.on('connected', this._onConnectHandle)
|
||||
|
||||
this._onDisconnectHandle = (error?: Error) => this.emit('disconnect', error)
|
||||
this._webrtc.on('disconnected', this._onDisconnectHandle)
|
||||
}
|
||||
|
||||
public get connected() {
|
||||
@ -80,6 +95,11 @@ class WebrtcReconnecter extends ReconnecterAbstract {
|
||||
public disconnect() {
|
||||
this._webrtc.disconnect()
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this._webrtc.off('connected', this._onConnectHandle)
|
||||
this._webrtc.off('disconnected', this._onDisconnectHandle)
|
||||
}
|
||||
}
|
||||
|
||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
@ -227,6 +247,11 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
this.emit('disconnect', error)
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this._websocket_reconn.destroy()
|
||||
this._webrtc_reconn.destroy()
|
||||
}
|
||||
|
||||
_webrtcQualityDowngrade(quality: string): string | undefined {
|
||||
// get index of selected or surrent quality
|
||||
const index = this._state.webrtc.videos.indexOf(quality)
|
||||
|
Reference in New Issue
Block a user