@webex/internal-plugin-metrics 3.0.0-beta.32 → 3.0.0-beta.321

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 (68) hide show
  1. package/dist/batcher.js +2 -1
  2. package/dist/batcher.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +456 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +819 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  11. package/dist/call-diagnostic/config.js +610 -0
  12. package/dist/call-diagnostic/config.js.map +1 -0
  13. package/dist/client-metrics-batcher.js +2 -1
  14. package/dist/client-metrics-batcher.js.map +1 -1
  15. package/dist/config.js +22 -2
  16. package/dist/config.js.map +1 -1
  17. package/dist/index.js +30 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/metrics.js +30 -30
  20. package/dist/metrics.js.map +1 -1
  21. package/dist/metrics.types.js +7 -0
  22. package/dist/metrics.types.js.map +1 -0
  23. package/dist/new-metrics.js +333 -0
  24. package/dist/new-metrics.js.map +1 -0
  25. package/dist/types/batcher.d.ts +2 -0
  26. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  27. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +194 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +417 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
  30. package/dist/types/call-diagnostic/config.d.ts +172 -0
  31. package/dist/types/client-metrics-batcher.d.ts +2 -0
  32. package/dist/types/config.d.ts +36 -0
  33. package/dist/types/index.d.ts +13 -0
  34. package/dist/types/metrics.d.ts +3 -0
  35. package/dist/types/metrics.types.d.ts +104 -0
  36. package/dist/types/new-metrics.d.ts +139 -0
  37. package/dist/types/utils.d.ts +6 -0
  38. package/dist/utils.js +27 -0
  39. package/dist/utils.js.map +1 -0
  40. package/package.json +13 -8
  41. package/src/batcher.js +1 -0
  42. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +75 -0
  43. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +419 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics.ts +861 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
  46. package/src/call-diagnostic/config.ts +666 -0
  47. package/src/client-metrics-batcher.js +1 -0
  48. package/src/config.js +20 -0
  49. package/src/index.ts +43 -0
  50. package/src/metrics.js +25 -27
  51. package/src/metrics.types.ts +160 -0
  52. package/src/new-metrics.ts +317 -0
  53. package/src/utils.ts +17 -0
  54. package/test/unit/spec/batcher.js +2 -0
  55. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +452 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +506 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1973 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
  59. package/test/unit/spec/client-metrics-batcher.js +2 -0
  60. package/test/unit/spec/metrics.js +66 -97
  61. package/test/unit/spec/new-metrics.ts +267 -0
  62. package/test/unit/spec/utils.ts +22 -0
  63. package/tsconfig.json +6 -0
  64. package/dist/call-diagnostic-events-batcher.js +0 -60
  65. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  66. package/src/call-diagnostic-events-batcher.js +0 -62
  67. package/src/index.js +0 -17
  68. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,36 @@
1
+ export const CLIENT_NAME: "webex-js-sdk";
2
+ declare namespace _default {
3
+ export namespace device {
4
+ namespace preDiscoveryServices {
5
+ const metricsServiceUrl: string;
6
+ const metrics: string;
7
+ }
8
+ }
9
+ export namespace metrics_1 {
10
+ const appType: string;
11
+ const batcherWait: number;
12
+ const batcherMaxCalls: number;
13
+ const batcherMaxWait: number;
14
+ const batcherRetryPlateau: number;
15
+ const waitForServiceTimeout: number;
16
+ }
17
+ export { metrics_1 as metrics };
18
+ }
19
+ export default _default;
20
+ export namespace OS_NAME {
21
+ const WINDOWS: string;
22
+ const MAC: string;
23
+ const IOS: string;
24
+ const ANDROID: string;
25
+ const CHROME: string;
26
+ const LINUX: string;
27
+ const OTHERS: string;
28
+ }
29
+ export const OSMap: {
30
+ 'Chrome OS': string;
31
+ macOS: string;
32
+ Windows: string;
33
+ iOS: string;
34
+ Android: string;
35
+ Linux: string;
36
+ };
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+ import '@webex/internal-plugin-device';
5
+ import config from './config';
6
+ import NewMetrics from './new-metrics';
7
+ import * as Utils from './utils';
8
+ import { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitOperationalEvent, SubmitMQE } from './metrics.types';
9
+ import * as CALL_DIAGNOSTIC_CONFIG from './call-diagnostic/config';
10
+ import * as CallDiagnosticUtils from './call-diagnostic/call-diagnostic-metrics.util';
11
+ export { default, getOSNameInternal } from './metrics';
12
+ export { config, CALL_DIAGNOSTIC_CONFIG, NewMetrics, Utils, CallDiagnosticUtils };
13
+ export type { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitMQE, SubmitOperationalEvent, };
@@ -0,0 +1,3 @@
1
+ export function getOSNameInternal(): any;
2
+ export default Metrics;
3
+ declare const Metrics: any;
@@ -0,0 +1,104 @@
1
+ import { ClientEvent as RawClientEvent, Event as RawEvent, MediaQualityEvent as RawMediaQualityEvent } from '@webex/event-dictionary-ts';
2
+ export type Event = Omit<RawEvent, 'event'> & {
3
+ event: RawClientEvent | RawMediaQualityEvent;
4
+ };
5
+ export type ClientEventError = NonNullable<RawClientEvent['errors']>[0];
6
+ export type EnvironmentType = NonNullable<RawEvent['origin']['environment']>;
7
+ export type NewEnvironmentType = NonNullable<RawEvent['origin']['newEnvironment']>;
8
+ export type ClientLaunchMethodType = NonNullable<RawEvent['origin']['clientInfo']>['clientLaunchMethod'];
9
+ export type SubmitClientEventOptions = {
10
+ meetingId?: string;
11
+ mediaConnections?: any[];
12
+ rawError?: any;
13
+ correlationId?: string;
14
+ preLoginId?: string;
15
+ environment?: EnvironmentType;
16
+ newEnvironmentType?: NewEnvironmentType;
17
+ clientLaunchMethod?: ClientLaunchMethodType;
18
+ webexConferenceIdStr?: string;
19
+ globalMeetingId?: string;
20
+ };
21
+ export type SubmitMQEOptions = {
22
+ meetingId: string;
23
+ mediaConnections?: any[];
24
+ networkType?: Event['origin']['networkType'];
25
+ webexConferenceIdStr?: string;
26
+ globalMeetingId?: string;
27
+ };
28
+ export type InternalEvent = {
29
+ name: 'internal.client.meetinginfo.request' | 'internal.client.meetinginfo.response' | 'internal.reset.join.latencies' | 'internal.client.meeting.click.joinbutton' | 'internal.host.meeting.participant.admitted' | 'internal.client.meeting.interstitial-window.showed' | 'internal.client.interstitial-window.click.joinbutton' | 'internal.client.add-media.turn-discovery.start' | 'internal.client.add-media.turn-discovery.end';
30
+ payload?: never;
31
+ options?: never;
32
+ };
33
+ export interface ClientEvent {
34
+ name: RawClientEvent['name'];
35
+ payload?: RawClientEvent;
36
+ options?: SubmitClientEventOptions;
37
+ }
38
+ export interface BehavioralEvent {
39
+ name: 'host.meeting.participant.admitted' | 'sdk.media-flow.started';
40
+ payload?: never;
41
+ options?: never;
42
+ }
43
+ export interface OperationalEvent {
44
+ name: never;
45
+ payload?: never;
46
+ options?: never;
47
+ }
48
+ export interface FeatureEvent {
49
+ name: never;
50
+ payload?: never;
51
+ options?: never;
52
+ }
53
+ export interface MediaQualityEvent {
54
+ name: RawMediaQualityEvent['name'];
55
+ payload?: RawMediaQualityEvent;
56
+ options: SubmitMQEOptions;
57
+ }
58
+ export type RecursivePartial<T> = {
59
+ [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
60
+ };
61
+ export type MetricEventNames = InternalEvent['name'] | ClientEvent['name'] | BehavioralEvent['name'] | OperationalEvent['name'] | FeatureEvent['name'] | MediaQualityEvent['name'];
62
+ export type ClientInfo = NonNullable<RawEvent['origin']['clientInfo']>;
63
+ export type ClientType = NonNullable<RawEvent['origin']['clientInfo']>['clientType'];
64
+ export type SubClientType = NonNullable<RawEvent['origin']['clientInfo']>['subClientType'];
65
+ export type NetworkType = NonNullable<RawEvent['origin']>['networkType'];
66
+ export type ClientSubServiceType = ClientEvent['payload']['webexSubServiceType'];
67
+ export type ClientEventPayload = RecursivePartial<ClientEvent['payload']>;
68
+ export type ClientEventLeaveReason = ClientEvent['payload']['leaveReason'];
69
+ export type ClientEventPayloadError = ClientEvent['payload']['errors'];
70
+ export type MediaQualityEventAudioSetupDelayPayload = NonNullable<MediaQualityEvent['payload']>['audioSetupDelay'];
71
+ export type MediaQualityEventVideoSetupDelayPayload = NonNullable<MediaQualityEvent['payload']>['videoSetupDelay'];
72
+ export type SubmitMQEPayload = RecursivePartial<MediaQualityEvent['payload']> & {
73
+ intervals: NonNullable<MediaQualityEvent['payload']>['intervals'];
74
+ };
75
+ export type SubmitInternalEvent = (args: {
76
+ name: InternalEvent['name'];
77
+ payload?: RecursivePartial<InternalEvent['payload']>;
78
+ options?: any;
79
+ }) => void;
80
+ export type SubmitBehavioralEvent = (args: {
81
+ name: BehavioralEvent['name'];
82
+ payload?: RecursivePartial<BehavioralEvent['payload']>;
83
+ options?: any;
84
+ }) => void;
85
+ export type SubmitClientEvent = (args: {
86
+ name: ClientEvent['name'];
87
+ payload?: RecursivePartial<ClientEvent['payload']>;
88
+ options?: SubmitClientEventOptions;
89
+ }) => Promise<any>;
90
+ export type SubmitOperationalEvent = (args: {
91
+ name: OperationalEvent['name'];
92
+ payload?: RecursivePartial<OperationalEvent['payload']>;
93
+ options?: any;
94
+ }) => void;
95
+ export type SubmitMQE = (args: {
96
+ name: MediaQualityEvent['name'];
97
+ payload: SubmitMQEPayload;
98
+ options: any;
99
+ }) => void;
100
+ export type BuildClientEventFetchRequestOptions = (args: {
101
+ name: ClientEvent['name'];
102
+ payload?: RecursivePartial<ClientEvent['payload']>;
103
+ options?: SubmitClientEventOptions;
104
+ }) => Promise<any>;
@@ -0,0 +1,139 @@
1
+ import { WebexPlugin } from '@webex/webex-core';
2
+ import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
3
+ import { RecursivePartial, ClientEvent, FeatureEvent, BehavioralEvent, OperationalEvent, MediaQualityEvent, InternalEvent, SubmitClientEventOptions } from './metrics.types';
4
+ import CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-latencies';
5
+ /**
6
+ * Metrics plugin to centralize all types of metrics.
7
+ * @class
8
+ */
9
+ declare class Metrics extends WebexPlugin {
10
+ static instance: Metrics;
11
+ callDiagnosticLatencies: CallDiagnosticLatencies;
12
+ callDiagnosticMetrics: CallDiagnosticMetrics;
13
+ /**
14
+ * Constructor
15
+ * @param args
16
+ * @constructor
17
+ * @private
18
+ * @returns
19
+ */
20
+ constructor(...args: any[]);
21
+ /**
22
+ * On Ready
23
+ */
24
+ private onReady;
25
+ /**
26
+ * Used for internal purposes only
27
+ * @param args
28
+ */
29
+ submitInternalEvent({ name, payload, options, }: {
30
+ name: InternalEvent['name'];
31
+ payload?: RecursivePartial<InternalEvent['payload']>;
32
+ options?: any;
33
+ }): void;
34
+ /**
35
+ * Behavioral event
36
+ * @param args
37
+ */
38
+ submitBehavioralEvent({ name, payload, options, }: {
39
+ name: BehavioralEvent['name'];
40
+ payload?: RecursivePartial<BehavioralEvent['payload']>;
41
+ options?: any;
42
+ }): void;
43
+ /**
44
+ * Operational event
45
+ * @param args
46
+ */
47
+ submitOperationalEvent({ name, payload, options, }: {
48
+ name: OperationalEvent['name'];
49
+ payload?: RecursivePartial<OperationalEvent['payload']>;
50
+ options?: any;
51
+ }): void;
52
+ /**
53
+ * Call Analyzer: Media Quality Event
54
+ * @param args
55
+ */
56
+ submitMQE({ name, payload, options, }: {
57
+ name: MediaQualityEvent['name'];
58
+ payload: RecursivePartial<MediaQualityEvent['payload']> & {
59
+ intervals: MediaQualityEvent['payload']['intervals'];
60
+ };
61
+ options: any;
62
+ }): void;
63
+ /**
64
+ * Call Analyzer: Feature Usage Event
65
+ * @param args
66
+ */
67
+ submitFeatureEvent({ name, payload, options, }: {
68
+ name: FeatureEvent['name'];
69
+ payload?: RecursivePartial<FeatureEvent['payload']>;
70
+ options: any;
71
+ }): void;
72
+ /**
73
+ * Call Analyzer: Client Event
74
+ * @public
75
+ * @param args
76
+ */
77
+ submitClientEvent({ name, payload, options, }: {
78
+ name: ClientEvent['name'];
79
+ payload?: RecursivePartial<ClientEvent['payload']>;
80
+ options?: SubmitClientEventOptions;
81
+ }): Promise<any>;
82
+ /**
83
+ * Submit a pre-login metric to clientmetrics
84
+ * @public
85
+ * @param payload
86
+ * @param preLoginId - pre-login ID of user
87
+ * @returns
88
+ */
89
+ postPreLoginMetric(payload: any, preLoginId: string): Promise<any>;
90
+ /**
91
+ * Issue request to alias a user's pre-login ID with their CI UUID
92
+ * @param {string} preLoginId
93
+ * @returns {Object} HttpResponse object
94
+ */
95
+ clientMetricsAliasUser(preLoginId: string): any;
96
+ /**
97
+ * Returns a promise that will resolve to fetch options for submitting a metric.
98
+ *
99
+ * This is to support quickly submitting metrics when the browser/tab is closing.
100
+ * Calling submitClientEvent will not work because there some async steps that will
101
+ * not complete before the browser is closed. Instead, we pre-gather all the
102
+ * information/options needed for the request(s), and then simply and quickly
103
+ * fire the fetch(es) when beforeUnload is triggered.
104
+ *
105
+ * We must use fetch instead of request because fetch has a keepalive option that
106
+ * allows the request it to outlive the page.
107
+ *
108
+ * Note: the timings values will be wrong, but setMetricTimingsAndFetch() will
109
+ * properly adjust them before submitting.
110
+ *
111
+ * @public
112
+ * @param {Object} arg
113
+ * @param {String} arg.name - event name
114
+ * @param {Object} arg.payload - event payload
115
+ * @param {Object} arg.options - other options
116
+ * @returns {Promise} promise that resolves to options to be used with fetch
117
+ */
118
+ buildClientEventFetchRequestOptions({ name, payload, options, }: {
119
+ name: ClientEvent['name'];
120
+ payload?: RecursivePartial<ClientEvent['payload']>;
121
+ options?: SubmitClientEventOptions;
122
+ }): Promise<any>;
123
+ /**
124
+ * Submits a metric from pre-built request options via the fetch API. Updates
125
+ * the "$timings" and "originTime" values to Date.now() since the existing times
126
+ * were set when the options were built (not submitted).
127
+
128
+ * @param {any} options - the pre-built request options for submitting a metric
129
+ * @returns {Promise} promise that resolves to the response object
130
+ */
131
+ setMetricTimingsAndFetch(options: any): Promise<any>;
132
+ /**
133
+ * Returns true if the specified serviceErrorCode maps to an expected error.
134
+ * @param {number} serviceErrorCode the service error code
135
+ * @returns {boolean}
136
+ */
137
+ isServiceErrorExpected(serviceErrorCode: number): boolean;
138
+ }
139
+ export default Metrics;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates common metadata for errors
3
+ * @param {any} error
4
+ * @returns {object}
5
+ */
6
+ export declare const generateCommonErrorMetadata: (error: any) => any;
package/dist/utils.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.generateCommonErrorMetadata = void 0;
9
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
10
+ /* eslint-disable import/prefer-default-export */
11
+ /**
12
+ * Generates common metadata for errors
13
+ * @param {any} error
14
+ * @returns {object}
15
+ */
16
+ var generateCommonErrorMetadata = function generateCommonErrorMetadata(error) {
17
+ if (error instanceof Error) {
18
+ return (0, _stringify.default)({
19
+ message: error === null || error === void 0 ? void 0 : error.message,
20
+ name: error === null || error === void 0 ? void 0 : error.name,
21
+ stack: error === null || error === void 0 ? void 0 : error.stack
22
+ });
23
+ }
24
+ return error;
25
+ };
26
+ exports.generateCommonErrorMetadata = generateCommonErrorMetadata;
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["generateCommonErrorMetadata","error","Error","message","name","stack"],"sources":["utils.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n/**\n * Generates common metadata for errors\n * @param {any} error\n * @returns {object}\n */\nexport const generateCommonErrorMetadata = (error) => {\n if (error instanceof Error) {\n return JSON.stringify({\n message: error?.message,\n name: error?.name,\n stack: error?.stack,\n });\n }\n\n return error;\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2B,CAAIC,KAAK,EAAK;EACpD,IAAIA,KAAK,YAAYC,KAAK,EAAE;IAC1B,OAAO,wBAAe;MACpBC,OAAO,EAAEF,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,OAAO;MACvBC,IAAI,EAAEH,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEG,IAAI;MACjBC,KAAK,EAAEJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEI;IAChB,CAAC,CAAC;EACJ;EAEA,OAAOJ,KAAK;AACd,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@webex/internal-plugin-metrics",
3
- "version": "3.0.0-beta.32",
3
+ "version": "3.0.0-beta.321",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "devMain": "src/index.js",
8
+ "types": "dist/types/index.d.ts",
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "https://github.com/webex/webex-js-sdk.git",
@@ -23,13 +24,17 @@
23
24
  "@sinonjs/fake-timers": "^6.0.1",
24
25
  "sinon": "^9.2.4"
25
26
  },
27
+ "scripts": {
28
+ "build": "yarn run -T tsc --declaration true --declarationDir ./dist/types"
29
+ },
26
30
  "dependencies": {
27
- "@webex/common": "3.0.0-beta.32",
28
- "@webex/common-timers": "3.0.0-beta.32",
29
- "@webex/internal-plugin-device": "3.0.0-beta.32",
30
- "@webex/internal-plugin-metrics": "3.0.0-beta.32",
31
- "@webex/test-helper-chai": "3.0.0-beta.32",
32
- "@webex/test-helper-mock-webex": "3.0.0-beta.32",
33
- "@webex/webex-core": "3.0.0-beta.32"
31
+ "@webex/common": "3.0.0-beta.321",
32
+ "@webex/common-timers": "3.0.0-beta.321",
33
+ "@webex/event-dictionary-ts": "^1.0.1329",
34
+ "@webex/internal-plugin-device": "3.0.0-beta.321",
35
+ "@webex/internal-plugin-metrics": "3.0.0-beta.321",
36
+ "@webex/test-helper-chai": "3.0.0-beta.321",
37
+ "@webex/test-helper-mock-webex": "3.0.0-beta.321",
38
+ "@webex/webex-core": "3.0.0-beta.321"
34
39
  }
35
40
  }
package/src/batcher.js CHANGED
@@ -40,6 +40,7 @@ const MetricsBatcher = Batcher.extend({
40
40
  body: {
41
41
  metrics: payload,
42
42
  },
43
+ waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,
43
44
  });
44
45
  },
45
46
 
@@ -0,0 +1,75 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ /* eslint-disable valid-jsdoc */
3
+
4
+ import {uniqueId} from 'lodash';
5
+ import Batcher from '../batcher';
6
+ import {prepareDiagnosticMetricItem} from './call-diagnostic-metrics.util';
7
+ import {CALL_DIAGNOSTIC_LOG_IDENTIFIER} from './config';
8
+ import {generateCommonErrorMetadata} from '../utils';
9
+
10
+ const CallDiagnosticEventsBatcher = Batcher.extend({
11
+ namespace: 'Metrics',
12
+
13
+ /**
14
+ * Prepare item
15
+ * @param item
16
+ * @returns
17
+ */
18
+ prepareItem(item) {
19
+ return Promise.resolve(prepareDiagnosticMetricItem(this.webex, item));
20
+ },
21
+
22
+ /**
23
+ * Prepare request, add time sensitive date etc.
24
+ * @param queue
25
+ * @returns
26
+ */
27
+ prepareRequest(queue) {
28
+ // Add sent timestamp
29
+ queue.forEach((item) => {
30
+ item.eventPayload.originTime = item.eventPayload.originTime || {};
31
+ item.eventPayload.originTime.sent = new Date().toISOString();
32
+ });
33
+
34
+ return Promise.resolve(queue);
35
+ },
36
+
37
+ /**
38
+ *
39
+ * @param payload
40
+ * @returns
41
+ */
42
+ submitHttpRequest(payload) {
43
+ const batchId = uniqueId('ca-batch-');
44
+
45
+ return this.webex
46
+ .request({
47
+ method: 'POST',
48
+ service: 'metrics',
49
+ resource: 'clientmetrics',
50
+ body: {
51
+ metrics: payload,
52
+ },
53
+ waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,
54
+ })
55
+ .then((res) => {
56
+ this.webex.logger.log(
57
+ CALL_DIAGNOSTIC_LOG_IDENTIFIER,
58
+ `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request successful.`
59
+ );
60
+
61
+ return res;
62
+ })
63
+ .catch((err) => {
64
+ this.webex.logger.error(
65
+ CALL_DIAGNOSTIC_LOG_IDENTIFIER,
66
+ `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request failed:`,
67
+ `error: ${generateCommonErrorMetadata(err)}`
68
+ );
69
+
70
+ return Promise.reject(err);
71
+ });
72
+ },
73
+ });
74
+
75
+ export default CallDiagnosticEventsBatcher;