diff --git a/packages/@webex/internal-plugin-metrics/src/index.ts b/packages/@webex/internal-plugin-metrics/src/index.ts index 7247332be85..551d7ca4453 100644 --- a/packages/@webex/internal-plugin-metrics/src/index.ts +++ b/packages/@webex/internal-plugin-metrics/src/index.ts @@ -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, @@ -47,6 +48,7 @@ export { BehavioralMetrics, OperationalMetrics, BusinessMetrics, + RtcMetrics, }; export type { ClientEvent, diff --git a/packages/@webex/plugin-meetings/src/rtcMetrics/constants.ts b/packages/@webex/internal-plugin-metrics/src/rtcMetrics/constants.ts similarity index 100% rename from packages/@webex/plugin-meetings/src/rtcMetrics/constants.ts rename to packages/@webex/internal-plugin-metrics/src/rtcMetrics/constants.ts diff --git a/packages/@webex/plugin-meetings/src/rtcMetrics/index.ts b/packages/@webex/internal-plugin-metrics/src/rtcMetrics/index.ts similarity index 98% rename from packages/@webex/plugin-meetings/src/rtcMetrics/index.ts rename to packages/@webex/internal-plugin-metrics/src/rtcMetrics/index.ts index 6e9f6790011..cc1f3f6b415 100644 --- a/packages/@webex/plugin-meetings/src/rtcMetrics/index.ts +++ b/packages/@webex/internal-plugin-metrics/src/rtcMetrics/index.ts @@ -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 => { diff --git a/packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts b/packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts index 496de75ce26..6a08680e0e8 100644 --- a/packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +++ b/packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts @@ -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, @@ -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'}], @@ -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, [ @@ -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); diff --git a/packages/@webex/plugin-meetings/test/unit/spec/rtcMetrics/index.ts b/packages/@webex/internal-plugin-metrics/test/unit/spec/rtcMetrics/index.ts similarity index 98% rename from packages/@webex/plugin-meetings/test/unit/spec/rtcMetrics/index.ts rename to packages/@webex/internal-plugin-metrics/test/unit/spec/rtcMetrics/index.ts index cdcc25f3430..12eebc0e31c 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/rtcMetrics/index.ts +++ b/packages/@webex/internal-plugin-metrics/test/unit/spec/rtcMetrics/index.ts @@ -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'; @@ -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'); diff --git a/packages/@webex/plugin-meetings/src/media/index.ts b/packages/@webex/plugin-meetings/src/media/index.ts index eac32f8e533..28c014e4852 100644 --- a/packages/@webex/plugin-meetings/src/media/index.ts +++ b/packages/@webex/plugin-meetings/src/media/index.ts @@ -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(); diff --git a/packages/@webex/plugin-meetings/src/meeting/index.ts b/packages/@webex/plugin-meetings/src/meeting/index.ts index 526fd355080..c1d14b2dc48 100644 --- a/packages/@webex/plugin-meetings/src/meeting/index.ts +++ b/packages/@webex/plugin-meetings/src/meeting/index.ts @@ -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'; @@ -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'; 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 294a61a6846..f9bc7b813dc 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js +++ b/packages/@webex/plugin-meetings/test/unit/spec/meeting/index.js @@ -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'; @@ -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({ @@ -2509,8 +2508,6 @@ 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( @@ -2518,10 +2515,10 @@ describe('plugin-meetings', () => { 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 () => {