Skip to content

Commit

Permalink
refactor(internal-plugin-metrics): move rtcMetrics from plugin-meetin…
Browse files Browse the repository at this point in the history
…gs (webex#3871)
  • Loading branch information
rarajes2 authored Oct 10, 2024
1 parent 4a00a43 commit 988ebd5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/@webex/internal-plugin-metrics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-l
import BehavioralMetrics from './behavioral-metrics';
import OperationalMetrics from './operational-metrics';
import BusinessMetrics from './business-metrics';
import RtcMetrics from './rtcMetrics';

registerInternalPlugin('metrics', Metrics, {
config,
Expand All @@ -47,6 +48,7 @@ export {
BehavioralMetrics,
OperationalMetrics,
BusinessMetrics,
RtcMetrics,
};
export type {
ClientEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable class-methods-use-this */
import {CallDiagnosticUtils} from '@webex/internal-plugin-metrics';
import uuid from 'uuid';
import * as CallDiagnosticUtils from '../call-diagnostic/call-diagnostic-metrics.util';
import RTC_METRICS from './constants';

const parseJsonPayload = (payload: any[]): any | null => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sinon from 'sinon';
import bowser from 'bowser';
import {assert} from '@webex/test-helper-chai';
import {WebexHttpError} from '@webex/webex-core';
import {BrowserDetection} from '@webex/common';
import window from 'global/window';
import {
CallDiagnosticLatencies,
CallDiagnosticMetrics,
Expand Down Expand Up @@ -1012,6 +1014,9 @@ describe('internal-plugin-metrics', () => {
const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
const getSubServiceTypeSpy = sinon.spy(cd, 'getSubServiceType');
const validatorSpy = sinon.spy(cd, 'validator');
sinon.stub(window.navigator, 'userAgent').get(() => userAgent);
sinon.stub(bowser, 'getParser').returns(userAgent);

const options = {
meetingId: fakeMeeting.id,
mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
Expand Down Expand Up @@ -1040,7 +1045,7 @@ describe('internal-plugin-metrics', () => {
assert.deepEqual(webexLoggerLogCalls[2].args, [
'call-diagnostic-events -> ',
'CallDiagnosticMetrics: @createClientEventObjectInMeeting => collected browser data',
'{"error":"unable to access window.navigator.userAgent"}',
`${JSON.stringify(userAgent)}`,
]);

assert.deepEqual(webexLoggerLogCalls[3].args, [
Expand Down Expand Up @@ -2768,11 +2773,11 @@ describe('internal-plugin-metrics', () => {
// The method is called in beforeEach itself. We are just testing it here
it('sets the received deviceInfo to call-diagnostics', () => {
const webexLoggerLogCalls = webex.logger.log.getCalls();
const device = { userId: 'userId', url: 'deviceUrl', orgId: 'orgId' };
const device = {userId: 'userId', url: 'deviceUrl', orgId: 'orgId'};

assert.deepEqual(webexLoggerLogCalls[0].args, [
'CallDiagnosticMetrics: @setDeviceInfo called',
device
device,
]);

assert.deepEqual(cd.device, device);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'jsdom-global/register';
import RtcMetrics from '@webex/plugin-meetings/src/rtcMetrics';
import RtcMetrics from '../../../../src/rtcMetrics';
import MockWebex from '@webex/test-helper-mock-webex';
import {assert} from '@webex/test-helper-chai';
import sinon from 'sinon';
Expand All @@ -25,6 +25,7 @@ describe('RtcMetrics', () => {

beforeEach(() => {
clock = sinon.useFakeTimers();
window.setInterval = setInterval;
webex = new MockWebex();
metrics = new RtcMetrics(webex, 'mock-meeting-id', 'mock-correlation-id');
anonymizeIpSpy = sandbox.spy(metrics, 'anonymizeIp');
Expand Down
2 changes: 1 addition & 1 deletion packages/@webex/plugin-meetings/src/media/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
LocalSystemAudioStream,
LocalMicrophoneStream,
} from '@webex/media-helpers';
import {RtcMetrics} from '@webex/internal-plugin-metrics';
import LoggerProxy from '../common/logs/logger-proxy';
import {MEDIA_TRACK_CONSTRAINT} from '../constants';
import Config from '../config';
import StaticConfig from '../common/config';
import BrowserDetection from '../common/browser-detection';
import RtcMetrics from '../rtcMetrics';

const {isBrowser} = BrowserDetection();

Expand Down
2 changes: 1 addition & 1 deletion packages/@webex/plugin-meetings/src/meeting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ClientEventLeaveReason,
CallDiagnosticUtils,
CALL_DIAGNOSTIC_CONFIG,
RtcMetrics,
} from '@webex/internal-plugin-metrics';
import {ClientEvent as RawClientEvent} from '@webex/event-dictionary-ts';

Expand Down Expand Up @@ -155,7 +156,6 @@ import ControlsOptionsManager from '../controls-options-manager';
import PermissionError from '../common/errors/permission';
import {LocusMediaRequest} from './locusMediaRequest';
import {ConnectionStateHandler, ConnectionStateEvent} from './connectionStateHandler';
import RtcMetrics from '../rtcMetrics';

// default callback so we don't call an undefined function, but in practice it should never be used
const DEFAULT_ICE_PHASE_CALLBACK = () => 'JOIN_MEETING_FINAL';
Expand Down
13 changes: 5 additions & 8 deletions packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'jsdom-global/register';
import {cloneDeep, forEach, isEqual, isUndefined} from 'lodash';
import sinon from 'sinon';
import * as InternalMediaCoreModule from '@webex/internal-media-core';
import * as RtcMetricsModule from '@webex/plugin-meetings/src/rtcMetrics';
import * as RemoteMediaManagerModule from '@webex/plugin-meetings/src/multistream/remoteMediaManager';
import StateMachine from 'javascript-state-machine';
import uuid from 'uuid';
Expand Down Expand Up @@ -2487,8 +2486,8 @@ describe('plugin-meetings', () => {
});

it('should create rtcMetrics and pass them to Media.createMediaConnection()', async () => {
const fakeRtcMetrics = {id: 'fake rtc metrics object'};
const rtcMetricsCtor = sinon.stub(RtcMetricsModule, 'default').returns(fakeRtcMetrics);
const setIntervalOriginal = window.setInterval;
window.setInterval = sinon.stub().returns(1);

// setup the minimum mocks required for multistream connection
fakeMediaConnection.createSendSlot = sinon.stub().returns({
Expand All @@ -2509,19 +2508,17 @@ describe('plugin-meetings', () => {
mediaSettings: {},
});

assert.calledOnceWithExactly(rtcMetricsCtor, webex, meeting.id, meeting.correlationId);

// check that rtcMetrics was passed to Media.createMediaConnection
assert.calledOnce(Media.createMediaConnection);
assert.calledWith(
Media.createMediaConnection,
true,
meeting.getMediaConnectionDebugId(),
meeting.id,
sinon.match({
rtcMetrics: fakeRtcMetrics,
})
sinon.match.hasNested('rtcMetrics.webex', webex)
);

window.setInterval = setIntervalOriginal;
});

it('should pass the turn server info to the peer connection', async () => {
Expand Down

0 comments on commit 988ebd5

Please sign in to comment.