@observertc/observer-js 1.0.1-72a904d.0 → 1.0.1-9d3744d.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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,CAAC,CAAC;AAE9F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CASlG;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CASjH;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIhD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,mBAAmB,UAAO,GAAG,MAAM,CAkB3E;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAU3D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,CAAC,CAAC;AAE9F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CASlG;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CASjH;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIhD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,wBAAwB,SAAI,GAAG,MAAM,CAI9E;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,mBAAmB,UAAO,GAAG,MAAM,CAkB3E;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAU3D"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseJsonAs = exports.getMedian = exports.isValidUuid = exports.asyncIteratorConverter = exports.iteratorConverter = void 0;
3
+ exports.parseJsonAs = exports.getMedian = exports.getAverage = exports.isValidUuid = exports.asyncIteratorConverter = exports.iteratorConverter = void 0;
4
4
  function iteratorConverter(generator) {
5
5
  return {
6
6
  [Symbol.iterator]() {
@@ -28,6 +28,12 @@ function isValidUuid(str) {
28
28
  return regexp.test(str);
29
29
  }
30
30
  exports.isValidUuid = isValidUuid;
31
+ function getAverage(arr, defaultAvgIfArrLengthIs0 = 0) {
32
+ if (arr.length === 0)
33
+ return defaultAvgIfArrLengthIs0;
34
+ return arr.reduce((a, b) => a + b, 0) / arr.length;
35
+ }
36
+ exports.getAverage = getAverage;
31
37
  function getMedian(arr, copyArrayForSorting = true) {
32
38
  // Sort the array in ascending order
33
39
  const sortedArr = copyArrayForSorting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@observertc/observer-js",
3
- "version": "1.0.1-72a904d.0",
3
+ "version": "1.0.1-9d3744d.0",
4
4
  "description": "Server Side NodeJS Library for processing ObserveRTC Samples",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,7 +9,6 @@ import { RemoteTrackResolver } from './utils/RemoteTrackResolver';
9
9
  import { OnAllClientCallUpdater } from './updaters/OnAllClientCallUpdater';
10
10
  import { Updater } from './updaters/Updater';
11
11
  import { OnIntervalUpdater } from './updaters/OnIntervalUpdater';
12
- import { ObservedCallSummary } from './ObservedCallSummary';
13
12
  import { OnAnyClientCallUpdater } from './updaters/OnAnyClientCallUpdater';
14
13
 
15
14
  export type ObservedCallSettings<AppData extends Record<string, unknown> = Record<string, unknown>> = {
@@ -153,6 +152,7 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
153
152
 
154
153
  public close() {
155
154
  if (this.closed) return;
155
+ this.update(); // last update before closing
156
156
  this.closed = true;
157
157
 
158
158
  this.updater?.close();
@@ -190,7 +190,7 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
190
190
  if (this.observedClients.size === 0) {
191
191
  this.emit('empty');
192
192
  }
193
- --this.totalRemovedClients;
193
+ ++this.totalRemovedClients;
194
194
  });
195
195
  result.on('update', onUpdate);
196
196
  result.on('joined', joined);
@@ -222,10 +222,6 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
222
222
  this.numberOfOutboundRtpStreams += client.numberOfOutboundRtpStreams;
223
223
  this.numberOfPeerConnections += client.numberOfPeerConnections;
224
224
  this.numberOfDataChannels += client.numberOfDataChannels;
225
-
226
- if (client.usingTURN) {
227
- this.clientsUsedTurn.add(client.clientId);
228
- }
229
225
  }
230
226
 
231
227
  this.detectors.update();
@@ -242,12 +238,12 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
242
238
 
243
239
  private _onClientUpdate(client: ObservedClient) {
244
240
  this.totalClientsReceivedAudioBytes += client.deltaReceivedAudioBytes;
245
- this.totalClientsSentAudioBytes += client.deltaSentAudioBytes;
246
241
  this.totalClientsReceivedVideoBytes += client.deltaReceivedVideoBytes;
247
- this.totalClientsReceivedVideoBytes += client.deltaSentVideoBytes;
248
242
  this.totalClientsReceivedDataChannelBytes += client.deltaDataChannelBytesReceived;
249
- this.totalClientsSentDataChannelBytes += client.deltaDataChannelBytesSent;
250
243
  this.totalClientsReceivedBytes += client.deltaTransportReceivedBytes;
244
+ this.totalClientsSentAudioBytes += client.deltaSentAudioBytes;
245
+ this.totalClientsSentVideoBytes += client.deltaSentVideoBytes;
246
+ this.totalClientsSentDataChannelBytes += client.deltaDataChannelBytesSent;
251
247
  this.totalClientsSentBytes += client.deltaTransportSentBytes;
252
248
 
253
249
  this.deltaRttLt50Measurements += client.deltaRttLt50Measurements;
@@ -262,6 +258,10 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
262
258
 
263
259
  this.deltaNumberOfIssues += client.deltaNumberOfIssues;
264
260
  this.numberOfIssues += client.deltaNumberOfIssues;
261
+
262
+ if (client.usingTURN) {
263
+ this.clientsUsedTurn.add(client.clientId);
264
+ }
265
265
  }
266
266
 
267
267
  private _clientJoined(client: ObservedClient) {
@@ -304,50 +304,50 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
304
304
  this.emit('ended');
305
305
  }
306
306
 
307
- public resetSummaryMetrics() {
308
- this.totalAddedClients = 0;
309
- this.totalRemovedClients = 0;
307
+ // public resetSummaryMetrics() {
308
+ // this.totalAddedClients = 0;
309
+ // this.totalRemovedClients = 0;
310
310
 
311
- this.totalClientsReceivedAudioBytes = 0;
312
- this.totalClientsReceivedVideoBytes = 0;
313
- this.totalClientsReceivedBytes = 0;
311
+ // this.totalClientsReceivedAudioBytes = 0;
312
+ // this.totalClientsReceivedVideoBytes = 0;
313
+ // this.totalClientsReceivedBytes = 0;
314
314
 
315
- this.totalClientsSentAudioBytes = 0;
316
- this.totalClientsSentVideoBytes = 0;
317
- this.totalClientsSentBytes = 0;
315
+ // this.totalClientsSentAudioBytes = 0;
316
+ // this.totalClientsSentVideoBytes = 0;
317
+ // this.totalClientsSentBytes = 0;
318
318
 
319
- this.totalRttLt50Measurements = 0;
320
- this.totalRttLt150Measurements = 0;
321
- this.totalRttLt300Measurements = 0;
322
- this.totalRttGtOrEq300Measurements = 0;
319
+ // this.totalRttLt50Measurements = 0;
320
+ // this.totalRttLt150Measurements = 0;
321
+ // this.totalRttLt300Measurements = 0;
322
+ // this.totalRttGtOrEq300Measurements = 0;
323
323
 
324
- this.numberOfIssues = 0;
324
+ // this.numberOfIssues = 0;
325
325
 
326
- this.clientsUsedTurn.clear();
326
+ // this.clientsUsedTurn.clear();
327
327
 
328
- }
328
+ // }
329
329
 
330
- public createSummary(): ObservedCallSummary {
331
- return {
332
- currentActiveClients: this.observedClients.size,
333
- totalAddedClients: this.totalAddedClients,
334
- totalRemovedClients: this.totalRemovedClients,
330
+ // public createSummary(): ObservedCallSummary {
331
+ // return {
332
+ // currentActiveClients: this.observedClients.size,
333
+ // totalAddedClients: this.totalAddedClients,
334
+ // totalRemovedClients: this.totalRemovedClients,
335
335
 
336
- totalClientsReceivedAudioBytes: this.totalClientsReceivedBytes,
337
- totalClientsReceivedVideoBytes: this.totalClientsReceivedVideoBytes,
338
- totalClientsReceivedBytes: this.totalClientsReceivedBytes,
339
-
340
- totalClientsSentAudioBytes: this.totalClientsSentAudioBytes,
341
- totalClientsSentVideoBytes: this.totalClientsSentVideoBytes,
342
- totalClientsSentBytes: this.totalClientsSentBytes,
343
-
344
- totalRttLt50Measurements: this.totalRttLt50Measurements,
345
- totalRttLt150Measurements: this.totalRttLt150Measurements,
346
- totalRttLt300Measurements: this.totalRttLt300Measurements,
347
- totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
348
-
349
- numberOfIssues: this.numberOfIssues,
350
- numberOfClientsUsedTurn: this.clientsUsedTurn.size,
351
- };
352
- }
336
+ // totalClientsReceivedAudioBytes: this.totalClientsReceivedBytes,
337
+ // totalClientsReceivedVideoBytes: this.totalClientsReceivedVideoBytes,
338
+ // totalClientsReceivedBytes: this.totalClientsReceivedBytes,
339
+
340
+ // totalClientsSentAudioBytes: this.totalClientsSentAudioBytes,
341
+ // totalClientsSentVideoBytes: this.totalClientsSentVideoBytes,
342
+ // totalClientsSentBytes: this.totalClientsSentBytes,
343
+
344
+ // totalRttLt50Measurements: this.totalRttLt50Measurements,
345
+ // totalRttLt150Measurements: this.totalRttLt150Measurements,
346
+ // totalRttLt300Measurements: this.totalRttLt300Measurements,
347
+ // totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
348
+
349
+ // numberOfIssues: this.numberOfIssues,
350
+ // numberOfClientsUsedTurn: this.clientsUsedTurn.size,
351
+ // };
352
+ // }
353
353
  }
@@ -7,10 +7,9 @@ import * as MetaData from './schema/ClientMetaTypes';
7
7
  import { ClientEventTypes } from './schema/ClientEventTypes';
8
8
  import { ObservedCall } from './ObservedCall';
9
9
  import { ClientMetaTypes } from './schema/ClientMetaTypes';
10
- import { getMedian, parseJsonAs } from './common/utils';
10
+ import { parseJsonAs } from './common/utils';
11
11
  import { CalculatedScore } from './scores/CalculatedScore';
12
12
  import { Detectors } from './detectors/Detectors';
13
- import { ObservedClientSummary } from './ObservedClientSummary';
14
13
 
15
14
  const logger = createLogger('ObservedClient');
16
15
 
@@ -73,8 +72,10 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
73
72
  public mediaConstraints: string[] = [];
74
73
 
75
74
  public usingTURN = false;
75
+ public usingTCP = false;
76
76
  public availableOutgoingBitrate = 0;
77
77
  public availableIncomingBitrate = 0;
78
+
78
79
  public totalInboundPacketsLost = 0;
79
80
  public totalInboundPacketsReceived = 0;
80
81
  public totalOutboundPacketsSent = 0;
@@ -100,7 +101,6 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
100
101
  public deltaInboundPacketsLost = 0;
101
102
  public deltaInboundPacketsReceived = 0;
102
103
  public deltaOutboundPacketsSent = 0;
103
- public deltaRttInMsMeasurements: number[] = [];
104
104
  public deltaTransportSentBytes = 0;
105
105
  public deltaTransportReceivedBytes = 0;
106
106
  public deltaRttLt50Measurements = 0;
@@ -108,7 +108,10 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
108
108
  public deltaRttLt300Measurements = 0;
109
109
  public deltaRttGtOrEq300Measurements = 0;
110
110
 
111
- public currentRttInMs?: number;
111
+ public currentMaxRttInMs?: number;
112
+ public currentMinRttInMs?: number;
113
+ public currentAvgRttInMs?: number;
114
+
112
115
  public sendingAudioBitrate = 0;
113
116
  public sendingVideoBitrate = 0;
114
117
  public receivingAudioBitrate = 0;
@@ -128,7 +131,7 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
128
131
 
129
132
  public totalScoreSum = 0;
130
133
  public numberOfScoreMeasurements = 0;
131
- public numberOfIssues = 0;
134
+ public totalNumberOfIssues = 0;
132
135
 
133
136
  public readonly mediaDevices: MetaData.MediaDeviceInfo[] = [];
134
137
  public issues: ClientIssue[] = [];
@@ -166,7 +169,9 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
166
169
  const now = Date.now();
167
170
  const elapsedInMs = now - this.updated;
168
171
  const elapsedInSeconds = elapsedInMs / 1000;
169
-
172
+ let sumOfRtts = 0;
173
+ let numberOfRttMeasurements = 0;
174
+
170
175
  ++this.acceptedSamples;
171
176
 
172
177
  this.availableIncomingBitrate = 0;
@@ -184,7 +189,6 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
184
189
  this.deltaSentVideoBytes = 0;
185
190
  this.deltaTransportReceivedBytes = 0;
186
191
  this.deltaTransportSentBytes = 0;
187
- this.deltaRttInMsMeasurements = [];
188
192
  this.deltaRttLt50Measurements = 0;
189
193
  this.deltaRttLt150Measurements = 0;
190
194
  this.deltaRttLt300Measurements = 0;
@@ -196,14 +200,87 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
196
200
  this.numberOfInbundTracks = 0;
197
201
  this.numberOfOutboundRtpStreams = 0;
198
202
  this.numberOfOutboundTracks = 0;
203
+ this.usingTURN = false;
204
+ this.usingTCP = false;
205
+ this.currentMinRttInMs = undefined;
206
+ this.currentMaxRttInMs = undefined;
199
207
 
200
- sample.clientEvents?.forEach(this._processClientEvent.bind(this));
201
- sample.clientMetaItems?.forEach(this.addMetadata.bind(this));
202
- sample.clientIssues?.forEach(this.addIssue.bind(this));
203
- sample.peerConnections?.forEach(this._updatePeerConnection.bind(this));
204
- sample.extensionStats?.forEach(this.addExtensionStats.bind(this));
208
+ for (const clientEvent of sample.clientEvents ?? []) {
209
+ this._processClientEvent(clientEvent);
210
+ }
211
+
212
+ for (const metaData of sample.clientMetaItems ?? []) {
213
+ this.addMetadata(metaData);
214
+ }
215
+
216
+ for (const issue of sample.clientIssues ?? []) {
217
+ this.addIssue(issue);
218
+
219
+ ++this.deltaNumberOfIssues;
220
+ }
221
+
222
+ for (const extensionStat of sample.extensionStats ?? []) {
223
+ this.addExtensionStats(extensionStat);
224
+ }
225
+
226
+ for (const pcSample of sample.peerConnections ?? []) {
227
+ const observedPeerConnection = this._updatePeerConnection(pcSample);
228
+
229
+ if (!observedPeerConnection) continue;
230
+
231
+ this.deltaDataChannelBytesReceived += observedPeerConnection.deltaDataChannelBytesReceived;
232
+ this.deltaDataChannelBytesSent += observedPeerConnection.deltaDataChannelBytesSent;
233
+ this.deltaDataChannelMessagesReceived += observedPeerConnection.deltaDataChannelMessagesReceived;
234
+ this.deltaDataChannelMessagesSent += observedPeerConnection.deltaDataChannelMessagesSent;
235
+ this.deltaInboundPacketsLost += observedPeerConnection.deltaInboundPacketsLost;
236
+ this.deltaInboundPacketsReceived += observedPeerConnection.deltaInboundPacketsReceived;
237
+ this.deltaOutboundPacketsSent += observedPeerConnection.deltaOutboundPacketsSent;
238
+ this.deltaReceivedAudioBytes += observedPeerConnection.deltaReceivedAudioBytes;
239
+ this.deltaReceivedVideoBytes += observedPeerConnection.deltaReceivedVideoBytes;
240
+ this.deltaSentAudioBytes += observedPeerConnection.deltaSentAudioBytes;
241
+ this.deltaSentVideoBytes += observedPeerConnection.deltaSentVideoBytes;
242
+ this.deltaTransportReceivedBytes += observedPeerConnection.deltaTransportReceivedBytes;
243
+ this.deltaTransportSentBytes += observedPeerConnection.deltaTransportSentBytes;
244
+
245
+ this.availableIncomingBitrate += observedPeerConnection.availableIncomingBitrate;
246
+ this.availableOutgoingBitrate += observedPeerConnection.availableOutgoingBitrate;
247
+
248
+ this.numberOfDataChannels += observedPeerConnection.observedDataChannels.size;
249
+ this.numberOfInbundTracks += observedPeerConnection.observedInboundTracks.size;
250
+ this.numberOfOutboundRtpStreams += observedPeerConnection.observedOutboundRtps.size;
251
+ this.numberOfOutboundTracks += observedPeerConnection.observedOutboundTracks.size;
252
+ this.numberOfInboundRtpStreams += observedPeerConnection.observedInboundRtps.size;
253
+
254
+ if (observedPeerConnection.usingTURN) {
255
+ this.usingTURN = true;
256
+ }
257
+ if (observedPeerConnection.usingTCP) {
258
+ this.usingTCP = true;
259
+ }
260
+
261
+ if (observedPeerConnection.currentRttInMs) {
262
+ if (this.currentMinRttInMs === undefined || observedPeerConnection.currentRttInMs < this.currentMinRttInMs) {
263
+ this.currentMinRttInMs = observedPeerConnection.currentRttInMs;
264
+ }
265
+ if (this.currentMaxRttInMs === undefined || observedPeerConnection.currentRttInMs > this.currentMaxRttInMs) {
266
+ this.currentMaxRttInMs = observedPeerConnection.currentRttInMs;
267
+ }
268
+ if (observedPeerConnection.currentRttInMs < 50) {
269
+ this.deltaRttLt50Measurements += 1;
270
+ } else if (observedPeerConnection.currentRttInMs < 150) {
271
+ this.deltaRttLt150Measurements += 1;
272
+ } else if (observedPeerConnection.currentRttInMs < 300) {
273
+ this.deltaRttLt300Measurements += 1;
274
+ } else if (300 <= observedPeerConnection.currentRttInMs) {
275
+ this.deltaRttGtOrEq300Measurements += 1;
276
+ }
277
+
278
+ sumOfRtts += observedPeerConnection.currentRttInMs;
279
+ ++numberOfRttMeasurements;
280
+ }
281
+ }
205
282
 
206
- this._updateRttMeasurements();
283
+ sample.peerConnections?.forEach(this._updatePeerConnection.bind(this));
207
284
 
208
285
  // emit new attachments?
209
286
  this.attachments = sample.attachments;
@@ -225,12 +302,13 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
225
302
  this.totalRttLt150Measurements += this.deltaRttLt150Measurements;
226
303
  this.totalRttLt300Measurements += this.deltaRttLt300Measurements;
227
304
  this.totalRttGtOrEq300Measurements += this.deltaRttGtOrEq300Measurements;
228
- this.numberOfIssues += this.deltaNumberOfIssues;
305
+ this.totalNumberOfIssues += this.deltaNumberOfIssues;
229
306
 
230
307
  this.receivingAudioBitrate = (this.deltaReceivedAudioBytes * 8) / (elapsedInSeconds);
231
308
  this.receivingVideoBitrate = (this.totalReceivedVideoBytes * 8) / (elapsedInSeconds);
232
309
  this.sendingAudioBitrate = (this.deltaSentAudioBytes * 8) / (elapsedInSeconds);
233
310
  this.sendingVideoBitrate = (this.deltaSentVideoBytes * 8) / (elapsedInSeconds);
311
+ this.currentAvgRttInMs = 0 < numberOfRttMeasurements ? sumOfRtts / numberOfRttMeasurements : undefined;
234
312
 
235
313
  this.calculatedScore.value = sample.score;
236
314
  this.detectors.update();
@@ -311,7 +389,6 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
311
389
  public addIssue(issue: ClientIssue) {
312
390
  if (this.closed) return;
313
391
 
314
- ++this.deltaNumberOfIssues;
315
392
  this.emit('issue', issue);
316
393
  this.call.observer.emit('client-issue', this, issue);
317
394
  }
@@ -320,15 +397,15 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
320
397
  this.call.observer.emit('client-extension-stats', this, stats);
321
398
  }
322
399
 
323
- private _updatePeerConnection(sample: PeerConnectionSample) {
400
+ private _updatePeerConnection(sample: PeerConnectionSample): ObservedPeerConnection | undefined {
324
401
  let observedPeerConnection = this.observedPeerConnections.get(sample.peerConnectionId);
325
402
 
326
403
  if (!observedPeerConnection) {
327
404
  if (!sample.peerConnectionId) {
328
- return logger.warn(
405
+ return (logger.warn(
329
406
  `ObservedClient received an invalid PeerConnectionSample (missing peerConnectionId field). ClientId: ${this.clientId}, CallId: ${this.call.callId}`,
330
407
  sample
331
- );
408
+ ), void 0);
332
409
  }
333
410
 
334
411
  observedPeerConnection = new ObservedPeerConnection(sample.peerConnectionId, this);
@@ -343,107 +420,54 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
343
420
 
344
421
  observedPeerConnection.accept(sample);
345
422
 
346
- observedPeerConnection.currentRttInMs;
347
-
348
- this.deltaDataChannelBytesReceived += observedPeerConnection.deltaDataChannelBytesReceived;
349
- this.deltaDataChannelBytesSent += observedPeerConnection.deltaDataChannelBytesSent;
350
- this.deltaDataChannelMessagesReceived += observedPeerConnection.deltaDataChannelMessagesReceived;
351
- this.deltaDataChannelMessagesSent += observedPeerConnection.deltaDataChannelMessagesSent;
352
- this.deltaInboundPacketsLost += observedPeerConnection.deltaInboundPacketsLost;
353
- this.deltaInboundPacketsReceived += observedPeerConnection.deltaInboundPacketsReceived;
354
- this.deltaOutboundPacketsSent += observedPeerConnection.deltaOutboundPacketsSent;
355
- this.deltaReceivedAudioBytes += observedPeerConnection.deltaReceivedAudioBytes;
356
- this.deltaReceivedVideoBytes += observedPeerConnection.deltaReceivedVideoBytes;
357
- this.deltaSentAudioBytes += observedPeerConnection.deltaSentAudioBytes;
358
- this.deltaSentVideoBytes += observedPeerConnection.deltaSentVideoBytes;
359
- this.deltaTransportReceivedBytes += observedPeerConnection.deltaTransportReceivedBytes;
360
- this.deltaTransportSentBytes += observedPeerConnection.deltaTransportSentBytes;
361
-
362
- this.availableIncomingBitrate += observedPeerConnection.availableIncomingBitrate;
363
- this.availableOutgoingBitrate += observedPeerConnection.availableOutgoingBitrate;
364
-
365
- this.numberOfDataChannels += observedPeerConnection.observedDataChannels.size;
366
- this.numberOfInbundTracks += observedPeerConnection.observedInboundTracks.size;
367
- this.numberOfOutboundRtpStreams += observedPeerConnection.observedOutboundRtps.size;
368
- this.numberOfOutboundTracks += observedPeerConnection.observedOutboundTracks.size;
369
- this.numberOfInboundRtpStreams += observedPeerConnection.observedInboundRtps.size;
370
-
371
- if (observedPeerConnection.currentRttInMs) {
372
- this.deltaRttInMsMeasurements.push(observedPeerConnection.currentRttInMs);
373
- }
423
+ return observedPeerConnection;
374
424
  }
375
425
 
376
- public resetSummaryMetrics() {
377
- this.totalDataChannelBytesReceived = 0;
378
- this.totalDataChannelBytesSent = 0;
379
- this.totalDataChannelMessagesReceived = 0;
380
- this.totalDataChannelMessagesSent = 0;
381
- this.totalInboundPacketsLost = 0;
382
- this.totalInboundPacketsReceived = 0;
383
- this.totalOutboundPacketsSent = 0;
384
- this.totalReceivedAudioBytes = 0;
385
- this.totalReceivedVideoBytes = 0;
386
- this.totalSentAudioBytes = 0;
387
- this.totalSentVideoBytes = 0;
388
- this.totalSentBytes = 0;
389
- this.totalReceivedBytes = 0;
426
+ // public resetSummaryMetrics() {
427
+ // this.totalDataChannelBytesReceived = 0;
428
+ // this.totalDataChannelBytesSent = 0;
429
+ // this.totalDataChannelMessagesReceived = 0;
430
+ // this.totalDataChannelMessagesSent = 0;
431
+ // this.totalInboundPacketsLost = 0;
432
+ // this.totalInboundPacketsReceived = 0;
433
+ // this.totalOutboundPacketsSent = 0;
434
+ // this.totalReceivedAudioBytes = 0;
435
+ // this.totalReceivedVideoBytes = 0;
436
+ // this.totalSentAudioBytes = 0;
437
+ // this.totalSentVideoBytes = 0;
438
+ // this.totalSentBytes = 0;
439
+ // this.totalReceivedBytes = 0;
390
440
 
391
- this.numberOfIssues = 0;
441
+ // this.totalNumberOfIssues = 0;
392
442
 
393
- this.totalScoreSum = 0;
394
- this.numberOfScoreMeasurements = 0;
395
- }
396
-
397
- public createSummary(): ObservedClientSummary {
398
- return {
399
- totalRttLt50Measurements: this.totalRttLt50Measurements,
400
- totalRttLt150Measurements: this.totalRttLt150Measurements,
401
- totalRttLt300Measurements: this.totalRttLt300Measurements,
402
- totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
403
- totalDataChannelBytesReceived: this.totalDataChannelBytesReceived,
404
- totalDataChannelBytesSent: this.totalDataChannelBytesSent,
405
- totalDataChannelMessagesReceived: this.totalDataChannelMessagesReceived,
406
- totalDataChannelMessagesSent: this.totalDataChannelMessagesSent,
407
- totalInboundPacketsLost: this.totalInboundPacketsLost,
408
- totalInboundPacketsReceived: this.totalInboundPacketsReceived,
409
- totalOutboundPacketsSent: this.totalOutboundPacketsSent,
410
- totalReceivedAudioBytes: this.totalReceivedAudioBytes,
411
- totalReceivedVideoBytes: this.totalReceivedVideoBytes,
412
- totalSentAudioBytes: this.totalSentAudioBytes,
413
- totalSentVideoBytes: this.totalSentVideoBytes,
414
- totalSentBytes: this.totalSentBytes,
415
- totalReceivedBytes: this.totalReceivedBytes,
443
+ // this.totalScoreSum = 0;
444
+ // this.numberOfScoreMeasurements = 0;
445
+ // }
446
+
447
+ // public createSummary(): ObservedClientSummary {
448
+ // return {
449
+ // totalRttLt50Measurements: this.totalRttLt50Measurements,
450
+ // totalRttLt150Measurements: this.totalRttLt150Measurements,
451
+ // totalRttLt300Measurements: this.totalRttLt300Measurements,
452
+ // totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
453
+ // totalDataChannelBytesReceived: this.totalDataChannelBytesReceived,
454
+ // totalDataChannelBytesSent: this.totalDataChannelBytesSent,
455
+ // totalDataChannelMessagesReceived: this.totalDataChannelMessagesReceived,
456
+ // totalDataChannelMessagesSent: this.totalDataChannelMessagesSent,
457
+ // totalInboundPacketsLost: this.totalInboundPacketsLost,
458
+ // totalInboundPacketsReceived: this.totalInboundPacketsReceived,
459
+ // totalOutboundPacketsSent: this.totalOutboundPacketsSent,
460
+ // totalReceivedAudioBytes: this.totalReceivedAudioBytes,
461
+ // totalReceivedVideoBytes: this.totalReceivedVideoBytes,
462
+ // totalSentAudioBytes: this.totalSentAudioBytes,
463
+ // totalSentVideoBytes: this.totalSentVideoBytes,
464
+ // totalSentBytes: this.totalSentBytes,
465
+ // totalReceivedBytes: this.totalReceivedBytes,
416
466
 
417
- numberOfIssues: this.numberOfIssues,
467
+ // numberOfIssues: this.totalNumberOfIssues,
418
468
 
419
- totalScoreSum: this.totalScoreSum,
420
- numberOfScoreMeasurements: this.numberOfScoreMeasurements,
421
- };
422
- }
423
-
424
- private _updateRttMeasurements() {
425
- if (this.deltaRttInMsMeasurements.length < 1) {
426
- this.currentRttInMs = undefined;
427
-
428
- return;
429
- }
430
- this.currentRttInMs = getMedian(this.deltaRttInMsMeasurements, false);
431
-
432
- if (this.currentRttInMs < 0) {
433
- logger.warn(`Current Rtt for client ${this.clientId} is smaller than 0`);
434
- this.currentRttInMs = undefined;
435
-
436
- return;
437
- }
438
-
439
- if (this.currentRttInMs < 50) {
440
- this.deltaRttLt50Measurements += 1;
441
- } else if (this.currentRttInMs < 150) {
442
- this.deltaRttLt150Measurements += 1;
443
- } else if (this.currentRttInMs < 300) {
444
- this.deltaRttLt300Measurements += 1;
445
- } else if (300 <= this.currentRttInMs) {
446
- this.deltaRttGtOrEq300Measurements += 1;
447
- }
448
- }
469
+ // totalScoreSum: this.totalScoreSum,
470
+ // numberOfScoreMeasurements: this.numberOfScoreMeasurements,
471
+ // };
472
+ // }
449
473
  }
@@ -302,7 +302,9 @@ export class ObservedPeerConnection extends EventEmitter {
302
302
  this.deltaReceivedVideoPackets = 0;
303
303
  this.deltaSentAudioBytes = 0;
304
304
  this.deltaSentVideoBytes = 0;
305
-
305
+ this.deltaTransportReceivedBytes = 0;
306
+ this.deltaTransportSentBytes = 0;
307
+
306
308
  this.sendingAudioBitrate = 0;
307
309
  this.sendingVideoBitrate = 0;
308
310
  this.receivingAudioBitrate = 0;
@@ -428,7 +430,10 @@ export class ObservedPeerConnection extends EventEmitter {
428
430
  }
429
431
  if (sample.peerConnectionTransports) {
430
432
  for (const peerConnectionTransport of sample.peerConnectionTransports) {
431
- this._updatePeerConnectionTransportStats(peerConnectionTransport);
433
+ const observedTransport = this._updatePeerConnectionTransportStats(peerConnectionTransport);
434
+
435
+ if (!observedTransport) continue;
436
+
432
437
  }
433
438
  }
434
439
  if (sample.remoteInboundRtps) {
@@ -496,16 +501,24 @@ export class ObservedPeerConnection extends EventEmitter {
496
501
  } else {
497
502
  this.currentJitter = undefined;
498
503
  }
499
-
500
- const selectedIceCandidatePairs = this.selectedIceCandidatePairs;
501
- const selectedCandidatePairForTurn = selectedIceCandidatePairs.filter((pair) =>
502
- pair.getLocalCandidate()?.candidateType === 'relay' &&
503
- pair.getRemoteCandidate()?.url?.startsWith('turn:')
504
- );
505
504
  const wasUsingTURN = this.usingTURN;
505
+ const selectedIceCandidatePairs = this.selectedIceCandidatePairs;
506
+ const selectedCandidatePairForTurn: ObservedIceCandidatePair[] = [];
507
+
508
+ this.usingTCP = false;
509
+ this.usingTURN = false;
506
510
 
507
- this.usingTCP = selectedIceCandidatePairs.some((pair) => pair.getLocalCandidate()?.protocol === 'tcp');
508
- this.usingTURN = 0 < selectedCandidatePairForTurn.length;
511
+ for (const selectedCandidatePair of selectedIceCandidatePairs) {
512
+ if (selectedCandidatePair.getLocalCandidate()?.protocol === 'tcp') {
513
+ this.usingTCP = true;
514
+ }
515
+ if (selectedCandidatePair.getLocalCandidate()?.candidateType === 'relay' && selectedCandidatePair.getRemoteCandidate()?.url?.startsWith('turn:')) {
516
+ selectedCandidatePairForTurn.push(selectedCandidatePair);
517
+ this.usingTURN = true;
518
+ }
519
+ this.deltaTransportReceivedBytes += selectedCandidatePair.deltaBytesReceived;
520
+ this.deltaTransportSentBytes += selectedCandidatePair.deltaBytesSent;
521
+ }
509
522
 
510
523
  if (this.usingTURN) {
511
524
  if (!this.observedTurnServer) {