@flashphoner/websdk 2.0.263 → 2.0.265

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.
@@ -13354,9 +13354,7 @@ const StreamStatsCollector = function(description, id, mediaConnection, wsConnec
13354
13354
  statCollector.timerBusy = true;
13355
13355
  let stats = await statCollector.mediaConnection.getWebRTCStats();
13356
13356
 
13357
- if (!statCollector.metricsBatch) {
13358
- statCollector.metricsBatch = [];
13359
- }
13357
+ statCollector.startNewBatch();
13360
13358
 
13361
13359
  let metrics = [];
13362
13360
  let lostMetrics = [];
@@ -13367,7 +13365,7 @@ const StreamStatsCollector = function(description, id, mediaConnection, wsConnec
13367
13365
  id: components[1],
13368
13366
  name: components[2]
13369
13367
  }
13370
- let value = "NO";
13368
+ let value = null;
13371
13369
 
13372
13370
  if (stats[descriptor.type]) {
13373
13371
  for (const report of stats[descriptor.type]) {
@@ -13377,23 +13375,29 @@ const StreamStatsCollector = function(description, id, mediaConnection, wsConnec
13377
13375
  }
13378
13376
  }
13379
13377
  }
13380
- metrics.push(value);
13381
- if (value == "NO") {
13378
+ if (value === null) {
13382
13379
  lostMetrics.push(descriptor);
13380
+ } else {
13381
+ metrics.push(value);
13383
13382
  }
13384
13383
  });
13384
+ // Metrics list may change if some metrics are added or some metrics are lost #WCS-4627
13385
+ let headersUpdated = await statCollector.updateHeaders(stats);
13385
13386
  if (lostMetrics.length) {
13386
13387
  statCollector.logger.info(LOG_PREFIX + "-" + statCollector.id, "Missing metrics: " + JSON.stringify(lostMetrics));
13387
- }
13388
- statCollector.metricsBatch.push(metrics);
13389
- statCollector.batchCount--;
13390
- if (statCollector.batchCount === 0) {
13388
+ // Send metrics already collected and start a new batch with current metrics array to send them later #WCS-4627
13391
13389
  await statCollector.sendMetrics();
13390
+ statCollector.startNewBatch(metrics);
13391
+ } else {
13392
+ statCollector.metricsBatch.push(metrics);
13393
+ statCollector.batchCount--;
13394
+ if (statCollector.batchCount === 0 || headersUpdated) {
13395
+ await statCollector.sendMetrics();
13396
+ }
13392
13397
  }
13393
13398
  // Check if metrics list changed and send a new headers if needed #WCS-4619
13394
- if (await statCollector.updateHeaders(stats)) {
13399
+ if (headersUpdated) {
13395
13400
  statCollector.logger.info(LOG_PREFIX + "-" + statCollector.id, "RTC metrics list has changed, sending a new metrics description");
13396
- await statCollector.sendMetrics();
13397
13401
  statCollector.sendHeaders();
13398
13402
  }
13399
13403
  statCollector.timerBusy = false;
@@ -13404,7 +13408,7 @@ const StreamStatsCollector = function(description, id, mediaConnection, wsConnec
13404
13408
  let metricsToSend = [];
13405
13409
  let metricsData;
13406
13410
 
13407
- for (let i = 0; i < statCollector.metricsBatch.length; i++) {
13411
+ for (let i = 0; statCollector.metricsBatch && i < statCollector.metricsBatch.length; i++) {
13408
13412
  let metricsString = "";
13409
13413
  for (let j = 0; j < statCollector.metricsBatch[i].length; j++) {
13410
13414
  let valueString = valueToString(statCollector.metricsBatch[i][j]);
@@ -13441,8 +13445,21 @@ const StreamStatsCollector = function(description, id, mediaConnection, wsConnec
13441
13445
  };
13442
13446
  statCollector.send("webRTCMetricsBatch", data);
13443
13447
  }
13444
- statCollector.metricsBatch = null;
13445
- statCollector.batchCount = statCollector.description.batchSize;
13448
+ statCollector.cleanBatch();
13449
+ },
13450
+ startNewBatch: function(metrics) {
13451
+ if (!statCollector.metricsBatch) {
13452
+ statCollector.metricsBatch = [];
13453
+ if (metrics) {
13454
+ statCollector.metricsBatch.push(metrics);
13455
+ }
13456
+ }
13457
+ },
13458
+ cleanBatch: function() {
13459
+ if (statCollector.metricsBatch) {
13460
+ statCollector.metricsBatch = null;
13461
+ statCollector.batchCount = statCollector.description.batchSize;
13462
+ }
13446
13463
  }
13447
13464
  }
13448
13465
  return statCollector;