mirror of
https://github.com/m1k1o/neko.git
synced 2025-08-06 10:20:26 +02:00
add Trickle ICE support.
This commit is contained in:
parent
baffa8dde4
commit
4850b5cb7c
5 changed files with 38 additions and 0 deletions
|
@ -13,6 +13,7 @@ export interface NekoWebRTCEvents {
|
|||
connected: () => void
|
||||
disconnected: (error?: Error) => void
|
||||
track: (event: RTCTrackEvent) => void
|
||||
candidate: (candidate: RTCIceCandidateInit) => void
|
||||
}
|
||||
|
||||
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> {
|
||||
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._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._state = this._peer!.iceConnectionState
|
||||
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue