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