From 9902ae88f85515eb629af98a27d09cd667c6f80d Mon Sep 17 00:00:00 2001 From: Coread Date: Wed, 11 Dec 2024 15:13:22 +0000 Subject: [PATCH] feat(plugin-meetings): set up the listeners before triggering ice gathering (#4025) --- .../src/reachability/clusterReachability.ts | 5 ++++- .../test/unit/spec/reachability/clusterReachability.ts | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts b/packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts index cc3674ac169..a9472e3a8f1 100644 --- a/packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts +++ b/packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts @@ -357,11 +357,14 @@ export class ClusterReachability extends EventsScope { this.startTimestamp = performance.now(); + // Set up the state change listeners before triggering the ICE gathering + const gatherIceCandidatePromise = this.gatherIceCandidates(); + // not awaiting the next call on purpose, because we're not sending the offer anywhere and there won't be any answer // we just need to make this call to trigger the ICE gathering process this.pc.setLocalDescription(offer); - await this.gatherIceCandidates(); + await gatherIceCandidatePromise; } catch (error) { LoggerProxy.logger.warn(`Reachability:ClusterReachability#start --> Error: `, error); } diff --git a/packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts b/packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts index b2a23609004..8b76fe0eef3 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts +++ b/packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts @@ -15,6 +15,7 @@ describe('ClusterReachability', () => { let previousRTCPeerConnection; let clusterReachability; let fakePeerConnection; + let gatherIceCandidatesSpy; const emittedEvents: Record = { [Events.resultReady]: [], @@ -44,6 +45,8 @@ describe('ClusterReachability', () => { xtls: ['stun:xtls1.webex.com', 'stun:xtls2.webex.com:443'], }); + gatherIceCandidatesSpy = sinon.spy(clusterReachability, 'gatherIceCandidates'); + resetEmittedEvents(); clusterReachability.on(Events.resultReady, (data: ResultEventData) => { @@ -151,6 +154,10 @@ describe('ClusterReachability', () => { assert.calledOnceWithExactly(fakePeerConnection.createOffer, {offerToReceiveAudio: true}); assert.calledOnce(fakePeerConnection.setLocalDescription); + // Make sure that gatherIceCandidates is called before setLocalDescription + // as setLocalDescription triggers the ICE gathering process + assert.isTrue(gatherIceCandidatesSpy.calledBefore(fakePeerConnection.setLocalDescription)); + clusterReachability.abort(); await promise;