@webex/internal-plugin-metrics 3.0.0-beta.19 → 3.0.0-beta.190

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 (67) hide show
  1. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +134 -0
  2. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  3. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +451 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +511 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +106 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  9. package/dist/call-diagnostic/config.js +461 -0
  10. package/dist/call-diagnostic/config.js.map +1 -0
  11. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js +7 -0
  12. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js.map +1 -0
  13. package/dist/call-diagnostic/generated-types-temp/Event.js +7 -0
  14. package/dist/call-diagnostic/generated-types-temp/Event.js.map +1 -0
  15. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js +7 -0
  16. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js.map +1 -0
  17. package/dist/config.js +20 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/index.js +25 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/metrics.js +30 -30
  22. package/dist/metrics.js.map +1 -1
  23. package/dist/metrics.types.js +7 -0
  24. package/dist/metrics.types.js.map +1 -0
  25. package/dist/new-metrics.js +185 -0
  26. package/dist/new-metrics.js.map +1 -0
  27. package/dist/types/batcher.d.ts +2 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +189 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +324 -0
  31. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +31 -0
  32. package/dist/types/call-diagnostic/config.d.ts +57 -0
  33. package/dist/types/call-diagnostic/generated-types-temp/ClientEvent.d.ts +1112 -0
  34. package/dist/types/call-diagnostic/generated-types-temp/Event.d.ts +4851 -0
  35. package/dist/types/call-diagnostic/generated-types-temp/MediaQualityEvent.d.ts +2121 -0
  36. package/dist/types/client-metrics-batcher.d.ts +2 -0
  37. package/dist/types/config.d.ts +35 -0
  38. package/dist/types/index.d.ts +11 -0
  39. package/dist/types/metrics.d.ts +3 -0
  40. package/dist/types/metrics.types.d.ts +87 -0
  41. package/dist/types/new-metrics.d.ts +83 -0
  42. package/package.json +12 -8
  43. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +148 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +408 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.ts +528 -0
  46. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +102 -0
  47. package/src/call-diagnostic/config.ts +455 -0
  48. package/src/call-diagnostic/generated-types-temp/ClientEvent.ts +2357 -0
  49. package/src/call-diagnostic/generated-types-temp/Event.ts +7669 -0
  50. package/src/call-diagnostic/generated-types-temp/MediaQualityEvent.ts +2321 -0
  51. package/src/config.js +19 -0
  52. package/src/index.ts +39 -0
  53. package/src/metrics.js +25 -27
  54. package/src/metrics.types.ts +131 -0
  55. package/src/new-metrics.ts +170 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +243 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +474 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +722 -0
  59. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +76 -0
  60. package/test/unit/spec/metrics.js +65 -97
  61. package/test/unit/spec/new-metrics.ts +91 -0
  62. package/tsconfig.json +6 -0
  63. package/dist/call-diagnostic-events-batcher.js +0 -60
  64. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  65. package/src/call-diagnostic-events-batcher.js +0 -62
  66. package/src/index.js +0 -17
  67. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
package/src/config.js CHANGED
@@ -21,3 +21,22 @@ export default {
21
21
  batcherRetryPlateau: 32000,
22
22
  },
23
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,
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
@@ -6,14 +6,17 @@
6
6
 
7
7
  import {WebexPlugin} from '@webex/webex-core';
8
8
  import {BrowserDetection} from '@webex/common';
9
+ import {OS_NAME, OSMap, CLIENT_NAME} from './config';
9
10
 
10
- import {CLIENT_NAME} from './config';
11
11
  import Batcher from './batcher';
12
12
  import ClientMetricsBatcher from './client-metrics-batcher';
13
- import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
14
13
 
15
14
  const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
16
15
 
16
+ export function getOSNameInternal() {
17
+ return OSMap[getOSName()] ?? OS_NAME.OTHERS;
18
+ }
19
+
17
20
  function getSparkUserAgent(webex) {
18
21
  const {appName, appVersion, appPlatform} = webex?.config ?? {};
19
22
 
@@ -34,7 +37,6 @@ const Metrics = WebexPlugin.extend({
34
37
  children: {
35
38
  batcher: Batcher,
36
39
  clientMetricsBatcher: ClientMetricsBatcher,
37
- callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,
38
40
  },
39
41
 
40
42
  namespace: 'Metrics',
@@ -44,13 +46,12 @@ const Metrics = WebexPlugin.extend({
44
46
  },
45
47
 
46
48
  /**
47
- * This corresponds to #sendSemiStructured() in the deprecated metrics handler
49
+ * Returns the payload for submitting client metrics.
48
50
  * @param {string} eventName
49
- * @param {Object} props
50
- * @param {string} preLoginId
51
- * @returns {Object} HttpResponse object
51
+ * @param {any} props
52
+ * @returns {any} - the payload
52
53
  */
53
- submitClientMetrics(eventName, props = {}, preLoginId) {
54
+ getClientMetricsPayload(eventName, props) {
54
55
  if (!eventName) {
55
56
  throw Error('Missing behavioral metric name. Please provide one');
56
57
  }
@@ -59,22 +60,14 @@ const Metrics = WebexPlugin.extend({
59
60
  payload.tags = {
60
61
  ...props.tags,
61
62
  browser: getBrowserName(),
62
- os: getOSName(),
63
+ os: getOSNameInternal(),
63
64
 
64
65
  // Node does not like this so we need to check if it exists or not
65
66
  // eslint-disable-next-line no-undef
66
67
  domain:
67
68
  typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
68
- client_id: this.webex.credentials.config.client_id,
69
- user_id: this.webex.internal.device.userId,
70
69
  };
71
70
 
72
- try {
73
- payload.tags.org_id = this.webex.credentials.getOrgId();
74
- } catch {
75
- this.logger.info('metrics: unable to get orgId');
76
- }
77
-
78
71
  payload.fields = {
79
72
  ...props.fields,
80
73
  browser_version: getBrowserVersion(),
@@ -82,6 +75,7 @@ const Metrics = WebexPlugin.extend({
82
75
  sdk_version: this.webex.version,
83
76
  platform: 'Web',
84
77
  spark_user_agent: getSparkUserAgent(this.webex),
78
+ client_id: this.webex.credentials.config.client_id,
85
79
  };
86
80
 
87
81
  payload.type = props.type || this.webex.config.metrics.type;
@@ -93,7 +87,7 @@ const Metrics = WebexPlugin.extend({
93
87
  },
94
88
  locale: 'en-US',
95
89
  os: {
96
- name: getOSName(),
90
+ name: getOSNameInternal(),
97
91
  version: getOSVersion(),
98
92
  },
99
93
  };
@@ -106,6 +100,19 @@ const Metrics = WebexPlugin.extend({
106
100
  // is impossible so unable to use Date.now()
107
101
  payload.timestamp = new Date().valueOf();
108
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
+
109
116
  if (preLoginId) {
110
117
  const _payload = {
111
118
  metrics: [payload],
@@ -154,15 +161,6 @@ const Metrics = WebexPlugin.extend({
154
161
  })
155
162
  );
156
163
  },
157
-
158
- submitCallDiagnosticEvents(payload) {
159
- const event = {
160
- type: 'diagnostic-event',
161
- eventPayload: payload,
162
- };
163
-
164
- return this.callDiagnosticEventsBatcher.request(event);
165
- },
166
164
  });
167
165
 
168
166
  export default Metrics;
@@ -0,0 +1,131 @@
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
+ }) => void;
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;
@@ -0,0 +1,170 @@
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
+
21
+ /**
22
+ * Metrics plugin to centralize all types of metrics.
23
+ * @class
24
+ */
25
+ class Metrics extends WebexPlugin {
26
+ // eslint-disable-next-line no-use-before-define
27
+ static instance: Metrics;
28
+
29
+ // Call Diagnostic latencies
30
+ callDiagnosticLatencies: CallDiagnosticLatencies;
31
+ // Helper classes to handle the different types of metrics
32
+ callDiagnosticMetrics: CallDiagnosticMetrics;
33
+
34
+ /**
35
+ * Constructor
36
+ * @param args
37
+ * @constructor
38
+ * @private
39
+ * @returns
40
+ */
41
+ constructor(...args) {
42
+ super(...args);
43
+
44
+ this.onReady();
45
+ }
46
+
47
+ /**
48
+ * On Ready
49
+ */
50
+ private onReady() {
51
+ // @ts-ignore
52
+ this.webex.once('ready', () => {
53
+ // @ts-ignore
54
+ this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
55
+ // @ts-ignore
56
+ this.callDiagnosticLatencies = new CallDiagnosticLatencies({}, {parent: this.webex});
57
+ });
58
+ }
59
+
60
+ /**
61
+ * Used for internal purposes only
62
+ * @param args
63
+ */
64
+ submitInternalEvent({
65
+ name,
66
+ payload,
67
+ options,
68
+ }: {
69
+ name: InternalEvent['name'];
70
+ payload?: RecursivePartial<InternalEvent['payload']>;
71
+ options?: any;
72
+ }) {
73
+ if (name === 'internal.reset.join.latencies') {
74
+ this.callDiagnosticLatencies.clearTimestamps();
75
+ } else {
76
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Behavioral event
82
+ * @param args
83
+ */
84
+ submitBehavioralEvent({
85
+ name,
86
+ payload,
87
+ options,
88
+ }: {
89
+ name: BehavioralEvent['name'];
90
+ payload?: RecursivePartial<BehavioralEvent['payload']>;
91
+ options?: any;
92
+ }) {
93
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
94
+ throw new Error('Not implemented.');
95
+ }
96
+
97
+ /**
98
+ * Operational event
99
+ * @param args
100
+ */
101
+ submitOperationalEvent({
102
+ name,
103
+ payload,
104
+ options,
105
+ }: {
106
+ name: OperationalEvent['name'];
107
+ payload?: RecursivePartial<OperationalEvent['payload']>;
108
+ options?: any;
109
+ }) {
110
+ throw new Error('Not implemented.');
111
+ }
112
+
113
+ /**
114
+ * Call Analyzer: Media Quality Event
115
+ * @param args
116
+ */
117
+ submitMQE({
118
+ name,
119
+ payload,
120
+ options,
121
+ }: {
122
+ name: MediaQualityEvent['name'];
123
+ payload: RecursivePartial<MediaQualityEvent['payload']> & {
124
+ intervals: MediaQualityEvent['payload']['intervals'];
125
+ };
126
+ options: any;
127
+ }) {
128
+ this.callDiagnosticLatencies.saveTimestamp({key: name});
129
+ this.callDiagnosticMetrics.submitMQE({name, payload, options});
130
+ }
131
+
132
+ /**
133
+ * Call Analyzer: Feature Usage Event
134
+ * @param args
135
+ */
136
+ submitFeatureEvent({
137
+ name,
138
+ payload,
139
+ options,
140
+ }: {
141
+ name: FeatureEvent['name'];
142
+ payload?: RecursivePartial<FeatureEvent['payload']>;
143
+ options: any;
144
+ }) {
145
+ throw new Error('Not implemented.');
146
+ }
147
+
148
+ /**
149
+ * Call Analyzer: Client Event
150
+ * @public
151
+ * @param args
152
+ */
153
+ public submitClientEvent({
154
+ name,
155
+ payload,
156
+ options,
157
+ }: {
158
+ name: ClientEvent['name'];
159
+ payload?: RecursivePartial<ClientEvent['payload']>;
160
+ options: SubmitClientEventOptions;
161
+ }) {
162
+ this.callDiagnosticLatencies.saveTimestamp({
163
+ key: name,
164
+ options: {meetingId: options?.meetingId},
165
+ });
166
+ this.callDiagnosticMetrics.submitClientEvent({name, payload, options});
167
+ }
168
+ }
169
+
170
+ export default Metrics;