Skip to content

Commit

Permalink
fix(meetings): empty webrtc dumps when user closes the browser early (w…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-bazyl authored and parv_gour committed Sep 27, 2024
1 parent ecacc14 commit c6d85e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/@webex/plugin-meetings/src/rtcMetrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default class RtcMetrics {

connectionId: string;

initialMetricsSent: boolean;

/**
* Initialize the interval.
*
Expand All @@ -47,9 +49,7 @@ export default class RtcMetrics {
this.meetingId = meetingId;
this.webex = webex;
this.correlationId = correlationId;
this.setNewConnectionId();
// Send the first set of metrics at 5 seconds in the case of a user leaving the call shortly after joining.
setTimeout(this.sendMetricsInQueue.bind(this), 5 * 1000);
this.resetConnection();
}

/**
Expand Down Expand Up @@ -79,6 +79,13 @@ export default class RtcMetrics {

this.metricsQueue.push(data);

if (!this.initialMetricsSent && data.name === 'stats-report') {
// this is the first useful set of data (WCME gives it to us after 5s), send it out immediately
// in case the user is unhappy and closes the browser early
this.sendMetricsInQueue();
this.initialMetricsSent = true;
}

try {
// If a connection fails, send the rest of the metrics in queue and get a new connection id.
const parsedPayload = parseJsonPayload(data.payload);
Expand All @@ -88,7 +95,7 @@ export default class RtcMetrics {
parsedPayload.value === 'failed'
) {
this.sendMetricsInQueue();
this.setNewConnectionId();
this.resetConnection();
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -130,8 +137,9 @@ export default class RtcMetrics {
*
* @returns {void}
*/
private setNewConnectionId() {
private resetConnection() {
this.connectionId = uuid.v4();
this.initialMetricsSent = false;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions packages/@webex/plugin-meetings/test/unit/spec/rtcMetrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,35 @@ describe('RtcMetrics', () => {
metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
assert.calledOnce(anonymizeIpSpy);
})

it('should send metrics on first stats-report', () => {
assert.callCount(webex.request, 0);

metrics.addMetrics(FAKE_METRICS_ITEM);
assert.callCount(webex.request, 0);

// first stats-report should trigger a call to webex.request
metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
assert.callCount(webex.request, 1);
});

it('should send metrics on first stats-report after a new connection', () => {
assert.callCount(webex.request, 0);

// first stats-report should trigger a call to webex.request
metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
assert.callCount(webex.request, 1);

// subsequent stats-report doesn't trigger it
metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
assert.callCount(webex.request, 1);

// now, simulate a failure - that triggers a new connection and upload of the metrics
metrics.addMetrics(FAILURE_METRICS_ITEM);
assert.callCount(webex.request, 2);

// and another stats-report should trigger another upload of the metrics
metrics.addMetrics({ name: 'stats-report', payload: [STATS_WITH_IP] });
assert.callCount(webex.request, 3);
});
});

0 comments on commit c6d85e9

Please sign in to comment.