mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
webrtc connect / disconnect functions.
This commit is contained in:
parent
f30614db25
commit
cab53d7d17
@ -73,11 +73,14 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
||||||
|
|
||||||
switch (this._state) {
|
switch (this._state) {
|
||||||
|
case 'disconnected':
|
||||||
|
this.onDisconnected(new Error('peer disconnected'))
|
||||||
|
break
|
||||||
case 'failed':
|
case 'failed':
|
||||||
this.onDisconnected(new Error('peer failed'))
|
this.onDisconnected(new Error('peer failed'))
|
||||||
break
|
break
|
||||||
case 'disconnected':
|
case 'closed':
|
||||||
this.onDisconnected(new Error('peer disconnected'))
|
this.onDisconnected(new Error('peer closed'))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
:webrtc="webrtc"
|
:webrtc="webrtc"
|
||||||
:screenWidth="state.screen.size.width"
|
:screenWidth="state.screen.size.width"
|
||||||
:screenHeight="state.screen.size.height"
|
:screenHeight="state.screen.size.height"
|
||||||
:isControling="controlling"
|
:isControling="controlling && watching"
|
||||||
:scrollSensitivity="state.control.scroll.sensitivity"
|
:scrollSensitivity="state.control.scroll.sensitivity"
|
||||||
:scrollInvert="state.control.scroll.inverse"
|
:scrollInvert="state.control.scroll.inverse"
|
||||||
:implicitControl="state.control.implicit_hosting && state.members[state.member_id].profile.can_host"
|
:implicitControl="state.control.implicit_hosting && state.members[state.member_id].profile.can_host"
|
||||||
@ -113,7 +113,11 @@
|
|||||||
} as NekoState
|
} as NekoState
|
||||||
|
|
||||||
public get connected() {
|
public get connected() {
|
||||||
return this.state.connection.websocket == 'connected' && this.state.connection.webrtc == 'connected'
|
return this.state.connection.websocket == 'connected'
|
||||||
|
}
|
||||||
|
|
||||||
|
public get watching() {
|
||||||
|
return this.state.connection.webrtc == 'connected'
|
||||||
}
|
}
|
||||||
|
|
||||||
public get controlling() {
|
public get controlling() {
|
||||||
@ -153,6 +157,30 @@
|
|||||||
this.api.disconnect()
|
this.api.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public webrtcConnect() {
|
||||||
|
if (!this.connected) {
|
||||||
|
throw new Error('client not connected to websocket')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.watching) {
|
||||||
|
throw new Error('client already connected to webrtc')
|
||||||
|
}
|
||||||
|
|
||||||
|
this.websocket.send('signal/request')
|
||||||
|
}
|
||||||
|
|
||||||
|
public webrtcDisconnect() {
|
||||||
|
if (!this.connected) {
|
||||||
|
throw new Error('client not connected to websocket')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.watching) {
|
||||||
|
throw new Error('client not connected to webrtc')
|
||||||
|
}
|
||||||
|
|
||||||
|
this.webrtc.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
public play() {
|
public play() {
|
||||||
this._video.play()
|
this._video.play()
|
||||||
}
|
}
|
||||||
@ -290,9 +318,9 @@
|
|||||||
this.events.emit('internal.websocket', 'connecting')
|
this.events.emit('internal.websocket', 'connecting')
|
||||||
})
|
})
|
||||||
this.websocket.on('connected', () => {
|
this.websocket.on('connected', () => {
|
||||||
this.websocket.send('signal/request')
|
|
||||||
Vue.set(this.state.connection, 'websocket', 'connected')
|
Vue.set(this.state.connection, 'websocket', 'connected')
|
||||||
this.events.emit('internal.websocket', 'connected')
|
this.events.emit('internal.websocket', 'connected')
|
||||||
|
this.webrtcConnect()
|
||||||
})
|
})
|
||||||
this.websocket.on('disconnected', () => {
|
this.websocket.on('disconnected', () => {
|
||||||
Vue.set(this.state.connection, 'websocket', 'disconnected')
|
Vue.set(this.state.connection, 'websocket', 'disconnected')
|
||||||
|
Loading…
Reference in New Issue
Block a user