From a961dd6428fb8c7f4bbb2ab1ac6d5f2b114fbe3e Mon Sep 17 00:00:00 2001 From: mbattista Date: Fri, 12 Mar 2021 23:45:01 +0000 Subject: [PATCH 1/2] should fix race condition --- client/src/neko/base.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/neko/base.ts b/client/src/neko/base.ts index 9cad66fd..9111c507 100644 --- a/client/src/neko/base.ts +++ b/client/src/neko/base.ts @@ -19,6 +19,7 @@ export abstract class BaseClient extends EventEmitter { protected _displayname?: string protected _state: RTCIceConnectionState = 'disconnected' protected _id = '' + protected _candidates: RTCIceCandidate[] = []; get id() { return this._id @@ -220,6 +221,9 @@ export abstract class BaseClient extends EventEmitter { this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed')) this._peer.setRemoteDescription({ type: 'offer', sdp }) + for (let candidate of this._candidates) { + this._peer.addIceCandidate(candidate) + } this._peer .createAnswer() .then((d) => { @@ -250,7 +254,11 @@ export abstract class BaseClient extends EventEmitter { if (event === EVENT.SIGNAL.CANDIDATE) { const { data } = payload as SignalCandidatePayload let candidate: RTCIceCandidate = JSON.parse(data) - this._peer!.addIceCandidate(candidate) + if (this._peer) { + this._peer.addIceCandidate(candidate) + } else { + this._candidates.push(candidate); + } return } From 5762f33e36186d98571b928ef199deb73edf37f4 Mon Sep 17 00:00:00 2001 From: m1k1o Date: Sat, 13 Mar 2021 10:32:05 +0100 Subject: [PATCH 2/2] fix lint and clear candidates array. --- client/src/neko/base.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/neko/base.ts b/client/src/neko/base.ts index 9111c507..de2532b1 100644 --- a/client/src/neko/base.ts +++ b/client/src/neko/base.ts @@ -19,7 +19,7 @@ export abstract class BaseClient extends EventEmitter { protected _displayname?: string protected _state: RTCIceConnectionState = 'disconnected' protected _id = '' - protected _candidates: RTCIceCandidate[] = []; + protected _candidates: RTCIceCandidate[] = [] get id() { return this._id @@ -221,9 +221,12 @@ export abstract class BaseClient extends EventEmitter { this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed')) this._peer.setRemoteDescription({ type: 'offer', sdp }) + for (let candidate of this._candidates) { this._peer.addIceCandidate(candidate) } + this._candidates = [] + this._peer .createAnswer() .then((d) => { @@ -257,7 +260,7 @@ export abstract class BaseClient extends EventEmitter { if (this._peer) { this._peer.addIceCandidate(candidate) } else { - this._candidates.push(candidate); + this._candidates.push(candidate) } return }