@webex/web-client-media-engine 1.34.2 → 1.34.3

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/dist/cjs/index.js CHANGED
@@ -6440,6 +6440,43 @@ var uuid_1 = require$$0;
6440
6440
  * @returns - Copied value.
6441
6441
  */
6442
6442
  var deepCopy$1 = function (value) { return JSON.parse(JSON.stringify(value)); };
6443
+ /**
6444
+ * Check deep equality between two values.
6445
+ *
6446
+ * @param value1 - First value to check.
6447
+ * @param value2 - Second value to check.
6448
+ * @returns True if values are deeply equal, false otherwise.
6449
+ */
6450
+ var deepEqual = function (value1, value2) {
6451
+ // If both immutable values are equal, return true.
6452
+ if (value1 === value2) {
6453
+ return true;
6454
+ }
6455
+ // If both are objects, we check the length and properties of each.
6456
+ if (value1 && value2 && typeof value1 === 'object' && typeof value2 === 'object') {
6457
+ if (value1.constructor !== value2.constructor)
6458
+ return false;
6459
+ // Return false if the objects are of different sizes.
6460
+ if (Object.keys(value1).length !== Object.keys(value2).length) {
6461
+ return false;
6462
+ }
6463
+ // Deep equal check each property in the opject.
6464
+ for (var prop in value1) {
6465
+ if (value2.hasOwnProperty(prop)) {
6466
+ if (!deepEqual(value1[prop], value2[prop])) {
6467
+ return false;
6468
+ }
6469
+ }
6470
+ else {
6471
+ return false;
6472
+ }
6473
+ }
6474
+ // Return true if we found no differing properties.
6475
+ return true;
6476
+ }
6477
+ // Return false if no other conditions are met.
6478
+ return false;
6479
+ };
6443
6480
  /**
6444
6481
  * Translates a RTCStatsReport into an object.
6445
6482
  *
@@ -6456,6 +6493,16 @@ var map2obj = function (report) {
6456
6493
  });
6457
6494
  return o;
6458
6495
  };
6496
+ var persistedKeys = ['type', 'id', 'timestamp'];
6497
+ /**
6498
+ * Check to see if the report consists of more than just the persisted metadata.
6499
+ *
6500
+ * @param report - The report line being checked.
6501
+ * @returns True if the report item contains non-persisted keys, false otherwise.
6502
+ */
6503
+ var hasNonMetadata = function (report) {
6504
+ return !!Object.keys(report).filter(function (key) { return !persistedKeys.includes(key); }).length;
6505
+ };
6459
6506
  /**
6460
6507
  * Apply a delta compression to the stats report. Reduces size by ~90%.
6461
6508
  * To reduce further, report keys could be compressed.
@@ -6468,20 +6515,21 @@ var deltaCompression = function (oldStats, newStats) {
6468
6515
  var updatedStats = deepCopy$1(newStats);
6469
6516
  Object.keys(updatedStats).forEach(function (id) {
6470
6517
  var report = updatedStats[id];
6471
- delete report.id;
6472
6518
  if (!oldStats[id]) {
6473
6519
  return;
6474
6520
  }
6521
+ // Persist specific values beyond delta compression, as long as they
6522
+ // aren't the only non-deduped keys.
6475
6523
  Object.keys(report).forEach(function (name) {
6476
- if (report[name] === oldStats[id][name]) {
6524
+ if (deepEqual(report[name], oldStats[id][name]) && !persistedKeys.includes(name)) {
6477
6525
  delete updatedStats[id][name];
6478
6526
  }
6479
- if (Object.keys(report).length === 0 ||
6480
- (Object.keys(report).length === 1 && report.timestamp)) {
6527
+ if (!hasNonMetadata(report)) {
6481
6528
  delete updatedStats[id];
6482
6529
  }
6483
6530
  });
6484
6531
  });
6532
+ // Use the most recent timestamp.
6485
6533
  var timestamp = -Infinity;
6486
6534
  Object.keys(updatedStats).forEach(function (id) {
6487
6535
  var report = updatedStats[id];
@@ -6489,15 +6537,34 @@ var deltaCompression = function (oldStats, newStats) {
6489
6537
  timestamp = report.timestamp;
6490
6538
  }
6491
6539
  });
6540
+ // Delete the timestamps on each item.
6492
6541
  Object.keys(updatedStats).forEach(function (id) {
6493
6542
  var report = updatedStats[id];
6494
6543
  if (report.timestamp === timestamp) {
6495
- report.timestamp = 0;
6544
+ delete report.timestamp;
6496
6545
  }
6497
6546
  });
6498
6547
  updatedStats.timestamp = timestamp;
6499
6548
  return updatedStats;
6500
6549
  };
6550
+ /**
6551
+ * Format the stats report into an array.
6552
+ *
6553
+ * @param report - A WebRTC stats report.
6554
+ * @returns - An array of Stats Report items.
6555
+ */
6556
+ var formatStatsReport = function (report) {
6557
+ return Object.keys(report)
6558
+ .filter(function (name) { return name !== 'timestamp'; })
6559
+ .map(function (name) { return report[name]; });
6560
+ };
6561
+ /**
6562
+ * Parametrize a single string event to contain type and an (empty) id.
6563
+ *
6564
+ * @param value - The value to parametrize.
6565
+ * @returns An event object.
6566
+ */
6567
+ var makeEvent = function (value) { return ([{ value: value, type: 'string', id: '' }]); };
6501
6568
  /**
6502
6569
  * Attach a Peer Connection to periodically get updated on events and stats.
6503
6570
  *
@@ -6514,39 +6581,41 @@ var rtcStats = function (pc, logger, intervalTime, id, statsPreProcessor) {
6514
6581
  /**
6515
6582
  * Log stats or event data with additional tracking information.
6516
6583
  *
6517
- * @param args - Array of parameters to log of any type.
6584
+ * @param name - Name of the event to log.
6585
+ * @param payload - Log data pertaining to the event.
6518
6586
  */
6519
- var trace = function (eventName, data) {
6520
- logger({ name: '[rtcstats]', id: id, eventName: eventName, data: data });
6587
+ var trace = function (name, payload, timestamp) {
6588
+ logger({ id: id, timestamp: timestamp ? Math.round(timestamp) : Date.now(), name: name, payload: payload });
6521
6589
  };
6522
- trace('creating stats report');
6523
6590
  pc.addEventListener('icecandidate', function (e) {
6524
- trace('onicecandidate', e.candidate);
6591
+ if (e.candidate) {
6592
+ trace('onicecandidate', makeEvent(JSON.stringify(e.candidate)));
6593
+ }
6525
6594
  });
6526
6595
  pc.addEventListener('icecandidateerror', function (event) {
6527
6596
  var _a = event, errorCode = _a.errorCode, errorText = _a.errorText;
6528
- trace('onicecandidateerror', { errorText: errorText, errorCode: errorCode });
6597
+ trace('onicecandidateerror', makeEvent("".concat(errorCode, ": ").concat(errorText)));
6529
6598
  });
6530
6599
  pc.addEventListener('track', function (e) {
6531
- trace('ontrack', "".concat(e.track.kind, ":").concat(e.track.id, " ").concat(e.streams.map(function (stream) { return "stream:".concat(stream.id); })));
6600
+ trace('ontrack', makeEvent("".concat(e.track.kind, ":").concat(e.track.id, " ").concat(e.streams.map(function (stream) { return "stream:".concat(stream.id); }).join(' '))));
6532
6601
  });
6533
6602
  pc.addEventListener('signalingstatechange', function () {
6534
- trace('onsignalingstatechange', pc.signalingState);
6603
+ trace('onsignalingstatechange', makeEvent(pc.signalingState));
6535
6604
  });
6536
6605
  pc.addEventListener('iceconnectionstatechange', function () {
6537
- trace('oniceconnectionstatechange', pc.iceConnectionState);
6606
+ trace('oniceconnectionstatechange', makeEvent(pc.iceConnectionState));
6538
6607
  });
6539
6608
  pc.addEventListener('icegatheringstatechange', function () {
6540
- trace('onicegatheringstatechange', pc.iceGatheringState);
6609
+ trace('onicegatheringstatechange', makeEvent(pc.iceGatheringState));
6541
6610
  });
6542
6611
  pc.addEventListener('connectionstatechange', function () {
6543
- trace('onconnectionstatechange', pc.connectionState);
6612
+ trace('onconnectionstatechange', makeEvent(pc.connectionState));
6544
6613
  });
6545
6614
  pc.addEventListener('negotiationneeded', function () {
6546
- trace('onnegotiationneeded');
6615
+ trace('onnegotiationneeded', makeEvent('negotiationneeded'));
6547
6616
  });
6548
6617
  pc.addEventListener('datachannel', function (event) {
6549
- trace('ondatachannel', [event.channel.id, event.channel.label]);
6618
+ trace('ondatachannel', makeEvent("".concat(event.channel.id, ": ").concat(event.channel.label)));
6550
6619
  });
6551
6620
  var interval = window.setInterval(function () {
6552
6621
  if (pc.signalingState === 'closed') {
@@ -6557,7 +6626,8 @@ var rtcStats = function (pc, logger, intervalTime, id, statsPreProcessor) {
6557
6626
  var now = map2obj(res);
6558
6627
  statsPreProcessor(now).then(function () {
6559
6628
  var base = deepCopy$1(now); // our new prev
6560
- trace('stats-report', deltaCompression(prev, now));
6629
+ var compressed = deltaCompression(prev, now);
6630
+ trace('stats-report', formatStatsReport(compressed), compressed.timestamp !== -Infinity ? compressed.timestamp : undefined);
6561
6631
  prev = base;
6562
6632
  });
6563
6633
  });