@observertc/client-monitor-js 3.3.1 → 3.4.0

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.
package/README.md CHANGED
@@ -1,23 +1,22 @@
1
- Javascript library to monitor WebRTC applications
2
- ---
1
+ ## Javascript library to monitor WebRTC applications
3
2
 
4
3
  @observertc/client-monitor-js is a client side library to monitor [WebRTCStats](https://www.w3.org/TR/webrtc-stats/) and to integrate your app to observertc components.
5
4
 
6
5
  Table of Contents:
7
6
 
8
- * [Quick Start](#quick-start)
9
- * [Integrations](#integrations)
10
- - [Mediasoup](#mediasoup)
11
- * [Detectors and Alerts](#detectors-and-alerts)
12
- - [Audio Desync Detector](#audio-desync-detector)
13
- - [CPU Performance Detector](#cpu-performance-detector)
14
- * [Calculated updates](#calculated-updates)
15
- * [Configurations](#configurations)
16
- * [NPM package](#npm-package)
17
- * [API docs](#api-docs)
18
- * [Schemas](#schemas)
19
- * [Getting Involved](#getting-involved)
20
- * [License](#license)
7
+ - [Quick Start](#quick-start)
8
+ - [Integrations](#integrations)
9
+ - [Mediasoup](#mediasoup)
10
+ - [Detectors and Alerts](#detectors-and-alerts)
11
+ - [Audio Desync Detector](#audio-desync-detector)
12
+ - [CPU Performance Detector](#cpu-performance-detector)
13
+ - [Calculated updates](#calculated-updates)
14
+ - [Configurations](#configurations)
15
+ - [NPM package](#npm-package)
16
+ - [API docs](#api-docs)
17
+ - [Schemas](#schemas)
18
+ - [Getting Involved](#getting-involved)
19
+ - [License](#license)
21
20
 
22
21
  ## Qucik Start
23
22
 
@@ -38,9 +37,8 @@ const config = {
38
37
  const monitor = createClientMonitor(config);
39
38
  const statsCollector = monitor.collectors.collectFromRTCPeerConnection(peerConnection);
40
39
 
41
- monitor.on('stats-collected', () => {
42
- const storage = monitor.storage;
43
- for (const inboundRtp of storage.inboundRtps()) {
40
+ monitor.on("stats-collected", () => {
41
+ for (const inboundRtp of monitor.inboundRtps) {
44
42
  const trackId = inboundRtp.getTrackId();
45
43
  const remoteOutboundRtp = inboundRtp.getRemoteOutboundRtp();
46
44
  console.log(trackId, inboundRtp.stats, remoteOutboundRtp.stats);
@@ -51,11 +49,11 @@ statsCollector.close();
51
49
  ```
52
50
 
53
51
  The above example do as follows:
54
- 1. create a client monitor, which collect stats every 5s
55
- 2. setup a stats collector from a peer connection
56
- 3. register an event called after stats are collected
57
- 4. print out the inbound rtps and then close the stats collector we registered in step 3.
58
52
 
53
+ 1. create a client monitor, which collect stats every 5s
54
+ 2. setup a stats collector from a peer connection
55
+ 3. register an event called after stats are collected
56
+ 4. print out the inbound rtps and then close the stats collector we registered in step 3.
59
57
 
60
58
  ## Integrations
61
59
 
@@ -72,29 +70,28 @@ const config = {
72
70
  const monitor = createClientMonitor(config);
73
71
  const mediasoupStatsCollector = monitor.collectors.collectFromMediasoupDevice(mediasoupDevice);
74
72
 
75
- monitor.on('stats-collected', () => {
73
+ monitor.on("stats-collected", () => {
76
74
  // do your stuff
77
75
 
78
- // you can close detach mediasoup
76
+ // you can close detach mediasoup
79
77
  // collector by calling the close
80
78
  mediasoupStatsCollector.close();
81
- })
79
+ });
82
80
  ```
83
81
 
84
- **Important Note**: The created collector is hooked on the device 'newtransport' event,
82
+ **Important Note**: The created collector is hooked on the device 'newtransport' event,
85
83
  and can detect transports automatically when they are created after the device is added.
86
84
  If you create transports before you add the device to the monitor,
87
- transports you created before will not be monitored automatically, you need to add them
85
+ transports you created before will not be monitored automatically, you need to add them
88
86
  to the statscollector, like this:
89
87
 
90
88
  ```javascript
91
- const myTransport = // your transport created before the device is added to the monitor
92
- mediasoupStatsCollector.addTransport(myTransport)
89
+ const myTransport = mediasoupStatsCollector.addTransport(myTransport); // your transport created before the device is added to the monitor
93
90
  ```
94
91
 
95
92
  ## Calculated Updates
96
93
 
97
- The Calculated Updates lets you observer metrics derived from the polled webrtc stats captured by the library. These calculated updates provide a richer, more nuanced understanding of your application's client-side behavior, offering valuable insights beyond what raw stats metrics can give you.
94
+ The Calculated Updates lets you observer metrics derived from the polled webrtc stats captured by the library. These calculated updates provide a richer, more nuanced understanding of your application's client-side behavior, offering valuable insights beyond what raw stats metrics can give you.
98
95
 
99
96
  ### Storage Updates
100
97
 
@@ -106,88 +103,82 @@ const monitor = createClientMonitor({
106
103
  collectingPeriodInMs: 2000,
107
104
  });
108
105
 
109
- const storage = monitor.storage;
110
106
  monitor.on('stats-collected', () => {
111
- console.log('average RTT in seconds', storage.avgRttInS);
112
- console.log('Sending audio bitrate', storage.sendingAudioBitrate);
113
- console.log('Sending video bitrate', storage.sendingVideoBitrate);
114
- console.log('Receiving audio bitrate', storage.receivingAudioBitrate);
115
- console.log('Receiving video bitrate', storage.receivingVideoBitrate);
116
-
107
+ console.log('average RTT in seconds', monitor.avgRttInS);
108
+ console.log('Sending audio bitrate', monitor.sendingAudioBitrate);
109
+ console.log('Sending video bitrate', monitor.sendingVideoBitrate);
110
+ console.log('Receiving audio bitrate', monitor.receivingAudioBitrate);
111
+ console.log('Receiving video bitrate', monitor.receivingVideoBitrate);
112
+ });
117
113
  ```
118
114
 
119
115
  ### PeerConnection Updates
120
116
 
121
117
  ```javascript
122
- import { createClientMonitor } from 'client-monitor-js';
118
+ import { createClientMonitor } from "client-monitor-js";
123
119
 
124
120
  // Create a ClientMonitor instance
125
121
  const monitor = createClientMonitor({
126
122
  collectingPeriodInMs: 2000,
127
123
  });
128
124
 
129
- const storage = monitor.storage;
130
- monitor.on('stats-collected', () => {
131
- for (const peerConnection of storage.peerConnections()) {
132
- console.log('average RTT in seconds', peerConnection.avgRttInS);
133
- console.log('Sending audio bitrate on PC', peerConnection.sendingAudioBitrate);
134
- console.log('Sending video bitrate on PC', peerConnection.sendingVideoBitrate);
135
- console.log('Receiving audio bitrate on PC', peerConnection.receivingAudioBitrate);
136
- console.log('Receiving video bitrate on PC', peerConnection.receivingVideoBitrate);
125
+ monitor.on("stats-collected", () => {
126
+ for (const peerConnection of monitor.peerConnections) {
127
+ console.log("average RTT in seconds", peerConnection.avgRttInS);
128
+ console.log("Sending audio bitrate on PC", peerConnection.sendingAudioBitrate);
129
+ console.log("Sending video bitrate on PC", peerConnection.sendingVideoBitrate);
130
+ console.log("Receiving audio bitrate on PC", peerConnection.receivingAudioBitrate);
131
+ console.log("Receiving video bitrate on PC", peerConnection.receivingVideoBitrate);
137
132
  }
138
133
  });
139
-
140
134
  ```
141
135
 
142
136
  ### Inbound RTP stats updates
143
137
 
144
138
  ```javascript
145
- import { createClientMonitor } from 'client-monitor-js';
139
+ import { createClientMonitor } from "client-monitor-js";
146
140
 
147
141
  // Create a ClientMonitor instance
148
142
  const monitor = createClientMonitor({
149
143
  collectingPeriodInMs: 2000,
150
144
  });
151
145
 
152
- const storage = monitor.storage;
153
- monitor.on('stats-collected', () => {
154
- for (const inboundRtp of storage.inboundRtps()) {
155
-
156
- console.log('mean opinion score for inbound-rtp', inboundRtp.score);
146
+ monitor.on("stats-collected", () => {
147
+ for (const inboundRtp of monitor.inboundRtps) {
148
+ console.log("mean opinion score for inbound-rtp", inboundRtp.score);
157
149
 
158
- console.log('receiving bitrate', inboundRtp.receivingBitrate);
159
- console.log('lost packets since last stats-collected', inboundRtp.lostPackets);
160
- console.log('received packets since last stats-collected', inboundRtp.receivedPackets);
161
- console.log('decoded frames since last stats-collected', inboundRtp.decodedFrames);
150
+ console.log("receiving bitrate", inboundRtp.receivingBitrate);
151
+ console.log("lost packets since last stats-collected", inboundRtp.lostPackets);
152
+ console.log("received packets since last stats-collected", inboundRtp.receivedPackets);
153
+ console.log("decoded frames since last stats-collected", inboundRtp.decodedFrames);
162
154
  }
163
155
  });
164
-
165
156
  ```
166
157
 
167
158
  ### Outbound RTP stats updates
168
159
 
169
160
  ```javascript
170
- import { createClientMonitor } from 'client-monitor-js';
161
+ import { createClientMonitor } from "client-monitor-js";
171
162
 
172
163
  // Create a ClientMonitor instance
173
164
  const monitor = createClientMonitor({
174
165
  collectingPeriodInMs: 2000,
175
166
  });
176
167
 
177
- const storage = monitor.storage;
178
- monitor.on('stats-collected', () => {
179
- for (const outboundRtp of storage.outboundRtps()) {
168
+ monitor.on("stats-collected", () => {
169
+ for (const outboundRtp of monitor.outboundRtps) {
170
+ console.log("stability score outbound-rtp", outboundRtp.score);
180
171
 
181
- console.log('stability score outbound-rtp', outboundRtp.score);
172
+ console.log("sending bitrate", outboundRtp.sendingBitrate);
173
+ console.log("sent packets since last stats-collected", outboundRtp.sentPackets);
182
174
 
183
- console.log('sending bitrate', outboundRtp.sendingBitrate);
184
- console.log('sent packets since last stats-collected', outboundRtp.sentPackets);
185
-
186
175
  const remoteInboundRtp = outboundRtp.getRemoteInboundRtp();
187
- console.log('Received packets on remote inbound-rtp belongs to this outbound-rtp', remoteInboundRtp?.receivedPackets);
176
+ console.log(
177
+ "Received packets on remote inbound-rtp belongs to this outbound-rtp",
178
+ remoteInboundRtp?.receivedPackets
179
+ );
188
180
  }
189
181
  });
190
-
191
182
  ```
192
183
 
193
184
  ## Detectors and Alerts
@@ -195,8 +186,9 @@ monitor.on('stats-collected', () => {
195
186
  Detectors and alerts provide events of tracking and responding to anomalies or performance issues based on the polled stats. Detectors are components that continuously monitor for specific conditions in the polled stats, and set an alert if certain thresholds are hit. You can subscribe to alerts of an instantiated client-monitor-js and configure detectors via initial configurations.
196
187
 
197
188
  List of built-in alerts:
198
- * `audio-desync-alert`: triggered when for an audio track several acceleration and deceleration is detected in a short amount of time indicating that the controlling system tries compensate discrepancies.
199
- * `cpu-performance-alert`: triggered whenever a browser detects quality limitation becasue of CPU, or the number of decoded frames per sec hit a certain threshold
189
+
190
+ - `audio-desync-alert`: triggered when for an audio track several acceleration and deceleration is detected in a short amount of time indicating that the controlling system tries compensate discrepancies.
191
+ - `cpu-performance-alert`: triggered whenever a browser detects quality limitation becasue of CPU, or the number of decoded frames per sec hit a certain threshold
200
192
 
201
193
  ### Audio Desync Detector
202
194
 
@@ -275,24 +267,19 @@ const config = {
275
267
  /**
276
268
  * By setting it, the monitor calls the added statsCollectors periodically
277
269
  * and pulls the stats.
278
- *
279
- * DEFAULT: undefined
270
+ *
271
+ * DEFAULT: 5000
280
272
  */
281
273
  collectingPeriodInMs: 5000,
282
- /**
283
- * By setting it, the monitor make samples periodically.
284
- *
285
- * DEFAULT: undefined
286
- */
287
- samplingPeriodInMs: 10000,
288
274
 
289
275
  /**
290
- * This is the interval the monitor periodically checks
291
- * if collecting or sampling action should be invoked or not.
292
- *
293
- * DEFAULT: if collecting or sampling period is set the default value is 1000, otherwise it's undefined
276
+ * By setting this, the observer makes samples after n number or collected stats.
277
+ *
278
+ * For example if the value is 10, the observer makes a sample after 10 collected stats (in every 10 collectingPeriodInMs).
279
+ *
280
+ * DEFAULT: 1
294
281
  */
295
- tickingTimeInMs: 10000,
282
+ samplingTick: 1,
296
283
  };
297
284
  ```
298
285
 
@@ -308,11 +295,10 @@ https://observertc.org/docs/api/client-monitor-js-v2/
308
295
 
309
296
  https://github.com/observertc/schemas
310
297
 
311
-
312
298
  ## Getting Involved
313
299
 
314
- Client-monitor is made with the intention to provide an open-source monitoring solution for
315
- WebRTC developers. If you are interested in getting involved
300
+ Client-monitor is made with the intention to provide an open-source monitoring solution for
301
+ WebRTC developers. If you are interested in getting involved
316
302
  please read our [contribution](CONTRIBUTING.md) guideline.
317
303
 
318
304
  ## License
@@ -16,17 +16,13 @@ export type ClientMonitorConfig = {
16
16
  */
17
17
  collectingPeriodInMs?: number;
18
18
  /**
19
- * By setting this, the observer makes samples periodically.
19
+ * By setting this, the observer makes samples after n number or collected stats.
20
20
  *
21
- * DEFAULT: undefined
22
- */
23
- samplingPeriodInMs?: number;
24
- /**
25
- * Sets the ticking time of the timer that invokes processes for collecting, sampling, and sending.
21
+ * For example if the value is 10, the observer makes a sample after 10 collected stats (in every 10 collectingPeriodInMs).
26
22
  *
27
- * DEFAULT: 1000
23
+ * DEFAULT: undefined
28
24
  */
29
- tickingTimeInMs?: number;
25
+ samplingTick?: number;
30
26
  };
31
27
  export type AlertState = 'on' | 'off';
32
28
  export interface ClientMonitorEvents {
@@ -101,10 +97,11 @@ export declare class ClientMonitor extends TypedEventEmitter<ClientMonitorEvents
101
97
  };
102
98
  private readonly _detectors;
103
99
  private readonly _sampler;
104
- private readonly _timer;
100
+ private _timer?;
105
101
  private _lastCollectedAt;
106
102
  private _lastSampledAt;
107
103
  private _closed;
104
+ private _actualCollectingTick;
108
105
  constructor(_config: ClientMonitorConfig);
109
106
  get closed(): boolean;
110
107
  close(): void;
@@ -118,7 +115,7 @@ export declare class ClientMonitor extends TypedEventEmitter<ClientMonitorEvents
118
115
  addCustomCallEvent(event: CustomCallEvent): void;
119
116
  addLocalSDP(localSDP: string[]): void;
120
117
  setCollectingPeriod(collectingPeriodInMs: number): void;
121
- setSamplingPeriod(samplingPeriodInMs: number): void;
118
+ setSamplingTick(samplingTick: number): void;
122
119
  get audioDesyncDetector(): {
123
120
  id: string;
124
121
  update: () => Promise<void>;
@@ -132,6 +129,26 @@ export declare class ClientMonitor extends TypedEventEmitter<ClientMonitorEvents
132
129
  addCongestionDetector(config?: CongestionDetectorConfig): void;
133
130
  getTrackStats(trackId: string): TrackStats | undefined;
134
131
  getPeerConnectionStats(peerConnectionId: string): PeerConnectionEntry | undefined;
132
+ get codecs(): import("./entries/StatsEntryInterfaces").CodecEntry[];
133
+ get inboundRtps(): import("./entries/StatsEntryInterfaces").InboundRtpEntry[];
134
+ get outboundRtps(): import("./entries/StatsEntryInterfaces").OutboundRtpEntry[];
135
+ get remoteInboundRtps(): import("./entries/StatsEntryInterfaces").RemoteInboundRtpEntry[];
136
+ get remoteOutboundRtps(): import("./entries/StatsEntryInterfaces").RemoteOutboundRtpEntry[];
137
+ get mediaSources(): import("./entries/StatsEntryInterfaces").MediaSourceEntry[];
138
+ get contributingSources(): import("./entries/StatsEntryInterfaces").ContributingSourceEntry[];
139
+ get dataChannels(): import("./entries/StatsEntryInterfaces").DataChannelEntry[];
140
+ get transceivers(): import("./entries/StatsEntryInterfaces").TransceiverEntry[];
141
+ get senders(): import("./entries/StatsEntryInterfaces").SenderEntry[];
142
+ get receivers(): import("./entries/StatsEntryInterfaces").ReceiverEntry[];
143
+ get transports(): import("./entries/StatsEntryInterfaces").TransportEntry[];
144
+ get sctpTransports(): import("./entries/StatsEntryInterfaces").SctpTransportEntry[];
145
+ get iceCandidatePairs(): import("./entries/StatsEntryInterfaces").IceCandidatePairEntry[];
146
+ get iceLocalCandidates(): import("./entries/StatsEntryInterfaces").LocalCandidateEntry[];
147
+ get iceRemoteCandidates(): import("./entries/StatsEntryInterfaces").RemoteCandidateEntry[];
148
+ get certificates(): import("./entries/StatsEntryInterfaces").CertificateEntry[];
149
+ get iceServers(): import("./entries/StatsEntryInterfaces").IceServerEntry[];
150
+ get peerConnections(): PeerConnectionEntry[];
151
+ get tracks(): TrackStats[];
135
152
  private _setupTimer;
136
153
  }
137
154
  //# sourceMappingURL=ClientMonitor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientMonitor.d.ts","sourceRoot":"","sources":["../src/ClientMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAoB,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAI1E,MAAM,MAAM,mBAAmB,GAAG;IAE9B;;;;;OAKG;IACH,oBAAoB,CAAC,EAA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AED,IAAW,YAAY,gEAEtB;IAED,IAAW,YAAY,gEAEtB;IAED,IAAW,OAAO,2DAEjB;IAED,IAAW,SAAS,6DAEnB;IAED,IAAW,UAAU,8DAEpB;IAED,IAAW,cAAc,kEAExB;IAED,IAAW,iBAAiB,qEAE3B;IAED,IAAW,kBAAkB,mEAE5B;IAED,IAAW,mBAAmB,oEAE7B;IAED,IAAW,YAAY,gEAEtB;IAED,IAAW,UAAU,8DAEpB;IAED,IAAW,eAAe,0BAEzB;IAED,IAAW,MAAM,iBAEhB;IAED,OAAO,CAAC,WAAW;CAUtB"}
@@ -29,7 +29,6 @@ const logger_1 = require("./utils/logger");
29
29
  const ClientMetaData_1 = require("./ClientMetaData");
30
30
  const StatsStorage_1 = require("./entries/StatsStorage");
31
31
  const TypedEmitter_1 = require("./utils/TypedEmitter");
32
- const Timer_1 = require("./utils/Timer");
33
32
  const Sampler_1 = require("./Sampler");
34
33
  const Adapter_1 = require("./collectors/Adapter");
35
34
  const validators = __importStar(require("./utils/validators"));
@@ -47,10 +46,10 @@ class ClientMonitor extends TypedEmitter_1.TypedEventEmitter {
47
46
  clientMonitor: this,
48
47
  });
49
48
  this._sampler = new Sampler_1.Sampler(this.storage);
50
- this._timer = (0, Timer_1.createTimer)();
51
49
  this._lastCollectedAt = Date.now();
52
50
  this._lastSampledAt = 0;
53
51
  this._closed = false;
52
+ this._actualCollectingTick = 0;
54
53
  this.meta = new ClientMetaData_1.ClientMetaData();
55
54
  this._sampler.addBrowser(this.meta.browser);
56
55
  this._sampler.addEngine(this.meta.engine);
@@ -84,20 +83,25 @@ class ClientMonitor extends TypedEmitter_1.TypedEventEmitter {
84
83
  return;
85
84
  }
86
85
  this._closed = true;
87
- this._timer.clear();
86
+ clearInterval(this._timer);
88
87
  this.storage.clear();
89
88
  this.collectors.clear();
90
89
  this._sampler.clear();
90
+ this._timer = undefined;
91
91
  }
92
92
  async collect() {
93
93
  const collectedStats = await this.collectors.collect();
94
- await this.storage.update(collectedStats);
94
+ this.storage.update(collectedStats);
95
95
  const timestamp = Date.now();
96
96
  this.emit('stats-collected', {
97
97
  collectedStats,
98
98
  elapsedSinceLastCollectedInMs: timestamp - this._lastCollectedAt,
99
99
  });
100
100
  this._lastCollectedAt = timestamp;
101
+ if (this._config.samplingTick && this._config.samplingTick <= ++this._actualCollectingTick) {
102
+ this._actualCollectingTick = 0;
103
+ this.sample();
104
+ }
101
105
  return collectedStats;
102
106
  }
103
107
  sample() {
@@ -154,8 +158,8 @@ class ClientMonitor extends TypedEmitter_1.TypedEventEmitter {
154
158
  this._config.collectingPeriodInMs = collectingPeriodInMs;
155
159
  this._setupTimer();
156
160
  }
157
- setSamplingPeriod(samplingPeriodInMs) {
158
- this._config.samplingPeriodInMs = samplingPeriodInMs;
161
+ setSamplingTick(samplingTick) {
162
+ this._config.samplingTick = samplingTick;
159
163
  this._setupTimer();
160
164
  }
161
165
  get audioDesyncDetector() {
@@ -196,27 +200,74 @@ class ClientMonitor extends TypedEmitter_1.TypedEventEmitter {
196
200
  getPeerConnectionStats(peerConnectionId) {
197
201
  return this.storage.getPeerConnection(peerConnectionId);
198
202
  }
203
+ get codecs() {
204
+ return [...this.storage.codecs()];
205
+ }
206
+ get inboundRtps() {
207
+ return [...this.storage.inboundRtps()];
208
+ }
209
+ get outboundRtps() {
210
+ return [...this.storage.outboundRtps()];
211
+ }
212
+ get remoteInboundRtps() {
213
+ return [...this.storage.remoteInboundRtps()];
214
+ }
215
+ get remoteOutboundRtps() {
216
+ return [...this.storage.remoteOutboundRtps()];
217
+ }
218
+ get mediaSources() {
219
+ return [...this.storage.mediaSources()];
220
+ }
221
+ get contributingSources() {
222
+ return [...this.storage.contributingSources()];
223
+ }
224
+ get dataChannels() {
225
+ return [...this.storage.dataChannels()];
226
+ }
227
+ get transceivers() {
228
+ return [...this.storage.transceivers()];
229
+ }
230
+ get senders() {
231
+ return [...this.storage.senders()];
232
+ }
233
+ get receivers() {
234
+ return [...this.storage.receivers()];
235
+ }
236
+ get transports() {
237
+ return [...this.storage.transports()];
238
+ }
239
+ get sctpTransports() {
240
+ return [...this.storage.sctpTransports()];
241
+ }
242
+ get iceCandidatePairs() {
243
+ return [...this.storage.iceCandidatePairs()];
244
+ }
245
+ get iceLocalCandidates() {
246
+ return [...this.storage.localCandidates()];
247
+ }
248
+ get iceRemoteCandidates() {
249
+ return [...this.storage.remoteCandidates()];
250
+ }
251
+ get certificates() {
252
+ return [...this.storage.certificates()];
253
+ }
254
+ get iceServers() {
255
+ return [...this.storage.iceServers()];
256
+ }
257
+ get peerConnections() {
258
+ return [...this.storage.peerConnections()];
259
+ }
260
+ get tracks() {
261
+ return [...this.storage.tracks()];
262
+ }
199
263
  _setupTimer() {
200
- if (!this._config.tickingTimeInMs) {
264
+ this._timer && clearInterval(this._timer);
265
+ this._timer = undefined;
266
+ if (!this._config.collectingPeriodInMs)
201
267
  return;
202
- }
203
- if (this._config.collectingPeriodInMs) {
204
- this._timer.setCollectingAction({
205
- action: () => this.collect().then(() => {
206
- // empty
207
- }),
208
- fixedDelayInMs: this._config.collectingPeriodInMs,
209
- });
210
- }
211
- if (this._config.samplingPeriodInMs) {
212
- this._timer.setSamplingAction({
213
- action: async () => {
214
- this.sample();
215
- },
216
- fixedDelayInMs: this._config.samplingPeriodInMs,
217
- });
218
- }
219
- this._timer.tickTimeInMs = this._config.tickingTimeInMs;
268
+ this._timer = setInterval(() => {
269
+ this.collect().catch(err => logger.error(err));
270
+ }, this._config.collectingPeriodInMs);
220
271
  }
221
272
  }
222
273
  exports.ClientMonitor = ClientMonitor;
@@ -202,7 +202,7 @@ class PeerConnectionEntryManifest {
202
202
  entry.droppedFrames = (stats.framesDropped ?? 0) - (entry.stats.framesDropped ?? 0);
203
203
  entry.receivedSamples = (stats.totalSamplesReceived ?? 0) - (entry.stats.totalSamplesReceived ?? 0);
204
204
  entry.silentConcealedSamples = (stats.silentConcealedSamples ?? 0) - (entry.stats.silentConcealedSamples ?? 0);
205
- entry.fractionLoss = entry.lostPackets / (entry.lostPackets + entry.receivedPackets);
205
+ entry.fractionLoss = entry.lostPackets === 0 && entry.receivedPackets === 0 ? 0 : entry.lostPackets / (entry.lostPackets + entry.receivedPackets);
206
206
  entry.stats = stats;
207
207
  entry.visited = true;
208
208
  if (entry.stats.kind === 'audio') {
@@ -53,7 +53,7 @@ export declare class StatsStorage {
53
53
  update(peerConnectionStats: {
54
54
  peerConnectionId: string;
55
55
  statsMap: StatsMap;
56
- }[]): Promise<void>;
56
+ }[]): void;
57
57
  clear(): void;
58
58
  addPeerConnection(peerConnectionId: string, peerConnectionLabel?: string): void;
59
59
  removePeerConnection(peerConnectionId: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"StatsStorage.d.ts","sourceRoot":"","sources":["../../src/entries/StatsStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,MAAM,MAAM,kBAAkB,GAAG;IAC7B,uBAAuB,EAAE,2BAA2B,CAAC;IACrD,yBAAyB,EAAE,2BAA2B,CAAC;CAC1D,CAAA;AAID,qBAAa,YAAY;IAEd,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,q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;OAEG;IACI,YAAY,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;IAIzD;;OAEG;IACI,aAAa,IAAI,gBAAgB,CAAC,iBAAiB,CAAC;IAI3D;;OAEG;IACI,YAAY,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;IAIzD;;;;OAIG;IACI,OAAO,IAAI,gBAAgB,CAAC,WAAW,CAAC;IAI/C;;OAEG;IACI,UAAU,IAAI,gBAAgB,CAAC,cAAc,CAAC;IAIrD;;;;OAIG;IACI,cAAc,IAAI,gBAAgB,CAAC,kBAAkB,CAAC;IAI7D;;OAEG;IACI,iBAAiB,IAAI,gBAAgB,CAAC,qBAAqB,CAAC;IAInE;;OAEG;IACI,eAAe,IAAI,gBAAgB,CAAC,mBAAmB,CAAC;IAI/D;;OAEG;IACI,gBAAgB,IAAI,gBAAgB,CAAC,oBAAoB,CAAC;IAIjE;;;OAGG;IACI,YAAY,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;IAIzD;;;;OAIG;IACI,UAAU,IAAI,gBAAgB,CAAC,cAAc,CAAC;IAIrD;;OAEG;IACI,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC;IAI7C;;OAEG;IACI,WAAW,IAAI,gBAAgB,CAAC,eAAe,CAAC;IAKvD,OAAO,CAAC,cAAc;IAsFtB,OAAO,CAAC,aAAa;IA8DrB,OAAO,CAAC,kBAAkB;CAW7B"}
@@ -30,7 +30,7 @@ class StatsStorage {
30
30
  get events() {
31
31
  return this._emitter;
32
32
  }
33
- async update(peerConnectionStats) {
33
+ update(peerConnectionStats) {
34
34
  for (const { peerConnectionId, statsMap } of peerConnectionStats) {
35
35
  const pcEntry = this._peerConnections.get(peerConnectionId);
36
36
  if (!pcEntry) {
@@ -39,13 +39,8 @@ class StatsStorage {
39
39
  }
40
40
  pcEntry.update(statsMap);
41
41
  }
42
- await new Promise((resolve, reject) => {
43
- this.processor.process(this, (err) => {
44
- if (err)
45
- reject(err);
46
- else
47
- resolve();
48
- });
42
+ this.processor.process(this, (err) => {
43
+ logger.warn(`update(): Failed to process stats`, err);
49
44
  });
50
45
  this._updateTracks();
51
46
  this._updateMetrics();
@@ -101,71 +96,31 @@ class StatsStorage {
101
96
  * The corresponded stats (receiver stats) are deprecated and will be removed from browser
102
97
  */
103
98
  receivers() {
104
- const peerConnections = this._peerConnections;
105
- function* iterator() {
106
- for (const pcEntry of peerConnections.values()) {
107
- for (const entry of pcEntry.receivers()) {
108
- yield entry;
109
- }
110
- }
111
- }
112
- return iterator();
99
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.receivers()]).values();
113
100
  }
114
101
  /**
115
102
  * Gives an iterator to read the collected media source stats and navigate to its relations.
116
103
  */
117
104
  mediaSources() {
118
- const peerConnections = this._peerConnections;
119
- function* iterator() {
120
- for (const pcEntry of peerConnections.values()) {
121
- for (const entry of pcEntry.mediaSources()) {
122
- yield entry;
123
- }
124
- }
125
- }
126
- return iterator();
105
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.mediaSources()]).values();
127
106
  }
128
107
  /**
129
108
  * Gives an iterator to read the collected outbound-rtp stats and navigate to its relations.
130
109
  */
131
110
  outboundRtps() {
132
- const peerConnections = this._peerConnections;
133
- function* iterator() {
134
- for (const pcEntry of peerConnections.values()) {
135
- for (const entry of pcEntry.outboundRtps()) {
136
- yield entry;
137
- }
138
- }
139
- }
140
- return iterator();
111
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.outboundRtps()]).values();
141
112
  }
142
113
  /**
143
114
  * Gives an iterator to read the collected remote-inbound-rtp stats and navigate to its relations.
144
115
  */
145
116
  remoteInboundRtps() {
146
- const peerConnections = this._peerConnections;
147
- function* iterator() {
148
- for (const pcEntry of peerConnections.values()) {
149
- for (const entry of pcEntry.remoteInboundRtps()) {
150
- yield entry;
151
- }
152
- }
153
- }
154
- return iterator();
117
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.remoteInboundRtps()]).values();
155
118
  }
156
119
  /**
157
120
  * Gives an iterator to read the collected remote-outbound-rtp stats and navigate to its relations.
158
121
  */
159
122
  remoteOutboundRtps() {
160
- const peerConnections = this._peerConnections;
161
- function* iterator() {
162
- for (const pcEntry of peerConnections.values()) {
163
- for (const entry of pcEntry.remoteOutboundRtps()) {
164
- yield entry;
165
- }
166
- }
167
- }
168
- return iterator();
123
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.remoteOutboundRtps()]).values();
169
124
  }
170
125
  /**
171
126
  * Gives an iterator to read the collected contributing sources and navigate to its relations.
@@ -173,57 +128,25 @@ class StatsStorage {
173
128
  * The corresponded stats (csrc stats) are deprecated and will be removed from browser
174
129
  */
175
130
  contributingSources() {
176
- const peerConnections = this._peerConnections;
177
- function* iterator() {
178
- for (const pcEntry of peerConnections.values()) {
179
- for (const entry of pcEntry.contributingSources()) {
180
- yield entry;
181
- }
182
- }
183
- }
184
- return iterator();
131
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.contributingSources()]).values();
185
132
  }
186
133
  /**
187
134
  * Gives an iterator to read the collected data channel stats and navigate to its relations.
188
135
  */
189
136
  dataChannels() {
190
- const peerConnections = this._peerConnections;
191
- function* iterator() {
192
- for (const pcEntry of peerConnections.values()) {
193
- for (const entry of pcEntry.dataChannels()) {
194
- yield entry;
195
- }
196
- }
197
- }
198
- return iterator();
137
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.dataChannels()]).values();
199
138
  }
200
139
  /**
201
140
  * Gives an iterator to read the collected Audio Playout stats and navigate to its relations.
202
141
  */
203
142
  audioPlayouts() {
204
- const peerConnections = this._peerConnections;
205
- function* iterator() {
206
- for (const pcEntry of peerConnections.values()) {
207
- for (const entry of pcEntry.audioPlayouts()) {
208
- yield entry;
209
- }
210
- }
211
- }
212
- return iterator();
143
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.audioPlayouts()]).values();
213
144
  }
214
145
  /**
215
146
  * Gives an iterator to read the collected transceiver stats and navigate to its relations.
216
147
  */
217
148
  transceivers() {
218
- const peerConnections = this._peerConnections;
219
- function* iterator() {
220
- for (const pcEntry of peerConnections.values()) {
221
- for (const entry of pcEntry.transceivers()) {
222
- yield entry;
223
- }
224
- }
225
- }
226
- return iterator();
149
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.transceivers()]).values();
227
150
  }
228
151
  /**
229
152
  * Gives an iterator to read the collected media source stats and navigate to its relations.
@@ -231,29 +154,13 @@ class StatsStorage {
231
154
  * The corresponded stats (sender stats) are deprecated and will be removed from browser
232
155
  */
233
156
  senders() {
234
- const peerConnections = this._peerConnections;
235
- function* iterator() {
236
- for (const pcEntry of peerConnections.values()) {
237
- for (const entry of pcEntry.senders()) {
238
- yield entry;
239
- }
240
- }
241
- }
242
- return iterator();
157
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.senders()]).values();
243
158
  }
244
159
  /**
245
160
  * Gives an iterator to read the collected transport stats and navigate to its relations.
246
161
  */
247
162
  transports() {
248
- const peerConnections = this._peerConnections;
249
- function* iterator() {
250
- for (const pcEntry of peerConnections.values()) {
251
- for (const entry of pcEntry.transports()) {
252
- yield entry;
253
- }
254
- }
255
- }
256
- return iterator();
163
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.transports()]).values();
257
164
  }
258
165
  /**
259
166
  * Gives an iterator to read the SCTP transport stats and navigate to its relations.
@@ -261,72 +168,32 @@ class StatsStorage {
261
168
  * The corresponded stats (sctp-transport stats) are deprecated and will be removed from browser
262
169
  */
263
170
  sctpTransports() {
264
- const peerConnections = this._peerConnections;
265
- function* iterator() {
266
- for (const pcEntry of peerConnections.values()) {
267
- for (const entry of pcEntry.sctpTransports()) {
268
- yield entry;
269
- }
270
- }
271
- }
272
- return iterator();
171
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.sctpTransports()]).values();
273
172
  }
274
173
  /**
275
174
  * Gives an iterator to read the collected ICE candidate pair stats and navigate to its relations.
276
175
  */
277
176
  iceCandidatePairs() {
278
- const peerConnections = this._peerConnections;
279
- function* iterator() {
280
- for (const pcEntry of peerConnections.values()) {
281
- for (const entry of pcEntry.iceCandidatePairs()) {
282
- yield entry;
283
- }
284
- }
285
- }
286
- return iterator();
177
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.iceCandidatePairs()]).values();
287
178
  }
288
179
  /**
289
180
  * Gives an iterator to read the collected local ICE candidate stats and navigate to its relations.
290
181
  */
291
182
  localCandidates() {
292
- const peerConnections = this._peerConnections;
293
- function* iterator() {
294
- for (const pcEntry of peerConnections.values()) {
295
- for (const entry of pcEntry.localCandidates()) {
296
- yield entry;
297
- }
298
- }
299
- }
300
- return iterator();
183
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.localCandidates()]).values();
301
184
  }
302
185
  /**
303
186
  * Gives an iterator to read the collected remote ICE candidate stats and navigate to its relations.
304
187
  */
305
188
  remoteCandidates() {
306
- const peerConnections = this._peerConnections;
307
- function* iterator() {
308
- for (const pcEntry of peerConnections.values()) {
309
- for (const entry of pcEntry.remoteCandidates()) {
310
- yield entry;
311
- }
312
- }
313
- }
314
- return iterator();
189
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.remoteCandidates()]).values();
315
190
  }
316
191
  /**
317
192
  * Gives an iterator to read the collected certificate stats and navigate to its relations.
318
193
  *
319
194
  */
320
195
  certificates() {
321
- const peerConnections = this._peerConnections;
322
- function* iterator() {
323
- for (const pcEntry of peerConnections.values()) {
324
- for (const entry of pcEntry.certificates()) {
325
- yield entry;
326
- }
327
- }
328
- }
329
- return iterator();
196
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.certificates()]).values();
330
197
  }
331
198
  /**
332
199
  * Gives an iterator to read the collected ICE server stats and navigate to its relations.
@@ -334,43 +201,20 @@ class StatsStorage {
334
201
  * The corresponded stats (ice-server stats) are deprecated and will be removed from browser
335
202
  */
336
203
  iceServers() {
337
- const peerConnections = this._peerConnections;
338
- function* iterator() {
339
- for (const pcEntry of peerConnections.values()) {
340
- for (const entry of pcEntry.iceServers()) {
341
- yield entry;
342
- }
343
- }
344
- }
345
- return iterator();
204
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.iceServers()]).values();
346
205
  }
347
206
  /**
348
207
  * Gives an iterator to read the collected codecs and navigate to its relations.
349
208
  */
350
209
  codecs() {
351
- const peerConnections = this._peerConnections;
352
- function* iterator() {
353
- for (const pcEntry of peerConnections.values()) {
354
- for (const entry of pcEntry.codecs()) {
355
- yield entry;
356
- }
357
- }
358
- }
359
- return iterator();
210
+ return [...this._peerConnections.values()].flatMap(pcEntry => [...pcEntry.codecs()]).values();
360
211
  }
361
212
  /**
362
213
  * Gives an iterator to read the collected inbound-rtp stats and navigate to its relations.
363
214
  */
364
215
  inboundRtps() {
365
- const peerConnections = this._peerConnections;
366
- function* iterator() {
367
- for (const pcEntry of peerConnections.values()) {
368
- for (const entry of pcEntry.inboundRtps()) {
369
- yield entry;
370
- }
371
- }
372
- }
373
- return iterator();
216
+ return [...this._peerConnections.values()]
217
+ .flatMap(pcEntry => [...pcEntry.inboundRtps()]).values();
374
218
  }
375
219
  _updateMetrics() {
376
220
  this.sendingAudioBitrate = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,YAAY,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,YAAY,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AAC9F,YAAY,EACR,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,C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f,eAAe,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAyC,MAAM,gBAAgB,CAAC;AAEjF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG;IAC/D;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB,GAAG,aAAa,CAchB;AAED,OAAO,EACH,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,gBAAgB,CAAC"}
package/lib/index.js CHANGED
@@ -34,17 +34,17 @@ let loggerSet = false;
34
34
  * @param config the given config to setup the observer
35
35
  */
36
36
  function createClientMonitor(config) {
37
- if (config && 0 < ((config?.collectingPeriodInMs ?? 0) + (config?.samplingPeriodInMs ?? 0))) {
38
- if (!config.tickingTimeInMs) {
39
- config.tickingTimeInMs = 1000;
40
- }
41
- }
42
37
  if (!loggerSet && config?.logLevel) {
43
38
  (0, logger_1.addLoggerProcess)((0, logger_1.createConsoleLogger)(config.logLevel));
44
39
  loggerSet = true;
45
40
  }
41
+ if (config && !config.samplingTick)
42
+ config.samplingTick = 1;
46
43
  return new ClientMonitor_1.ClientMonitor({
47
- ...(config ?? {}),
44
+ ...(config ?? {
45
+ collectingPeriodInMs: 5000,
46
+ samplingTick: 1,
47
+ }),
48
48
  });
49
49
  }
50
50
  exports.createClientMonitor = createClientMonitor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@observertc/client-monitor-js",
3
- "version": "3.3.1",
3
+ "version": "3.4.0",
4
4
  "description": "ObserveRTC Client Integration Javascript Library",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,15 +0,0 @@
1
- export type Timer = ReturnType<typeof createTimer>;
2
- export declare function createTimer(tickTimeInMs?: number): {
3
- readonly active: boolean;
4
- tickTimeInMs: number | undefined;
5
- setCollectingAction: (config: {
6
- action?: () => Promise<void>;
7
- fixedDelayInMs?: number;
8
- }) => void;
9
- setSamplingAction: (config: {
10
- action?: () => Promise<void>;
11
- fixedDelayInMs?: number;
12
- }) => void;
13
- clear: () => void;
14
- };
15
- //# sourceMappingURL=Timer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Timer.d.ts","sourceRoot":"","sources":["../../src/utils/Timer.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD,wBAAgB,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM;;;kCAkDR;QAAE,MAAM,CAAC,EAAE,MAAM,QAAQ,IAAI,CAAC,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,IAAI;gCAgBlE;QAAE,MAAM,CAAC,EAAE,MAAM,QAAQ,IAAI,CAAC,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,KAAG,IAAI;;EAoCtG"}
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTimer = void 0;
4
- const logger_1 = require("./logger");
5
- const logger = (0, logger_1.createLogger)(`Timer`);
6
- function createTimer(tickTimeInMs) {
7
- let timer;
8
- let collecting;
9
- let sampling;
10
- if (tickTimeInMs) {
11
- setTickingTime(tickTimeInMs);
12
- }
13
- function setTickingTime(tickInMs) {
14
- if (timer) {
15
- clearInterval(timer);
16
- timer = undefined;
17
- }
18
- if (!tickInMs) {
19
- return;
20
- }
21
- timer = setInterval(() => {
22
- if (!collecting && !sampling) {
23
- return;
24
- }
25
- const now = Date.now();
26
- let promise = Promise.resolve();
27
- if (collecting) {
28
- if (collecting.invoked) {
29
- if (collecting.invoked + collecting.fixedDelayInMs <= now) {
30
- promise = promise.then(() => collecting?.action() ?? Promise.resolve());
31
- collecting.invoked = now;
32
- }
33
- }
34
- else {
35
- promise = promise.then(() => collecting?.action() ?? Promise.resolve());
36
- collecting.invoked = now;
37
- }
38
- }
39
- if (sampling) {
40
- if (sampling.invoked) {
41
- if (sampling.invoked + sampling.fixedDelayInMs <= now) {
42
- promise = promise.then(() => sampling?.action() ?? Promise.resolve());
43
- sampling.invoked = now;
44
- }
45
- }
46
- else {
47
- promise = promise.then(() => sampling?.action() ?? Promise.resolve());
48
- sampling.invoked = now;
49
- }
50
- }
51
- promise.catch(err => {
52
- logger.warn(`Error occurred while executing timer action`, err);
53
- });
54
- }, tickInMs);
55
- }
56
- function setCollectingAction(config) {
57
- const { action, fixedDelayInMs, } = config;
58
- if (!action || !fixedDelayInMs) {
59
- collecting = undefined;
60
- return;
61
- }
62
- collecting = {
63
- action,
64
- created: Date.now(),
65
- fixedDelayInMs,
66
- };
67
- }
68
- function setSamplingAction(config) {
69
- const { action, fixedDelayInMs, } = config;
70
- if (!action || !fixedDelayInMs) {
71
- sampling = undefined;
72
- return;
73
- }
74
- sampling = {
75
- action,
76
- created: Date.now(),
77
- fixedDelayInMs,
78
- };
79
- }
80
- function clear() {
81
- if (timer) {
82
- clearInterval(timer);
83
- timer = undefined;
84
- }
85
- collecting = undefined;
86
- sampling = undefined;
87
- }
88
- return {
89
- get active() {
90
- return !!timer;
91
- },
92
- set tickTimeInMs(value) {
93
- setTickingTime(value);
94
- },
95
- setCollectingAction,
96
- setSamplingAction,
97
- clear,
98
- };
99
- }
100
- exports.createTimer = createTimer;