@webex/internal-plugin-metrics 3.0.0-beta.2 → 3.0.0-beta.200

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +1 -3
  2. package/dist/batcher.js +3 -22
  3. package/dist/batcher.js.map +1 -1
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +56 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +451 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js +584 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +225 -0
  11. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  12. package/dist/call-diagnostic/config.js +461 -0
  13. package/dist/call-diagnostic/config.js.map +1 -0
  14. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js +7 -0
  15. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js.map +1 -0
  16. package/dist/call-diagnostic/generated-types-temp/Event.js +7 -0
  17. package/dist/call-diagnostic/generated-types-temp/Event.js.map +1 -0
  18. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js +7 -0
  19. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js.map +1 -0
  20. package/dist/client-metrics-batcher.js +1 -7
  21. package/dist/client-metrics-batcher.js.map +1 -1
  22. package/dist/config.js +21 -5
  23. package/dist/config.js.map +1 -1
  24. package/dist/index.js +26 -10
  25. package/dist/index.js.map +1 -1
  26. package/dist/metrics.js +43 -80
  27. package/dist/metrics.js.map +1 -1
  28. package/dist/metrics.types.js +7 -0
  29. package/dist/metrics.types.js.map +1 -0
  30. package/dist/new-metrics.js +249 -0
  31. package/dist/new-metrics.js.map +1 -0
  32. package/dist/types/batcher.d.ts +2 -0
  33. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  34. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +189 -0
  35. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +348 -0
  36. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +52 -0
  37. package/dist/types/call-diagnostic/config.d.ts +57 -0
  38. package/dist/types/call-diagnostic/generated-types-temp/ClientEvent.d.ts +1112 -0
  39. package/dist/types/call-diagnostic/generated-types-temp/Event.d.ts +4851 -0
  40. package/dist/types/call-diagnostic/generated-types-temp/MediaQualityEvent.d.ts +2121 -0
  41. package/dist/types/client-metrics-batcher.d.ts +2 -0
  42. package/dist/types/config.d.ts +35 -0
  43. package/dist/types/index.d.ts +11 -0
  44. package/dist/types/metrics.d.ts +3 -0
  45. package/dist/types/metrics.types.d.ts +92 -0
  46. package/dist/types/new-metrics.d.ts +119 -0
  47. package/package.json +12 -8
  48. package/src/batcher.js +33 -26
  49. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +51 -0
  50. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +408 -0
  51. package/src/call-diagnostic/call-diagnostic-metrics.ts +591 -0
  52. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +233 -0
  53. package/src/call-diagnostic/config.ts +455 -0
  54. package/src/call-diagnostic/generated-types-temp/ClientEvent.ts +2395 -0
  55. package/src/call-diagnostic/generated-types-temp/Event.ts +7762 -0
  56. package/src/call-diagnostic/generated-types-temp/MediaQualityEvent.ts +2321 -0
  57. package/src/client-metrics-batcher.js +3 -4
  58. package/src/config.js +25 -5
  59. package/src/index.ts +39 -0
  60. package/src/metrics.js +44 -58
  61. package/src/metrics.types.ts +137 -0
  62. package/src/new-metrics.ts +223 -0
  63. package/test/unit/spec/batcher.js +26 -15
  64. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +243 -0
  65. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +474 -0
  66. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +820 -0
  67. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +336 -0
  68. package/test/unit/spec/client-metrics-batcher.js +26 -15
  69. package/test/unit/spec/metrics.js +85 -116
  70. package/test/unit/spec/new-metrics.ts +153 -0
  71. package/tsconfig.json +6 -0
  72. package/dist/call-diagnostic-events-batcher.js +0 -70
  73. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  74. package/src/call-diagnostic-events-batcher.js +0 -62
  75. package/src/index.js +0 -17
  76. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -180
@@ -22,11 +22,10 @@ const ClientMetricsBatcher = Batcher.extend({
22
22
  service: 'metrics',
23
23
  resource: 'clientmetrics',
24
24
  body: {
25
- metrics: payload
26
- }
25
+ metrics: payload,
26
+ },
27
27
  });
28
- }
29
-
28
+ },
30
29
  });
31
30
 
32
31
  export default ClientMetricsBatcher;
package/src/config.js CHANGED
@@ -8,15 +8,35 @@ export const CLIENT_NAME = 'webex-js-sdk';
8
8
  export default {
9
9
  device: {
10
10
  preDiscoveryServices: {
11
- metricsServiceUrl: process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',
12
- metrics: process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1'
13
- }
11
+ metricsServiceUrl:
12
+ process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',
13
+ metrics: process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',
14
+ },
14
15
  },
15
16
  metrics: {
16
17
  appType: inBrowser ? 'browser' : 'nodejs',
17
18
  batcherWait: 500,
18
19
  batcherMaxCalls: 50,
19
20
  batcherMaxWait: 1500,
20
- batcherRetryPlateau: 32000
21
- }
21
+ batcherRetryPlateau: 32000,
22
+ },
23
+ };
24
+
25
+ export const OS_NAME = {
26
+ WINDOWS: 'windows',
27
+ MAC: 'mac',
28
+ IOS: 'ios',
29
+ ANDROID: 'android',
30
+ CHROME: 'chrome',
31
+ LINUX: 'linux',
32
+ OTHERS: 'other',
33
+ };
34
+
35
+ export const OSMap = {
36
+ 'Chrome OS': OS_NAME.CHROME,
37
+ macOS: OS_NAME.MAC,
38
+ Windows: OS_NAME.WINDOWS,
39
+ iOS: OS_NAME.IOS,
40
+ Android: OS_NAME.ANDROID,
41
+ Linux: OS_NAME.LINUX,
22
42
  };
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-device';
6
+
7
+ import {registerInternalPlugin} from '@webex/webex-core';
8
+
9
+ import Metrics from './metrics';
10
+ import config from './config';
11
+ import NewMetrics from './new-metrics';
12
+ import {
13
+ ClientEvent,
14
+ SubmitBehavioralEvent,
15
+ SubmitClientEvent,
16
+ SubmitInternalEvent,
17
+ SubmitOperationalEvent,
18
+ SubmitMQE,
19
+ } from './metrics.types';
20
+ import * as CALL_DIAGNOSTIC_CONFIG from './call-diagnostic/config';
21
+
22
+ registerInternalPlugin('metrics', Metrics, {
23
+ config,
24
+ });
25
+
26
+ registerInternalPlugin('newMetrics', NewMetrics, {
27
+ config,
28
+ });
29
+
30
+ export {default, getOSNameInternal} from './metrics';
31
+ export {config, CALL_DIAGNOSTIC_CONFIG, NewMetrics};
32
+ export type {
33
+ ClientEvent,
34
+ SubmitBehavioralEvent,
35
+ SubmitClientEvent,
36
+ SubmitInternalEvent,
37
+ SubmitMQE,
38
+ SubmitOperationalEvent,
39
+ };
package/src/metrics.js CHANGED
@@ -1,28 +1,24 @@
1
+ /* eslint-disable default-param-last */
2
+
1
3
  /*!
2
4
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
5
  */
4
6
 
5
7
  import {WebexPlugin} from '@webex/webex-core';
6
8
  import {BrowserDetection} from '@webex/common';
9
+ import {OS_NAME, OSMap, CLIENT_NAME} from './config';
7
10
 
8
- import {CLIENT_NAME} from './config';
9
11
  import Batcher from './batcher';
10
12
  import ClientMetricsBatcher from './client-metrics-batcher';
11
- import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
12
13
 
13
- const {
14
- getOSName,
15
- getOSVersion,
16
- getBrowserName,
17
- getBrowserVersion
18
- } = BrowserDetection();
14
+ const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
15
+
16
+ export function getOSNameInternal() {
17
+ return OSMap[getOSName()] ?? OS_NAME.OTHERS;
18
+ }
19
19
 
20
20
  function getSparkUserAgent(webex) {
21
- const {
22
- appName,
23
- appVersion,
24
- appPlatform
25
- } = webex?.config ?? {};
21
+ const {appName, appVersion, appPlatform} = webex?.config ?? {};
26
22
 
27
23
  let sparkUserAgent = CLIENT_NAME;
28
24
 
@@ -37,29 +33,25 @@ function getSparkUserAgent(webex) {
37
33
  return sparkUserAgent;
38
34
  }
39
35
 
40
-
41
36
  const Metrics = WebexPlugin.extend({
42
37
  children: {
43
38
  batcher: Batcher,
44
39
  clientMetricsBatcher: ClientMetricsBatcher,
45
- callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher
46
40
  },
47
41
 
48
42
  namespace: 'Metrics',
49
43
 
50
44
  submit(key, value) {
51
- return this.batcher.request(Object.assign({key}, value));
45
+ return this.batcher.request({key, ...value});
52
46
  },
53
47
 
54
-
55
48
  /**
56
- * This corresponds to #sendSemiStructured() in the deprecated metrics handler
49
+ * Returns the payload for submitting client metrics.
57
50
  * @param {string} eventName
58
- * @param {Object} props
59
- * @param {string} preLoginId
60
- * @returns {Object} HttpResponse object
51
+ * @param {any} props
52
+ * @returns {any} - the payload
61
53
  */
62
- submitClientMetrics(eventName, props = {}, preLoginId) {
54
+ getClientMetricsPayload(eventName, props) {
63
55
  if (!eventName) {
64
56
  throw Error('Missing behavioral metric name. Please provide one');
65
57
  }
@@ -68,49 +60,38 @@ const Metrics = WebexPlugin.extend({
68
60
  payload.tags = {
69
61
  ...props.tags,
70
62
  browser: getBrowserName(),
71
- os: getOSName(),
63
+ os: getOSNameInternal(),
72
64
 
73
65
  // Node does not like this so we need to check if it exists or not
74
66
  // eslint-disable-next-line no-undef
75
- domain: typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
76
- client_id: this.webex.credentials.config.client_id,
77
- user_id: this.webex.internal.device.userId
67
+ domain:
68
+ typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
78
69
  };
79
70
 
80
- try {
81
- payload.tags.org_id = this.webex.credentials.getOrgId();
82
- }
83
- catch {
84
- this.logger.info('metrics: unable to get orgId');
85
- }
86
-
87
-
88
71
  payload.fields = {
89
72
  ...props.fields,
90
73
  browser_version: getBrowserVersion(),
91
74
  os_version: getOSVersion(),
92
75
  sdk_version: this.webex.version,
93
76
  platform: 'Web',
94
- spark_user_agent: getSparkUserAgent(this.webex)
77
+ spark_user_agent: getSparkUserAgent(this.webex),
78
+ client_id: this.webex.credentials.config.client_id,
95
79
  };
96
80
 
97
-
98
81
  payload.type = props.type || this.webex.config.metrics.type;
99
82
 
100
-
101
83
  payload.context = {
102
84
  ...props.context,
103
85
  app: {
104
- version: this.webex.version
86
+ version: this.webex.version,
105
87
  },
106
88
  locale: 'en-US',
107
89
  os: {
108
- name: getOSName(),
109
- version: getOSVersion()
110
- }
90
+ name: getOSNameInternal(),
91
+ version: getOSVersion(),
92
+ },
111
93
  };
112
94
 
113
-
114
95
  if (props.eventPayload) {
115
96
  payload.eventPayload = props.eventPayload;
116
97
  }
@@ -119,9 +100,22 @@ const Metrics = WebexPlugin.extend({
119
100
  // is impossible so unable to use Date.now()
120
101
  payload.timestamp = new Date().valueOf();
121
102
 
103
+ return payload;
104
+ },
105
+
106
+ /**
107
+ * This corresponds to #sendSemiStructured() in the deprecated metrics handler
108
+ * @param {string} eventName
109
+ * @param {Object} props
110
+ * @param {string} preLoginId
111
+ * @returns {Object} HttpResponse object
112
+ */
113
+ submitClientMetrics(eventName, props = {}, preLoginId) {
114
+ const payload = this.getClientMetricsPayload(eventName, props);
115
+
122
116
  if (preLoginId) {
123
117
  const _payload = {
124
- metrics: [payload]
118
+ metrics: [payload],
125
119
  };
126
120
 
127
121
  // Do not batch these because pre-login events occur during onboarding, so we will be partially blind
@@ -144,12 +138,12 @@ const Metrics = WebexPlugin.extend({
144
138
  api: 'metrics',
145
139
  resource: 'clientmetrics',
146
140
  headers: {
147
- 'x-prelogin-userid': preLoginId
141
+ 'x-prelogin-userid': preLoginId,
148
142
  },
149
143
  body: {},
150
144
  qs: {
151
- alias: true
152
- }
145
+ alias: true,
146
+ },
153
147
  });
154
148
  },
155
149
 
@@ -161,20 +155,12 @@ const Metrics = WebexPlugin.extend({
161
155
  resource: 'clientmetrics-prelogin',
162
156
  headers: {
163
157
  authorization: token.toString(),
164
- 'x-prelogin-userid': preLoginId
158
+ 'x-prelogin-userid': preLoginId,
165
159
  },
166
- body: payload
167
- }));
160
+ body: payload,
161
+ })
162
+ );
168
163
  },
169
-
170
- submitCallDiagnosticEvents(payload) {
171
- const event = {
172
- type: 'diagnostic-event',
173
- eventPayload: payload
174
- };
175
-
176
- return this.callDiagnosticEventsBatcher.request(event);
177
- }
178
164
  });
179
165
 
180
166
  export default Metrics;
@@ -0,0 +1,137 @@
1
+ import {ClientEvent as RawClientEvent} from './call-diagnostic/generated-types-temp/ClientEvent';
2
+ import {Event as RawEvent} from './call-diagnostic/generated-types-temp/Event';
3
+ import {MediaQualityEvent as RawMediaQualityEvent} from './call-diagnostic/generated-types-temp/MediaQualityEvent';
4
+
5
+ export type Event = Omit<RawEvent, 'event'> & {event: RawClientEvent | RawMediaQualityEvent};
6
+
7
+ export type ClientEventError = NonNullable<RawClientEvent['errors']>[0];
8
+
9
+ export type SubmitClientEventOptions = {
10
+ meetingId?: string;
11
+ mediaConnections?: any[];
12
+ rawError?: any;
13
+ showToUser?: boolean;
14
+ correlationId?: string;
15
+ };
16
+
17
+ export type SubmitMQEOptions = {
18
+ meetingId: string;
19
+ mediaConnections?: any[];
20
+ networkType?: Event['origin']['networkType'];
21
+ };
22
+
23
+ export type InternalEvent = {
24
+ name:
25
+ | 'internal.client.meetinginfo.request'
26
+ | 'internal.client.meetinginfo.response'
27
+ | 'internal.reset.join.latencies'
28
+ | 'internal.client.interstitial-window.launched'
29
+ | 'internal.client.meeting.click.joinbutton'
30
+ | 'internal.host.meeting.participant.admitted'
31
+ | 'internal.client.meeting.interstitial-window.showed'
32
+ | 'internal.client.interstitial-window.click.joinbutton';
33
+ payload?: never;
34
+ options?: never;
35
+ };
36
+
37
+ export interface ClientEvent {
38
+ name: RawClientEvent['name'];
39
+ payload?: RawClientEvent;
40
+ options?: SubmitClientEventOptions;
41
+ }
42
+
43
+ export interface BehavioralEvent {
44
+ // TODO: not implemented
45
+ name: 'host.meeting.participant.admitted' | 'sdk.media-flow.started';
46
+ payload?: never;
47
+ options?: never;
48
+ }
49
+
50
+ export interface OperationalEvent {
51
+ // TODO: not implemented
52
+ name: never;
53
+ payload?: never;
54
+ options?: never;
55
+ }
56
+
57
+ export interface FeatureEvent {
58
+ // TODO: not implemented
59
+ name: never;
60
+ payload?: never;
61
+ options?: never;
62
+ }
63
+
64
+ export interface MediaQualityEvent {
65
+ name: RawMediaQualityEvent['name'];
66
+ payload?: RawMediaQualityEvent;
67
+ options: SubmitMQEOptions;
68
+ }
69
+
70
+ export type RecursivePartial<T> = {
71
+ [P in keyof T]?: T[P] extends (infer U)[]
72
+ ? RecursivePartial<U>[]
73
+ : T[P] extends object
74
+ ? RecursivePartial<T[P]>
75
+ : T[P];
76
+ };
77
+
78
+ export type MetricEventNames =
79
+ | InternalEvent['name']
80
+ | ClientEvent['name']
81
+ | BehavioralEvent['name']
82
+ | OperationalEvent['name']
83
+ | FeatureEvent['name']
84
+ | MediaQualityEvent['name'];
85
+
86
+ export type ClientType = NonNullable<RawEvent['origin']['clientInfo']>['clientType'];
87
+ export type SubClientType = NonNullable<RawEvent['origin']['clientInfo']>['subClientType'];
88
+ export type NetworkType = NonNullable<RawEvent['origin']>['networkType'];
89
+
90
+ export type ClientEventPayload = RecursivePartial<ClientEvent['payload']>;
91
+
92
+ export type MediaQualityEventAudioSetupDelayPayload = NonNullable<
93
+ MediaQualityEvent['payload']
94
+ >['audioSetupDelay'];
95
+ export type MediaQualityEventVideoSetupDelayPayload = NonNullable<
96
+ MediaQualityEvent['payload']
97
+ >['videoSetupDelay'];
98
+
99
+ export type SubmitMQEPayload = RecursivePartial<MediaQualityEvent['payload']> & {
100
+ intervals: NonNullable<MediaQualityEvent['payload']>['intervals'];
101
+ };
102
+
103
+ export type SubmitInternalEvent = (args: {
104
+ name: InternalEvent['name'];
105
+ payload?: RecursivePartial<InternalEvent['payload']>;
106
+ options?: any;
107
+ }) => void;
108
+
109
+ export type SubmitBehavioralEvent = (args: {
110
+ name: BehavioralEvent['name'];
111
+ payload?: RecursivePartial<BehavioralEvent['payload']>;
112
+ options?: any;
113
+ }) => void;
114
+
115
+ export type SubmitClientEvent = (args: {
116
+ name: ClientEvent['name'];
117
+ payload?: RecursivePartial<ClientEvent['payload']>;
118
+ options?: SubmitClientEventOptions;
119
+ }) => Promise<any>;
120
+
121
+ export type SubmitOperationalEvent = (args: {
122
+ name: OperationalEvent['name'];
123
+ payload?: RecursivePartial<OperationalEvent['payload']>;
124
+ options?: any;
125
+ }) => void;
126
+
127
+ export type SubmitMQE = (args: {
128
+ name: MediaQualityEvent['name'];
129
+ payload: SubmitMQEPayload;
130
+ options: any;
131
+ }) => void;
132
+
133
+ export type BuildClientEventFetchRequestOptions = (args: {
134
+ name: ClientEvent['name'];
135
+ payload?: RecursivePartial<ClientEvent['payload']>;
136
+ options?: SubmitClientEventOptions;
137
+ }) => Promise<any>;
@@ -0,0 +1,223 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable class-methods-use-this */
3
+ /* eslint-disable valid-jsdoc */
4
+
5
+ // @ts-ignore
6
+ import {WebexPlugin} from '@webex/webex-core';
7
+
8
+ import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
9
+ import {
10
+ RecursivePartial,
11
+ ClientEvent,
12
+ FeatureEvent,
13
+ BehavioralEvent,
14
+ OperationalEvent,
15
+ MediaQualityEvent,
16
+ InternalEvent,
17
+ SubmitClientEventOptions,
18
+ } from './metrics.types';
19
+ import CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-latencies';
20
+ import {setMetricTimings} from './call-diagnostic/call-diagnostic-metrics.util';
21
+
22
+ /**
23
+ * Metrics plugin to centralize all types of metrics.
24
+ * @class
25
+ */
26
+ class Metrics extends WebexPlugin {
27
+ // eslint-disable-next-line no-use-before-define
28
+ static instance: Metrics;
29
+
30
+ // Call Diagnostic latencies
31
+ callDiagnosticLatencies: CallDiagnosticLatencies;
32
+ // Helper classes to handle the different types of metrics
33
+ callDiagnosticMetrics: CallDiagnosticMetrics;
34
+
35
+ /**
36
+ * Constructor
37
+ * @param args
38
+ * @constructor
39
+ * @private
40
+ * @returns
41
+ */
42
+ constructor(...args) {
43
+ super(...args);
44
+
45
+ this.onReady();
46
+ }
47
+
48
+ /**
49
+ * On Ready
50
+ */
51
+ private onReady() {
52
+ // @ts-ignore
53
+ this.webex.once('ready', () => {
54
+ // @ts-ignore
55
+ this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
56
+ // @ts-ignore
57
+ this.callDiagnosticLatencies = new CallDiagnosticLatencies({}, {parent: this.webex});
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Used for internal purposes only
63
+ * @param args
64
+ */
65
+ submitInternalEvent({
66
+ name,
67
+ payload,
68
+ options,
69
+ }: {
70
+ name: InternalEvent['name'];
71
+ payload?: RecursivePartial<InternalEvent['payload']>;
72
+ options?: any;
73
+ }) {
74
+ if (name === 'internal.reset.join.latencies') {
75
+ this.callDiagnosticLatencies.clearTimestamps();
76
+ } else {
77
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Behavioral event
83
+ * @param args
84
+ */
85
+ submitBehavioralEvent({
86
+ name,
87
+ payload,
88
+ options,
89
+ }: {
90
+ name: BehavioralEvent['name'];
91
+ payload?: RecursivePartial<BehavioralEvent['payload']>;
92
+ options?: any;
93
+ }) {
94
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
95
+ throw new Error('Not implemented.');
96
+ }
97
+
98
+ /**
99
+ * Operational event
100
+ * @param args
101
+ */
102
+ submitOperationalEvent({
103
+ name,
104
+ payload,
105
+ options,
106
+ }: {
107
+ name: OperationalEvent['name'];
108
+ payload?: RecursivePartial<OperationalEvent['payload']>;
109
+ options?: any;
110
+ }) {
111
+ throw new Error('Not implemented.');
112
+ }
113
+
114
+ /**
115
+ * Call Analyzer: Media Quality Event
116
+ * @param args
117
+ */
118
+ submitMQE({
119
+ name,
120
+ payload,
121
+ options,
122
+ }: {
123
+ name: MediaQualityEvent['name'];
124
+ payload: RecursivePartial<MediaQualityEvent['payload']> & {
125
+ intervals: MediaQualityEvent['payload']['intervals'];
126
+ };
127
+ options: any;
128
+ }) {
129
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
130
+ this.callDiagnosticMetrics.submitMQE({name, payload, options});
131
+ }
132
+
133
+ /**
134
+ * Call Analyzer: Feature Usage Event
135
+ * @param args
136
+ */
137
+ submitFeatureEvent({
138
+ name,
139
+ payload,
140
+ options,
141
+ }: {
142
+ name: FeatureEvent['name'];
143
+ payload?: RecursivePartial<FeatureEvent['payload']>;
144
+ options: any;
145
+ }) {
146
+ throw new Error('Not implemented.');
147
+ }
148
+
149
+ /**
150
+ * Call Analyzer: Client Event
151
+ * @public
152
+ * @param args
153
+ */
154
+ public submitClientEvent({
155
+ name,
156
+ payload,
157
+ options,
158
+ }: {
159
+ name: ClientEvent['name'];
160
+ payload?: RecursivePartial<ClientEvent['payload']>;
161
+ options?: SubmitClientEventOptions;
162
+ }): Promise<any> {
163
+ this.callDiagnosticLatencies.saveTimestamp({
164
+ key: name,
165
+ options: {meetingId: options?.meetingId},
166
+ });
167
+
168
+ return this.callDiagnosticMetrics.submitClientEvent({name, payload, options});
169
+ }
170
+
171
+ /**
172
+ * Returns a promise that will resolve to fetch options for submitting a metric.
173
+ *
174
+ * This is to support quickly submitting metrics when the browser/tab is closing.
175
+ * Calling submitClientEvent will not work because there some async steps that will
176
+ * not complete before the browser is closed. Instead, we pre-gather all the
177
+ * information/options needed for the request(s), and then simply and quickly
178
+ * fire the fetch(es) when beforeUnload is triggered.
179
+ *
180
+ * We must use fetch instead of request because fetch has a keepalive option that
181
+ * allows the request it to outlive the page.
182
+ *
183
+ * Note: the timings values will be wrong, but setMetricTimingsAndFetch() will
184
+ * properly adjust them before submitting.
185
+ *
186
+ * @public
187
+ * @param {Object} arg
188
+ * @param {String} arg.name - event name
189
+ * @param {Object} arg.payload - event payload
190
+ * @param {Object} arg.options - other options
191
+ * @returns {Promise} promise that resolves to options to be used with fetch
192
+ */
193
+ public async buildClientEventFetchRequestOptions({
194
+ name,
195
+ payload,
196
+ options,
197
+ }: {
198
+ name: ClientEvent['name'];
199
+ payload?: RecursivePartial<ClientEvent['payload']>;
200
+ options?: SubmitClientEventOptions;
201
+ }): Promise<any> {
202
+ return this.callDiagnosticMetrics.buildClientEventFetchRequestOptions({
203
+ name,
204
+ payload,
205
+ options,
206
+ });
207
+ }
208
+
209
+ /**
210
+ * Submits a metric from pre-built request options via the fetch API. Updates
211
+ * the "$timings" and "originTime" values to Date.now() since the existing times
212
+ * were set when the options were built (not submitted).
213
+
214
+ * @param {any} options - the pre-built request options for submitting a metric
215
+ * @returns {Promise} promise that resolves to the response object
216
+ */
217
+ public setMetricTimingsAndFetch(options: any): Promise<any> {
218
+ // @ts-ignore
219
+ return this.webex.setTimingsAndFetch(setMetricTimings(options));
220
+ }
221
+ }
222
+
223
+ export default Metrics;