mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
webrtc connection change.
This commit is contained in:
parent
73e043aa0d
commit
7858edb8ec
@ -111,8 +111,10 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
// Signal Events
|
// Signal Events
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
protected [EVENT.SIGNAL_PROVIDE]({ event }: message.SignalProvide) {
|
protected [EVENT.SIGNAL_PROVIDE]({ event, video, videos }: 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, 'videos', videos)
|
||||||
// TODO: Handle.
|
// TODO: Handle.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +123,11 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
// TODO: Handle.
|
// TODO: Handle.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected [EVENT.SIGNAL_VIDEO]({ event, video }: message.SignalVideo) {
|
||||||
|
this._log.debug('EVENT.SIGNAL_VIDEO')
|
||||||
|
Vue.set(this.state.connection.webrtc, 'video', video)
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Member Events
|
// Member Events
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -85,8 +85,12 @@
|
|||||||
connection: {
|
connection: {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
websocket: this.websocket.supported ? 'disconnected' : 'unavailable',
|
websocket: this.websocket.supported ? 'disconnected' : 'unavailable',
|
||||||
webrtc: this.webrtc.supported ? 'disconnected' : 'unavailable',
|
webrtc: {
|
||||||
webrtc_stats: null,
|
status: this.webrtc.supported ? 'disconnected' : 'unavailable',
|
||||||
|
stats: null,
|
||||||
|
video: null,
|
||||||
|
videos: [],
|
||||||
|
},
|
||||||
type: 'none',
|
type: 'none',
|
||||||
},
|
},
|
||||||
video: {
|
video: {
|
||||||
@ -127,7 +131,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get watching() {
|
public get watching() {
|
||||||
return this.state.connection.webrtc == 'connected'
|
return this.state.connection.webrtc.status == 'connected'
|
||||||
}
|
}
|
||||||
|
|
||||||
public get controlling() {
|
public get controlling() {
|
||||||
@ -264,6 +268,14 @@
|
|||||||
this.websocket.send('screen/set', { width, height, rate })
|
this.websocket.send('screen/set', { width, height, rate })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setWebRTCVideo(video: string) {
|
||||||
|
if (!this.state.connection.webrtc.videos.includes(video)) {
|
||||||
|
throw new Error('VideoID not found.')
|
||||||
|
}
|
||||||
|
|
||||||
|
this.websocket.send('signal/video', { video: video })
|
||||||
|
}
|
||||||
|
|
||||||
public sendUnicast(receiver: string, subject: string, body: any) {
|
public sendUnicast(receiver: string, subject: string, body: any) {
|
||||||
this.websocket.send('send/unicast', { receiver, subject, body })
|
this.websocket.send('send/unicast', { receiver, subject, body })
|
||||||
}
|
}
|
||||||
@ -373,20 +385,22 @@
|
|||||||
this.websocket.send('signal/candidate', candidate)
|
this.websocket.send('signal/candidate', candidate)
|
||||||
})
|
})
|
||||||
this.webrtc.on('stats', (stats: WebRTCStats) => {
|
this.webrtc.on('stats', (stats: WebRTCStats) => {
|
||||||
Vue.set(this.state.connection, 'webrtc_stats', stats)
|
Vue.set(this.state.connection.webrtc, 'stats', stats)
|
||||||
})
|
})
|
||||||
this.webrtc.on('connecting', () => {
|
this.webrtc.on('connecting', () => {
|
||||||
Vue.set(this.state.connection, 'webrtc', 'connecting')
|
Vue.set(this.state.connection.webrtc, 'status', 'connecting')
|
||||||
this.events.emit('connection.webrtc', 'connecting')
|
this.events.emit('connection.webrtc', 'connecting')
|
||||||
})
|
})
|
||||||
this.webrtc.on('connected', () => {
|
this.webrtc.on('connected', () => {
|
||||||
Vue.set(this.state.connection, 'webrtc', 'connected')
|
Vue.set(this.state.connection.webrtc, 'status', 'connected')
|
||||||
Vue.set(this.state.connection, 'type', 'webrtc')
|
Vue.set(this.state.connection, 'type', 'webrtc')
|
||||||
this.events.emit('connection.webrtc', 'connected')
|
this.events.emit('connection.webrtc', 'connected')
|
||||||
})
|
})
|
||||||
this.webrtc.on('disconnected', () => {
|
this.webrtc.on('disconnected', () => {
|
||||||
Vue.set(this.state.connection, 'webrtc', '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, 'videos', [])
|
||||||
Vue.set(this.state.connection, 'type', 'none')
|
Vue.set(this.state.connection, 'type', 'none')
|
||||||
this.events.emit('connection.webrtc', 'disconnected')
|
this.events.emit('connection.webrtc', 'disconnected')
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ export const SIGNAL_REQUEST = 'signal/request'
|
|||||||
export const SIGNAL_ANSWER = 'signal/answer'
|
export const SIGNAL_ANSWER = 'signal/answer'
|
||||||
export const SIGNAL_PROVIDE = 'signal/provide'
|
export const SIGNAL_PROVIDE = 'signal/provide'
|
||||||
export const SIGNAL_CANDIDATE = 'signal/candidate'
|
export const SIGNAL_CANDIDATE = 'signal/candidate'
|
||||||
|
export const SIGNAL_VIDEO = 'signal/video'
|
||||||
|
|
||||||
export const MEMBER_CREATED = 'member/created'
|
export const MEMBER_CREATED = 'member/created'
|
||||||
export const MEMBER_DELETED = 'member/deleted'
|
export const MEMBER_DELETED = 'member/deleted'
|
||||||
|
@ -37,6 +37,8 @@ export interface SignalProvide {
|
|||||||
sdp: string
|
sdp: string
|
||||||
lite: boolean
|
lite: boolean
|
||||||
ice: string[]
|
ice: string[]
|
||||||
|
video: string
|
||||||
|
videos: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SignalCandidate extends RTCIceCandidateInit {
|
export interface SignalCandidate extends RTCIceCandidateInit {
|
||||||
@ -48,6 +50,11 @@ export interface SignalAnswer {
|
|||||||
sdp: string
|
sdp: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SignalVideo {
|
||||||
|
event: string | undefined
|
||||||
|
video: string
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -13,11 +13,17 @@ export default interface State {
|
|||||||
export interface Connection {
|
export interface Connection {
|
||||||
authenticated: boolean
|
authenticated: boolean
|
||||||
websocket: 'unavailable' | 'disconnected' | 'connecting' | 'connected'
|
websocket: 'unavailable' | 'disconnected' | 'connecting' | 'connected'
|
||||||
webrtc: 'unavailable' | 'disconnected' | 'connecting' | 'connected'
|
webrtc: WebRTC
|
||||||
webrtc_stats: WebRTCStats | null
|
|
||||||
type: 'webrtc' | 'fallback' | 'none'
|
type: 'webrtc' | 'fallback' | 'none'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WebRTC {
|
||||||
|
status: 'unavailable' | 'disconnected' | 'connecting' | 'connected'
|
||||||
|
stats: WebRTCStats | null
|
||||||
|
video: string | null
|
||||||
|
videos: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface WebRTCStats {
|
export interface WebRTCStats {
|
||||||
bitrate: number
|
bitrate: number
|
||||||
packetLoss: number
|
packetLoss: number
|
||||||
|
Loading…
Reference in New Issue
Block a user