@webex/rtcstats
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -10,5 +10,4 @@ /** | ||
name: string; | ||
id: string; | ||
timestamp: number; | ||
payload: unknown[]; | ||
payload: string[]; | ||
}; | ||
@@ -21,5 +20,4 @@ /** | ||
* @param intervalTime - Time between each `getStats` check. | ||
* @param id - Optional id string used for logging. | ||
* @param statsPreProcessor - Optional function that modifies stats. | ||
*/ | ||
export declare const rtcStats: (pc: RTCPeerConnection, logger: (logData: LogData) => void, intervalTime: number, id?: any, statsPreProcessor?: (statsReport: StatsReport) => Promise<void>) => void; | ||
export declare const rtcStats: (pc: RTCPeerConnection, logger: (logData: LogData) => void, intervalTime: number, statsPreProcessor?: (statsReport: Map<string, unknown>) => Promise<void>) => void; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.rtcStats = void 0; | ||
var uuid_1 = require("uuid"); | ||
/** | ||
@@ -32,5 +31,6 @@ * Copies values of any nested depth. | ||
} | ||
// Deep equal check each property in the opject. | ||
for (var prop in value1) { | ||
if (value2.hasOwnProperty(prop)) { | ||
// Deep equal check each property in the object, returns true if we found no | ||
// differing properties. | ||
return Object.keys(value1).reduce(function (val, prop) { | ||
if (value2[prop]) { | ||
if (!deepEqual(value1[prop], value2[prop])) { | ||
@@ -43,5 +43,4 @@ return false; | ||
} | ||
} | ||
// Return true if we found no differing properties. | ||
return true; | ||
return val; | ||
}, true); | ||
} | ||
@@ -52,5 +51,5 @@ // Return false if no other conditions are met. | ||
/** | ||
* Translates a RTCStatsReport into an object. | ||
* Translates a Map into an object. | ||
* | ||
* @param report - The report. | ||
* @param report - The report in Map form. | ||
* @returns - A deduped object. | ||
@@ -75,2 +74,3 @@ */ | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var hasNonMetadata = function (report) { | ||
@@ -132,3 +132,3 @@ return !!Object.keys(report).filter(function (key) { return !persistedKeys.includes(key); }).length; | ||
.filter(function (name) { return name !== 'timestamp'; }) | ||
.map(function (name) { return report[name]; }); | ||
.map(function (name) { return JSON.stringify(report[name]); }); | ||
}; | ||
@@ -141,3 +141,3 @@ /** | ||
*/ | ||
var makeEvent = function (value) { return ([{ value: value, type: 'string', id: '' }]); }; | ||
var makeEvent = function (value) { return [JSON.stringify({ value: value, type: 'string', id: '' })]; }; | ||
/** | ||
@@ -149,7 +149,5 @@ * Attach a Peer Connection to periodically get updated on events and stats. | ||
* @param intervalTime - Time between each `getStats` check. | ||
* @param id - Optional id string used for logging. | ||
* @param statsPreProcessor - Optional function that modifies stats. | ||
*/ | ||
var rtcStats = function (pc, logger, intervalTime, id, statsPreProcessor) { | ||
if (id === void 0) { id = (0, uuid_1.v4)(); } | ||
var rtcStats = function (pc, logger, intervalTime, statsPreProcessor) { | ||
if (statsPreProcessor === void 0) { statsPreProcessor = function () { return Promise.resolve(); }; } | ||
@@ -162,5 +160,6 @@ var prev = {}; | ||
* @param payload - Log data pertaining to the event. | ||
* @param timestamp - Time the event happened in milliseconds. | ||
*/ | ||
var trace = function (name, payload, timestamp) { | ||
logger({ id: id, timestamp: timestamp ? Math.round(timestamp) : Date.now(), name: name, payload: payload }); | ||
logger({ timestamp: timestamp ? Math.round(timestamp) : Date.now(), name: name, payload: payload }); | ||
}; | ||
@@ -177,3 +176,5 @@ pc.addEventListener('icecandidate', function (e) { | ||
pc.addEventListener('track', function (e) { | ||
trace('ontrack', makeEvent("".concat(e.track.kind, ":").concat(e.track.id, " ").concat(e.streams.map(function (stream) { return "stream:".concat(stream.id); }).join(' ')))); | ||
trace('ontrack', makeEvent("".concat(e.track.kind, ":").concat(e.track.id, " ").concat(e.streams | ||
.map(function (stream) { return "stream:".concat(stream.id); }) | ||
.join(' ')))); | ||
}); | ||
@@ -204,4 +205,7 @@ pc.addEventListener('signalingstatechange', function () { | ||
pc.getStats(null).then(function (res) { | ||
var now = map2obj(res); | ||
statsPreProcessor(now).then(function () { | ||
// Convert from stats report to js Map in order to have values set in `statsPreProcessor` | ||
var statsMap = new Map(); | ||
res.forEach(function (stats, key) { return statsMap.set(key, stats); }); | ||
statsPreProcessor(statsMap).then(function () { | ||
var now = map2obj(statsMap); | ||
var base = deepCopy(now); // our new prev | ||
@@ -208,0 +212,0 @@ var compressed = deltaCompression(prev, now); |
{ | ||
"name": "@webex/rtcstats", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "dist/rtcstats.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/rtcstats.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11612
230