add ice restarts to reconnection logic.

This commit is contained in:
Miroslav Šedivý 2021-06-27 22:07:42 +02:00
parent 3edb97e784
commit 14bda1a028
4 changed files with 35 additions and 7 deletions

View file

@ -54,15 +54,16 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
return typeof RTCPeerConnection !== 'undefined' && typeof RTCPeerConnection.prototype.addTransceiver !== 'undefined'
}
get connected() {
get open() {
return (
typeof this._peer !== 'undefined' &&
['connected', 'checking', 'completed'].includes(this._state) &&
typeof this._channel !== 'undefined' &&
this._channel.readyState == 'open'
typeof this._peer !== 'undefined' && typeof this._channel !== 'undefined' && this._channel.readyState == 'open'
)
}
get connected() {
return this.open && ['connected', 'checking', 'completed'].includes(this._state)
}
public async setCandidate(candidate: RTCIceCandidateInit) {
if (!this._peer) {
this._candidates.push(candidate)
@ -137,6 +138,15 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
this._peer.ondatachannel = this.onDataChannel.bind(this)
this._peer.addTransceiver('audio', { direction: 'recvonly' })
this._peer.addTransceiver('video', { direction: 'recvonly' })
return await this.offer(sdp)
}
public async offer(sdp: string) {
if (!this._peer) {
throw new Error('attempting to set offer for nonexistent peer')
}
this._peer.setRemoteDescription({ type: 'offer', sdp })
if (this._candidates.length > 0) {