@observertc/observer-js 1.0.0-beta.22 → 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.d.mts CHANGED
@@ -141,7 +141,7 @@ type IceCandidatePairStats = {
141
141
  /**
142
142
  * The checklist state of this candidate pair. Values follow the W3C RTCStatsIceCandidatePairState enum (frozen, waiting, in-progress, failed, succeeded). Two further values are accepted for backward compatibility and are not part of the current spec: `new` (never standardised) and `cancelled` (removed from the spec after 2016).
143
143
  */
144
- state?: 'new' | 'frozen' | 'in-progress' | 'waiting' | 'failed' | 'succeeded' | 'cancelled' | 'inprogress';
144
+ state?: "new" | "frozen" | "in-progress" | "waiting" | "failed" | "succeeded" | "cancelled" | "inprogress";
145
145
  /**
146
146
  * Whether this candidate pair has been nominated.
147
147
  */
@@ -1265,9 +1265,9 @@ type OutboundTrackSample = {
1265
1265
  */
1266
1266
  score?: number;
1267
1267
  /**
1268
- * Details for score calculation
1268
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1269
1269
  */
1270
- scoreReasons?: string[];
1270
+ scoreReasons?: Record<string, number>;
1271
1271
  /**
1272
1272
  * Additional information attached to this stats
1273
1273
  */
@@ -1294,9 +1294,9 @@ type InboundTrackSample = {
1294
1294
  */
1295
1295
  score?: number;
1296
1296
  /**
1297
- * Details for score calculation
1297
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1298
1298
  */
1299
- scoreReasons?: string[];
1299
+ scoreReasons?: Record<string, number>;
1300
1300
  /**
1301
1301
  * Additional information attached to this stats
1302
1302
  */
@@ -1319,9 +1319,9 @@ type PeerConnectionSample = {
1319
1319
  */
1320
1320
  score?: number;
1321
1321
  /**
1322
- * Details for score calculation
1322
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1323
1323
  */
1324
- scoreReasons?: string[];
1324
+ scoreReasons?: Record<string, number>;
1325
1325
  /**
1326
1326
  * Inbound Track Stats items
1327
1327
  */
@@ -1408,9 +1408,9 @@ type ClientSample = {
1408
1408
  */
1409
1409
  score?: number;
1410
1410
  /**
1411
- * Details for score calculation
1411
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1412
1412
  */
1413
- scoreReasons?: string[];
1413
+ scoreReasons?: Record<string, number>;
1414
1414
  /**
1415
1415
  * Samples taken PeerConnections
1416
1416
  */
package/dist/index.d.ts CHANGED
@@ -141,7 +141,7 @@ type IceCandidatePairStats = {
141
141
  /**
142
142
  * The checklist state of this candidate pair. Values follow the W3C RTCStatsIceCandidatePairState enum (frozen, waiting, in-progress, failed, succeeded). Two further values are accepted for backward compatibility and are not part of the current spec: `new` (never standardised) and `cancelled` (removed from the spec after 2016).
143
143
  */
144
- state?: 'new' | 'frozen' | 'in-progress' | 'waiting' | 'failed' | 'succeeded' | 'cancelled' | 'inprogress';
144
+ state?: "new" | "frozen" | "in-progress" | "waiting" | "failed" | "succeeded" | "cancelled" | "inprogress";
145
145
  /**
146
146
  * Whether this candidate pair has been nominated.
147
147
  */
@@ -1265,9 +1265,9 @@ type OutboundTrackSample = {
1265
1265
  */
1266
1266
  score?: number;
1267
1267
  /**
1268
- * Details for score calculation
1268
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1269
1269
  */
1270
- scoreReasons?: string[];
1270
+ scoreReasons?: Record<string, number>;
1271
1271
  /**
1272
1272
  * Additional information attached to this stats
1273
1273
  */
@@ -1294,9 +1294,9 @@ type InboundTrackSample = {
1294
1294
  */
1295
1295
  score?: number;
1296
1296
  /**
1297
- * Details for score calculation
1297
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1298
1298
  */
1299
- scoreReasons?: string[];
1299
+ scoreReasons?: Record<string, number>;
1300
1300
  /**
1301
1301
  * Additional information attached to this stats
1302
1302
  */
@@ -1319,9 +1319,9 @@ type PeerConnectionSample = {
1319
1319
  */
1320
1320
  score?: number;
1321
1321
  /**
1322
- * Details for score calculation
1322
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1323
1323
  */
1324
- scoreReasons?: string[];
1324
+ scoreReasons?: Record<string, number>;
1325
1325
  /**
1326
1326
  * Inbound Track Stats items
1327
1327
  */
@@ -1408,9 +1408,9 @@ type ClientSample = {
1408
1408
  */
1409
1409
  score?: number;
1410
1410
  /**
1411
- * Details for score calculation
1411
+ * Reasons for the score calculation, mapping each reason to how much it contributed to the score
1412
1412
  */
1413
- scoreReasons?: string[];
1413
+ scoreReasons?: Record<string, number>;
1414
1414
  /**
1415
1415
  * Samples taken PeerConnections
1416
1416
  */
package/dist/index.js CHANGED
@@ -1547,6 +1547,24 @@ function parseJsonObject(value) {
1547
1547
  const parsed = parseJsonAs(value);
1548
1548
  return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
1549
1549
  }
1550
+ function normalizeScoreReasons(value) {
1551
+ if (value === void 0 || value === null) return void 0;
1552
+ const result = {};
1553
+ if (Array.isArray(value)) {
1554
+ for (const entry of value) {
1555
+ if (typeof entry !== "string" || entry.length === 0) continue;
1556
+ result[entry] = 0;
1557
+ }
1558
+ } else if (typeof value === "object") {
1559
+ for (const [key, magnitude] of Object.entries(value)) {
1560
+ if (typeof magnitude !== "number" || !Number.isFinite(magnitude)) continue;
1561
+ result[key] = magnitude;
1562
+ }
1563
+ } else {
1564
+ return void 0;
1565
+ }
1566
+ return Object.keys(result).length === 0 ? void 0 : result;
1567
+ }
1550
1568
 
1551
1569
  // src/ObservedOutboundTrack.ts
1552
1570
  var ObservedOutboundTrack = class {
@@ -2827,6 +2845,16 @@ var ObservedClient = class extends import_events2.EventEmitter {
2827
2845
  this.usingTCP = false;
2828
2846
  this.currentMinRttInMs = void 0;
2829
2847
  this.currentMaxRttInMs = void 0;
2848
+ sample.scoreReasons = normalizeScoreReasons(sample.scoreReasons);
2849
+ for (const pcSample of sample.peerConnections ?? []) {
2850
+ pcSample.scoreReasons = normalizeScoreReasons(pcSample.scoreReasons);
2851
+ for (const trackSample of pcSample.inboundTracks ?? []) {
2852
+ trackSample.scoreReasons = normalizeScoreReasons(trackSample.scoreReasons);
2853
+ }
2854
+ for (const trackSample of pcSample.outboundTracks ?? []) {
2855
+ trackSample.scoreReasons = normalizeScoreReasons(trackSample.scoreReasons);
2856
+ }
2857
+ }
2830
2858
  this._mergePendingInjections(sample);
2831
2859
  this._activeSample = sample;
2832
2860
  const clientEventsPostBuffer = [];