mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add Trickle ICE support.
This commit is contained in:
parent
baffa8dde4
commit
4850b5cb7c
@ -116,6 +116,11 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
|
|||||||
// TODO: Handle.
|
// TODO: Handle.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected [EVENT.SIGNAL_CANDIDATE]({ event, ...candidate }: message.SignalCandidate) {
|
||||||
|
this._log.debug('EVENT.SIGNAL_CANDIDATE')
|
||||||
|
// TODO: Handle.
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Member Events
|
// Member Events
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -13,6 +13,7 @@ export interface NekoWebRTCEvents {
|
|||||||
connected: () => void
|
connected: () => void
|
||||||
disconnected: (error?: Error) => void
|
disconnected: (error?: Error) => void
|
||||||
track: (event: RTCTrackEvent) => void
|
track: (event: RTCTrackEvent) => void
|
||||||
|
candidate: (candidate: RTCIceCandidateInit) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
||||||
@ -40,6 +41,16 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async setCandidate(candidate: RTCIceCandidateInit) {
|
||||||
|
if (!this._peer) {
|
||||||
|
this._log.warn(`could not add remote ICE candidate: peer does not exist!`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this._peer.addIceCandidate(candidate)
|
||||||
|
this._log.debug(`adding remote ICE candidate`, candidate)
|
||||||
|
}
|
||||||
|
|
||||||
public async connect(sdp: string, lite: boolean, servers: string[]): Promise<string> {
|
public async connect(sdp: string, lite: boolean, servers: string[]): Promise<string> {
|
||||||
this._log.info(`connecting`)
|
this._log.info(`connecting`)
|
||||||
|
|
||||||
@ -68,6 +79,17 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
this._log.debug(`peer signaling state changed`, this._peer ? this._peer.signalingState : undefined)
|
this._log.debug(`peer signaling state changed`, this._peer ? this._peer.signalingState : undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._peer.onicecandidate = (event: RTCPeerConnectionIceEvent) => {
|
||||||
|
if (!event.candidate) {
|
||||||
|
this._log.debug(`sent all remote ICE candidates`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const init = event.candidate.toJSON()
|
||||||
|
this.emit('candidate', init)
|
||||||
|
this._log.debug(`sending remote ICE candidate`, init)
|
||||||
|
}
|
||||||
|
|
||||||
this._peer.oniceconnectionstatechange = (event) => {
|
this._peer.oniceconnectionstatechange = (event) => {
|
||||||
this._state = this._peer!.iceConnectionState
|
this._state = this._peer!.iceConnectionState
|
||||||
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
||||||
|
@ -320,6 +320,9 @@
|
|||||||
this.websocket.send('signal/answer', { sdp })
|
this.websocket.send('signal/answer', { sdp })
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
break
|
break
|
||||||
|
case 'signal/candidate':
|
||||||
|
this.webrtc.setCandidate(payload)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.websocket.on('connecting', () => {
|
this.websocket.on('connecting', () => {
|
||||||
@ -356,6 +359,9 @@
|
|||||||
this._video.play()
|
this._video.play()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.webrtc.on('candidate', (candidate: RTCIceCandidateInit) => {
|
||||||
|
this.websocket.send('signal/candidate', candidate)
|
||||||
|
})
|
||||||
this.webrtc.on('connecting', () => {
|
this.webrtc.on('connecting', () => {
|
||||||
Vue.set(this.state.connection, 'webrtc', 'connecting')
|
Vue.set(this.state.connection, 'webrtc', 'connecting')
|
||||||
this.events.emit('connection.webrtc', 'connecting')
|
this.events.emit('connection.webrtc', 'connecting')
|
||||||
|
@ -5,6 +5,7 @@ export const SYSTEM_DISCONNECT = 'system/disconnect'
|
|||||||
export const SIGNAL_REQUEST = 'signal/request'
|
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 MEMBER_CREATED = 'member/created'
|
export const MEMBER_CREATED = 'member/created'
|
||||||
export const MEMBER_DELETED = 'member/deleted'
|
export const MEMBER_DELETED = 'member/deleted'
|
||||||
|
@ -39,6 +39,10 @@ export interface SignalProvide {
|
|||||||
ice: string[]
|
ice: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SignalCandidate extends RTCIceCandidateInit {
|
||||||
|
event: string | undefined
|
||||||
|
}
|
||||||
|
|
||||||
export interface SignalAnswer {
|
export interface SignalAnswer {
|
||||||
event: string | undefined
|
event: string | undefined
|
||||||
sdp: string
|
sdp: string
|
||||||
|
Loading…
Reference in New Issue
Block a user