mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
should fix race condition
This commit is contained in:
parent
108ac79443
commit
a961dd6428
@ -19,6 +19,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
protected _displayname?: string
|
protected _displayname?: string
|
||||||
protected _state: RTCIceConnectionState = 'disconnected'
|
protected _state: RTCIceConnectionState = 'disconnected'
|
||||||
protected _id = ''
|
protected _id = ''
|
||||||
|
protected _candidates: RTCIceCandidate[] = [];
|
||||||
|
|
||||||
get id() {
|
get id() {
|
||||||
return this._id
|
return this._id
|
||||||
@ -220,6 +221,9 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed'))
|
this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed'))
|
||||||
|
|
||||||
this._peer.setRemoteDescription({ type: 'offer', sdp })
|
this._peer.setRemoteDescription({ type: 'offer', sdp })
|
||||||
|
for (let candidate of this._candidates) {
|
||||||
|
this._peer.addIceCandidate(candidate)
|
||||||
|
}
|
||||||
this._peer
|
this._peer
|
||||||
.createAnswer()
|
.createAnswer()
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
@ -250,7 +254,11 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
if (event === EVENT.SIGNAL.CANDIDATE) {
|
if (event === EVENT.SIGNAL.CANDIDATE) {
|
||||||
const { data } = payload as SignalCandidatePayload
|
const { data } = payload as SignalCandidatePayload
|
||||||
let candidate: RTCIceCandidate = JSON.parse(data)
|
let candidate: RTCIceCandidate = JSON.parse(data)
|
||||||
this._peer!.addIceCandidate(candidate)
|
if (this._peer) {
|
||||||
|
this._peer.addIceCandidate(candidate)
|
||||||
|
} else {
|
||||||
|
this._candidates.push(candidate);
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user