diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index 99ade64ea64..edff3f1de51 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -4904,6 +4904,8 @@ export default class Meeting extends StatelessWebexPlugin { ); } + this.cleanUpBeforeReconnection(); + return this.reconnectionManager .reconnect(options, async () => { await this.waitForRemoteSDPAnswer(); @@ -7032,6 +7034,23 @@ export default class Meeting extends StatelessWebexPlugin { } } + private async cleanUpBeforeReconnection(): Promise { + try { + // when media fails, we want to upload a webrtc dump to see whats going on + // this function is async, but returns once the stats have been gathered + await this.forceSendStatsReport({callFrom: 'cleanUpBeforeReconnection'}); + + if (this.statsAnalyzer) { + await this.statsAnalyzer.stopAnalyzer(); + } + } catch (error) { + LoggerProxy.logger.error( + 'Meeting:index#cleanUpBeforeReconnection --> Error during cleanup: ', + error + ); + } + } + /** * Creates an instance of LocusMediaRequest for this meeting - it is needed for doing any calls * to Locus /media API (these are used for sending Roap messages and updating audio/video mute status). diff --git a/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js b/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js index 8e02dd9c312..a94ea8b5737 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js +++ b/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js @@ -7695,11 +7695,11 @@ describe('plugin-meetings', () => { id: 'stream', getTracks: () => [{id: 'track', addEventListener: sinon.stub()}], }; - const simulateConnectionStateChange = (newState) => { + const simulateConnectionStateChange = async (newState) => { meeting.mediaProperties.webrtcMediaConnection.getConnectionState = sinon .stub() .returns(newState); - eventListeners[MediaConnectionEventNames.PEER_CONNECTION_STATE_CHANGED](); + await eventListeners[MediaConnectionEventNames.PEER_CONNECTION_STATE_CHANGED](); }; beforeEach(() => { @@ -7961,7 +7961,7 @@ describe('plugin-meetings', () => { meeting.reconnectionManager = new ReconnectionManager(meeting); meeting.reconnectionManager.iceReconnected = sinon.stub().returns(undefined); meeting.setNetworkStatus = sinon.stub().returns(undefined); - meeting.statsAnalyzer = {startAnalyzer: sinon.stub()}; + meeting.statsAnalyzer = {startAnalyzer: sinon.stub(), stopAnalyzer: sinon.stub()}; meeting.mediaProperties.webrtcMediaConnection = { // mock the on() method and store all the listeners on: sinon.stub().callsFake((event, listener) => { @@ -8036,10 +8036,10 @@ describe('plugin-meetings', () => { }); describe('CONNECTION_STATE_CHANGED event when state = "Failed"', () => { - const mockFailedEvent = () => { + const mockFailedEvent = async () => { meeting.setupMediaConnectionListeners(); - simulateConnectionStateChange(ConnectionState.Failed); + await simulateConnectionStateChange(ConnectionState.Failed); }; const checkBehavioralMetricSent = (hasMediaConnectionConnectedAtLeastOnce = false) => { @@ -8069,6 +8069,22 @@ describe('plugin-meetings', () => { assert.notCalled(webex.internal.newMetrics.submitClientEvent); checkBehavioralMetricSent(true); }); + + it('stop stats analyzer during reconnection ', async () => { + meeting.hasMediaConnectionConnectedAtLeastOnce = true; + meeting.statsAnalyzer.stopAnalyzer = sinon.stub().resolves(); + meeting.reconnectionManager = { + reconnect: sinon.stub().resolves(), + resetReconnectionTimer: () => {} + }; + meeting.currentMediaStatus = { + video: true + }; + + await mockFailedEvent(); + + assert.calledOnce(meeting.statsAnalyzer.stopAnalyzer); + }); }); describe('should send correct metrics for ROAP_FAILURE event', () => {