@observertc/observer-js 1.0.0-beta.21 → 1.0.0-beta.23

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/index.mjs CHANGED
@@ -1411,17 +1411,37 @@ var ObservedInboundTrack = class {
1411
1411
  function pushFinite(target, value) {
1412
1412
  if (typeof value === "number" && Number.isFinite(value)) target.push(value);
1413
1413
  }
1414
- function parseJsonAs(json) {
1415
- if (!json) return void 0;
1414
+ function parseJsonAs(value) {
1415
+ if (value === void 0 || value === null || value === "") return void 0;
1416
+ if (typeof value === "object") return value;
1417
+ if (typeof value !== "string") return void 0;
1416
1418
  try {
1417
- return JSON.parse(json);
1419
+ return JSON.parse(value);
1418
1420
  } catch {
1419
1421
  return void 0;
1420
1422
  }
1421
1423
  }
1422
- function parseJsonObject(json) {
1423
- const parsed = parseJsonAs(json);
1424
- return typeof parsed === "object" && parsed !== null ? parsed : void 0;
1424
+ function parseJsonObject(value) {
1425
+ const parsed = parseJsonAs(value);
1426
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
1427
+ }
1428
+ function normalizeScoreReasons(value) {
1429
+ if (value === void 0 || value === null) return void 0;
1430
+ const result = {};
1431
+ if (Array.isArray(value)) {
1432
+ for (const entry of value) {
1433
+ if (typeof entry !== "string" || entry.length === 0) continue;
1434
+ result[entry] = 0;
1435
+ }
1436
+ } else if (typeof value === "object") {
1437
+ for (const [key, magnitude] of Object.entries(value)) {
1438
+ if (typeof magnitude !== "number" || !Number.isFinite(magnitude)) continue;
1439
+ result[key] = magnitude;
1440
+ }
1441
+ } else {
1442
+ return void 0;
1443
+ }
1444
+ return Object.keys(result).length === 0 ? void 0 : result;
1425
1445
  }
1426
1446
 
1427
1447
  // src/ObservedOutboundTrack.ts
@@ -2703,6 +2723,16 @@ var ObservedClient = class extends EventEmitter2 {
2703
2723
  this.usingTCP = false;
2704
2724
  this.currentMinRttInMs = void 0;
2705
2725
  this.currentMaxRttInMs = void 0;
2726
+ sample.scoreReasons = normalizeScoreReasons(sample.scoreReasons);
2727
+ for (const pcSample of sample.peerConnections ?? []) {
2728
+ pcSample.scoreReasons = normalizeScoreReasons(pcSample.scoreReasons);
2729
+ for (const trackSample of pcSample.inboundTracks ?? []) {
2730
+ trackSample.scoreReasons = normalizeScoreReasons(trackSample.scoreReasons);
2731
+ }
2732
+ for (const trackSample of pcSample.outboundTracks ?? []) {
2733
+ trackSample.scoreReasons = normalizeScoreReasons(trackSample.scoreReasons);
2734
+ }
2735
+ }
2706
2736
  this._mergePendingInjections(sample);
2707
2737
  this._activeSample = sample;
2708
2738
  const clientEventsPostBuffer = [];