webrtc connect with selected video.

This commit is contained in:
Miroslav Šedivý 2021-04-30 14:06:13 +00:00
parent 1d522e30a3
commit b39022c4de
3 changed files with 18 additions and 7 deletions

View File

@ -72,6 +72,7 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
this._log.debug('EVENT.SYSTEM_INIT') this._log.debug('EVENT.SYSTEM_INIT')
Vue.set(this._state, 'session_id', conf.session_id) Vue.set(this._state, 'session_id', conf.session_id)
Vue.set(this._state.control, 'implicit_hosting', conf.implicit_hosting) Vue.set(this._state.control, 'implicit_hosting', conf.implicit_hosting)
Vue.set(this._state.connection.webrtc, 'videos', conf.webrtc.videos)
for (const id in conf.sessions) { for (const id in conf.sessions) {
this[EVENT.SESSION_CREATED](conf.sessions[id]) this[EVENT.SESSION_CREATED](conf.sessions[id])
@ -108,10 +109,9 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
// Signal Events // Signal Events
///////////////////////////// /////////////////////////////
protected [EVENT.SIGNAL_PROVIDE]({ event, sdp, video, videos }: message.SignalProvide) { protected [EVENT.SIGNAL_PROVIDE]({ event, sdp, video }: message.SignalProvide) {
this._log.debug('EVENT.SIGNAL_PROVIDE') this._log.debug('EVENT.SIGNAL_PROVIDE')
Vue.set(this._state.connection.webrtc, 'video', video) Vue.set(this._state.connection.webrtc, 'video', video)
Vue.set(this._state.connection.webrtc, 'videos', videos)
// TODO: Handle. // TODO: Handle.
this.emit('connection.webrtc.sdp', 'remote', sdp) this.emit('connection.webrtc.sdp', 'remote', sdp)
} }

View File

@ -269,7 +269,7 @@
this.websocket.disconnect(new Error('manual action')) this.websocket.disconnect(new Error('manual action'))
} }
public webrtcConnect() { public webrtcConnect(video?: string) {
if (!this.connected) { if (!this.connected) {
throw new Error('client not connected to websocket') throw new Error('client not connected to websocket')
} }
@ -278,7 +278,11 @@
throw new Error('client already connected to webrtc') throw new Error('client already connected to webrtc')
} }
this.websocket.send(EVENT.SIGNAL_REQUEST) if (video && !this.state.connection.webrtc.videos.includes(video)) {
throw new Error('video id not found')
}
this.websocket.send(EVENT.SIGNAL_REQUEST, { video: video })
} }
public webrtcDisconnect() { public webrtcDisconnect() {
@ -489,6 +493,8 @@
let webrtcReconnect: any = null let webrtcReconnect: any = null
this.webrtc.on('disconnected', () => { this.webrtc.on('disconnected', () => {
const lastVideo = this.state.connection.webrtc.video ?? undefined
this.events.emit('connection.webrtc', 'disconnected') this.events.emit('connection.webrtc', 'disconnected')
this.clearWebRTCState() this.clearWebRTCState()
@ -508,7 +514,7 @@
// connect only if disconnected // connect only if disconnected
if (this.state.connection.webrtc.status == 'disconnected') { if (this.state.connection.webrtc.status == 'disconnected') {
try { try {
this.webrtcConnect() this.webrtcConnect(lastVideo)
} catch (e) {} } catch (e) {}
} }
@ -597,6 +603,7 @@
} }
clearWebSocketState() { clearWebSocketState() {
Vue.set(this.state.connection.webrtc, 'videos', [])
Vue.set(this.state.control, 'clipboard', null) Vue.set(this.state.control, 'clipboard', null)
Vue.set(this.state.control, 'host_id', null) Vue.set(this.state.control, 'host_id', null)
Vue.set(this.state.control, 'implicit_hosting', false) Vue.set(this.state.control, 'implicit_hosting', false)
@ -610,7 +617,6 @@
Vue.set(this.state.connection.webrtc, 'status', 'disconnected') Vue.set(this.state.connection.webrtc, 'status', 'disconnected')
Vue.set(this.state.connection.webrtc, 'stats', null) Vue.set(this.state.connection.webrtc, 'stats', null)
Vue.set(this.state.connection.webrtc, 'video', null) Vue.set(this.state.connection.webrtc, 'video', null)
Vue.set(this.state.connection.webrtc, 'videos', [])
Vue.set(this.state.connection, 'type', 'none') Vue.set(this.state.connection, 'type', 'none')
} }
} }

View File

@ -9,6 +9,11 @@ export interface Message {
// System // System
///////////////////////////// /////////////////////////////
export interface SystemWebRTC {
event: string | undefined
videos: string[]
}
export interface SystemInit { export interface SystemInit {
event: string | undefined event: string | undefined
session_id: string session_id: string
@ -16,6 +21,7 @@ export interface SystemInit {
screen_size: ScreenSize screen_size: ScreenSize
sessions: Record<string, SessionData> sessions: Record<string, SessionData>
implicit_hosting: boolean implicit_hosting: boolean
webrtc: SystemWebRTC
} }
export interface SystemAdmin { export interface SystemAdmin {
@ -38,7 +44,6 @@ export interface SignalProvide {
sdp: string sdp: string
iceservers: ICEServer[] iceservers: ICEServer[]
video: string video: string
videos: string[]
} }
export interface SignalCandidate extends RTCIceCandidateInit { export interface SignalCandidate extends RTCIceCandidateInit {