@whereby.com/media 1.16.2 → 1.17.0

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.cjs CHANGED
@@ -1448,33 +1448,38 @@ const debugLogger = {
1448
1448
  logger$9.withDebugLogger(debugLogger);
1449
1449
  class PacketLossAnalyser {
1450
1450
  constructor() {
1451
- this.PACKET_LOSS_PERIOD_THRESHOLD = 0.03;
1452
- this.INTERVAL_DIFF_THRESHOLD_MS = 5000;
1451
+ this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD = 0.04;
1452
+ this.END_PACKET_LOSS_PERIOD_THRESHOLD = 0.005;
1453
+ this.INTERVAL_DIFF_THRESHOLD_MS = 4000;
1453
1454
  this.STALE_MEASUREMENT_TIMEOUT_MS = 10000;
1455
+ this.MINIMUM_INTERVAL_MS = 30000;
1454
1456
  this.ssrcsHistory = new Map();
1455
1457
  this.staleMeasurementTimeouts = new Map();
1456
1458
  }
1457
1459
  addPacketLossMeasurement(id, packetLoss, timestamp) {
1458
1460
  this.handleStaleMeasurements(id);
1459
- const hasPacketLoss = packetLoss > this.PACKET_LOSS_PERIOD_THRESHOLD;
1461
+ const beginNewPacketLossPeriod = packetLoss > this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD;
1460
1462
  let history = this.ssrcsHistory.get(id);
1461
1463
  if (!history) {
1462
1464
  history = {
1463
1465
  id,
1464
- hasActivePacketLoss: hasPacketLoss,
1465
- currPeriod: hasPacketLoss ? { begin: timestamp } : undefined,
1466
+ hasActivePacketLoss: beginNewPacketLossPeriod,
1467
+ currPeriod: beginNewPacketLossPeriod ? { begin: timestamp } : undefined,
1466
1468
  hasPeriodicPacketLoss: false,
1467
1469
  };
1468
1470
  this.ssrcsHistory.set(id, history);
1469
1471
  return;
1470
1472
  }
1471
1473
  if (history.hasActivePacketLoss) {
1472
- if (!hasPacketLoss) {
1474
+ if (packetLoss < this.END_PACKET_LOSS_PERIOD_THRESHOLD) {
1473
1475
  this.endPacketLossPeriod(history, timestamp);
1476
+ if (history.prevIntervalInMs && history.prevIntervalInMs < this.MINIMUM_INTERVAL_MS) {
1477
+ this.ssrcsHistory.delete(id);
1478
+ }
1474
1479
  }
1475
1480
  return;
1476
1481
  }
1477
- if (hasPacketLoss) {
1482
+ if (beginNewPacketLossPeriod) {
1478
1483
  history.hasActivePacketLoss = true;
1479
1484
  history.currPeriod = {
1480
1485
  begin: timestamp,
@@ -1483,15 +1488,17 @@ class PacketLossAnalyser {
1483
1488
  }
1484
1489
  hasPeriodicPacketLoss(id, timestamp) {
1485
1490
  const history = this.ssrcsHistory.get(id);
1486
- if (history && this.intervalExceeded(history, timestamp)) {
1491
+ if (history && this.prevIntervalExceeded(history, timestamp)) {
1487
1492
  this.ssrcsHistory.delete(history.id);
1488
1493
  return false;
1489
1494
  }
1490
1495
  return (history === null || history === void 0 ? void 0 : history.hasPeriodicPacketLoss) || false;
1491
1496
  }
1492
- intervalExceeded(history, timestamp) {
1497
+ prevIntervalExceeded(history, timestamp) {
1493
1498
  if (history.prevPeriod && history.prevIntervalInMs) {
1494
- const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) + history.prevIntervalInMs;
1499
+ const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) +
1500
+ history.prevIntervalInMs +
1501
+ this.INTERVAL_DIFF_THRESHOLD_MS;
1495
1502
  return timestamp > intervalLimitTimestamp;
1496
1503
  }
1497
1504
  return false;
@@ -1502,7 +1509,7 @@ class PacketLossAnalyser {
1502
1509
  clearTimeout(staleMeasurementTimeout);
1503
1510
  }
1504
1511
  this.staleMeasurementTimeouts.set(id, setTimeout(() => {
1505
- logger$9.debug("Invalidating measurements for ssrc: %s", id);
1512
+ logger$9.debug("handleStaleMeasurements() [measurements invalid for ssrc: %s]", id);
1506
1513
  this.ssrcsHistory.delete(id);
1507
1514
  }, this.STALE_MEASUREMENT_TIMEOUT_MS));
1508
1515
  }
@@ -4330,7 +4337,9 @@ class P2pRtcManager {
4330
4337
  return;
4331
4338
  }
4332
4339
  const offer = this._transformIncomingSdp(data.message, session.pc);
4333
- (_b = (_a = session.handleOffer(offer).then((answer) => {
4340
+ (_b = (_a = session
4341
+ .handleOffer(offer)
4342
+ .then((answer) => {
4334
4343
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
4335
4344
  receiverId: data.clientId,
4336
4345
  message: this._transformOutgoingSdp(answer),
@@ -4535,6 +4544,20 @@ class P2pRtcManager {
4535
4544
  return entry;
4536
4545
  });
4537
4546
  }
4547
+ if (this._features.addGoogleStunServers) {
4548
+ peerConnectionConfig.iceServers = [
4549
+ ...peerConnectionConfig.iceServers,
4550
+ { urls: "stun:stun.l.google.com:19302" },
4551
+ { urls: "stun:stun2.l.google.com:19302" },
4552
+ ];
4553
+ }
4554
+ if (this._features.addCloudflareStunServers) {
4555
+ peerConnectionConfig.iceServers = [
4556
+ ...peerConnectionConfig.iceServers,
4557
+ { urls: "stun:stun.cloudflare.com:3478" },
4558
+ { urls: "stun:stun.cloudflare.com:53" },
4559
+ ];
4560
+ }
4538
4561
  if (this._features.useOnlyTURN) {
4539
4562
  peerConnectionConfig.iceTransportPolicy = "relay";
4540
4563
  const filter = {
@@ -4899,11 +4922,13 @@ class P2pRtcManager {
4899
4922
  }
4900
4923
  if (cleanSdpOn)
4901
4924
  offer.sdp = cleanSdp(offer.sdp);
4902
- pc.setLocalDescription(offer).catch((e) => {
4925
+ pc.setLocalDescription(offer)
4926
+ .catch((e) => {
4903
4927
  logger$3.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4904
4928
  this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4905
4929
  throw e;
4906
- }).then(() => {
4930
+ })
4931
+ .then(() => {
4907
4932
  this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4908
4933
  receiverId: clientId,
4909
4934
  message: this._transformOutgoingSdp(offer),
package/dist/index.mjs CHANGED
@@ -1427,33 +1427,38 @@ const debugLogger = {
1427
1427
  logger$9.withDebugLogger(debugLogger);
1428
1428
  class PacketLossAnalyser {
1429
1429
  constructor() {
1430
- this.PACKET_LOSS_PERIOD_THRESHOLD = 0.03;
1431
- this.INTERVAL_DIFF_THRESHOLD_MS = 5000;
1430
+ this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD = 0.04;
1431
+ this.END_PACKET_LOSS_PERIOD_THRESHOLD = 0.005;
1432
+ this.INTERVAL_DIFF_THRESHOLD_MS = 4000;
1432
1433
  this.STALE_MEASUREMENT_TIMEOUT_MS = 10000;
1434
+ this.MINIMUM_INTERVAL_MS = 30000;
1433
1435
  this.ssrcsHistory = new Map();
1434
1436
  this.staleMeasurementTimeouts = new Map();
1435
1437
  }
1436
1438
  addPacketLossMeasurement(id, packetLoss, timestamp) {
1437
1439
  this.handleStaleMeasurements(id);
1438
- const hasPacketLoss = packetLoss > this.PACKET_LOSS_PERIOD_THRESHOLD;
1440
+ const beginNewPacketLossPeriod = packetLoss > this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD;
1439
1441
  let history = this.ssrcsHistory.get(id);
1440
1442
  if (!history) {
1441
1443
  history = {
1442
1444
  id,
1443
- hasActivePacketLoss: hasPacketLoss,
1444
- currPeriod: hasPacketLoss ? { begin: timestamp } : undefined,
1445
+ hasActivePacketLoss: beginNewPacketLossPeriod,
1446
+ currPeriod: beginNewPacketLossPeriod ? { begin: timestamp } : undefined,
1445
1447
  hasPeriodicPacketLoss: false,
1446
1448
  };
1447
1449
  this.ssrcsHistory.set(id, history);
1448
1450
  return;
1449
1451
  }
1450
1452
  if (history.hasActivePacketLoss) {
1451
- if (!hasPacketLoss) {
1453
+ if (packetLoss < this.END_PACKET_LOSS_PERIOD_THRESHOLD) {
1452
1454
  this.endPacketLossPeriod(history, timestamp);
1455
+ if (history.prevIntervalInMs && history.prevIntervalInMs < this.MINIMUM_INTERVAL_MS) {
1456
+ this.ssrcsHistory.delete(id);
1457
+ }
1453
1458
  }
1454
1459
  return;
1455
1460
  }
1456
- if (hasPacketLoss) {
1461
+ if (beginNewPacketLossPeriod) {
1457
1462
  history.hasActivePacketLoss = true;
1458
1463
  history.currPeriod = {
1459
1464
  begin: timestamp,
@@ -1462,15 +1467,17 @@ class PacketLossAnalyser {
1462
1467
  }
1463
1468
  hasPeriodicPacketLoss(id, timestamp) {
1464
1469
  const history = this.ssrcsHistory.get(id);
1465
- if (history && this.intervalExceeded(history, timestamp)) {
1470
+ if (history && this.prevIntervalExceeded(history, timestamp)) {
1466
1471
  this.ssrcsHistory.delete(history.id);
1467
1472
  return false;
1468
1473
  }
1469
1474
  return (history === null || history === void 0 ? void 0 : history.hasPeriodicPacketLoss) || false;
1470
1475
  }
1471
- intervalExceeded(history, timestamp) {
1476
+ prevIntervalExceeded(history, timestamp) {
1472
1477
  if (history.prevPeriod && history.prevIntervalInMs) {
1473
- const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) + history.prevIntervalInMs;
1478
+ const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) +
1479
+ history.prevIntervalInMs +
1480
+ this.INTERVAL_DIFF_THRESHOLD_MS;
1474
1481
  return timestamp > intervalLimitTimestamp;
1475
1482
  }
1476
1483
  return false;
@@ -1481,7 +1488,7 @@ class PacketLossAnalyser {
1481
1488
  clearTimeout(staleMeasurementTimeout);
1482
1489
  }
1483
1490
  this.staleMeasurementTimeouts.set(id, setTimeout(() => {
1484
- logger$9.debug("Invalidating measurements for ssrc: %s", id);
1491
+ logger$9.debug("handleStaleMeasurements() [measurements invalid for ssrc: %s]", id);
1485
1492
  this.ssrcsHistory.delete(id);
1486
1493
  }, this.STALE_MEASUREMENT_TIMEOUT_MS));
1487
1494
  }
@@ -4309,7 +4316,9 @@ class P2pRtcManager {
4309
4316
  return;
4310
4317
  }
4311
4318
  const offer = this._transformIncomingSdp(data.message, session.pc);
4312
- (_b = (_a = session.handleOffer(offer).then((answer) => {
4319
+ (_b = (_a = session
4320
+ .handleOffer(offer)
4321
+ .then((answer) => {
4313
4322
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
4314
4323
  receiverId: data.clientId,
4315
4324
  message: this._transformOutgoingSdp(answer),
@@ -4514,6 +4523,20 @@ class P2pRtcManager {
4514
4523
  return entry;
4515
4524
  });
4516
4525
  }
4526
+ if (this._features.addGoogleStunServers) {
4527
+ peerConnectionConfig.iceServers = [
4528
+ ...peerConnectionConfig.iceServers,
4529
+ { urls: "stun:stun.l.google.com:19302" },
4530
+ { urls: "stun:stun2.l.google.com:19302" },
4531
+ ];
4532
+ }
4533
+ if (this._features.addCloudflareStunServers) {
4534
+ peerConnectionConfig.iceServers = [
4535
+ ...peerConnectionConfig.iceServers,
4536
+ { urls: "stun:stun.cloudflare.com:3478" },
4537
+ { urls: "stun:stun.cloudflare.com:53" },
4538
+ ];
4539
+ }
4517
4540
  if (this._features.useOnlyTURN) {
4518
4541
  peerConnectionConfig.iceTransportPolicy = "relay";
4519
4542
  const filter = {
@@ -4878,11 +4901,13 @@ class P2pRtcManager {
4878
4901
  }
4879
4902
  if (cleanSdpOn)
4880
4903
  offer.sdp = cleanSdp(offer.sdp);
4881
- pc.setLocalDescription(offer).catch((e) => {
4904
+ pc.setLocalDescription(offer)
4905
+ .catch((e) => {
4882
4906
  logger$3.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4883
4907
  this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4884
4908
  throw e;
4885
- }).then(() => {
4909
+ })
4910
+ .then(() => {
4886
4911
  this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4887
4912
  receiverId: clientId,
4888
4913
  message: this._transformOutgoingSdp(offer),
@@ -1427,33 +1427,38 @@ const debugLogger = {
1427
1427
  logger$9.withDebugLogger(debugLogger);
1428
1428
  class PacketLossAnalyser {
1429
1429
  constructor() {
1430
- this.PACKET_LOSS_PERIOD_THRESHOLD = 0.03;
1431
- this.INTERVAL_DIFF_THRESHOLD_MS = 5000;
1430
+ this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD = 0.04;
1431
+ this.END_PACKET_LOSS_PERIOD_THRESHOLD = 0.005;
1432
+ this.INTERVAL_DIFF_THRESHOLD_MS = 4000;
1432
1433
  this.STALE_MEASUREMENT_TIMEOUT_MS = 10000;
1434
+ this.MINIMUM_INTERVAL_MS = 30000;
1433
1435
  this.ssrcsHistory = new Map();
1434
1436
  this.staleMeasurementTimeouts = new Map();
1435
1437
  }
1436
1438
  addPacketLossMeasurement(id, packetLoss, timestamp) {
1437
1439
  this.handleStaleMeasurements(id);
1438
- const hasPacketLoss = packetLoss > this.PACKET_LOSS_PERIOD_THRESHOLD;
1440
+ const beginNewPacketLossPeriod = packetLoss > this.BEGIN_PACKET_LOSS_PERIOD_THRESHOLD;
1439
1441
  let history = this.ssrcsHistory.get(id);
1440
1442
  if (!history) {
1441
1443
  history = {
1442
1444
  id,
1443
- hasActivePacketLoss: hasPacketLoss,
1444
- currPeriod: hasPacketLoss ? { begin: timestamp } : undefined,
1445
+ hasActivePacketLoss: beginNewPacketLossPeriod,
1446
+ currPeriod: beginNewPacketLossPeriod ? { begin: timestamp } : undefined,
1445
1447
  hasPeriodicPacketLoss: false,
1446
1448
  };
1447
1449
  this.ssrcsHistory.set(id, history);
1448
1450
  return;
1449
1451
  }
1450
1452
  if (history.hasActivePacketLoss) {
1451
- if (!hasPacketLoss) {
1453
+ if (packetLoss < this.END_PACKET_LOSS_PERIOD_THRESHOLD) {
1452
1454
  this.endPacketLossPeriod(history, timestamp);
1455
+ if (history.prevIntervalInMs && history.prevIntervalInMs < this.MINIMUM_INTERVAL_MS) {
1456
+ this.ssrcsHistory.delete(id);
1457
+ }
1453
1458
  }
1454
1459
  return;
1455
1460
  }
1456
- if (hasPacketLoss) {
1461
+ if (beginNewPacketLossPeriod) {
1457
1462
  history.hasActivePacketLoss = true;
1458
1463
  history.currPeriod = {
1459
1464
  begin: timestamp,
@@ -1462,15 +1467,17 @@ class PacketLossAnalyser {
1462
1467
  }
1463
1468
  hasPeriodicPacketLoss(id, timestamp) {
1464
1469
  const history = this.ssrcsHistory.get(id);
1465
- if (history && this.intervalExceeded(history, timestamp)) {
1470
+ if (history && this.prevIntervalExceeded(history, timestamp)) {
1466
1471
  this.ssrcsHistory.delete(history.id);
1467
1472
  return false;
1468
1473
  }
1469
1474
  return (history === null || history === void 0 ? void 0 : history.hasPeriodicPacketLoss) || false;
1470
1475
  }
1471
- intervalExceeded(history, timestamp) {
1476
+ prevIntervalExceeded(history, timestamp) {
1472
1477
  if (history.prevPeriod && history.prevIntervalInMs) {
1473
- const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) + history.prevIntervalInMs;
1478
+ const intervalLimitTimestamp = this.calculatePeriodCenterTimestamp(history.prevPeriod) +
1479
+ history.prevIntervalInMs +
1480
+ this.INTERVAL_DIFF_THRESHOLD_MS;
1474
1481
  return timestamp > intervalLimitTimestamp;
1475
1482
  }
1476
1483
  return false;
@@ -1481,7 +1488,7 @@ class PacketLossAnalyser {
1481
1488
  clearTimeout(staleMeasurementTimeout);
1482
1489
  }
1483
1490
  this.staleMeasurementTimeouts.set(id, setTimeout(() => {
1484
- logger$9.debug("Invalidating measurements for ssrc: %s", id);
1491
+ logger$9.debug("handleStaleMeasurements() [measurements invalid for ssrc: %s]", id);
1485
1492
  this.ssrcsHistory.delete(id);
1486
1493
  }, this.STALE_MEASUREMENT_TIMEOUT_MS));
1487
1494
  }
@@ -4309,7 +4316,9 @@ class P2pRtcManager {
4309
4316
  return;
4310
4317
  }
4311
4318
  const offer = this._transformIncomingSdp(data.message, session.pc);
4312
- (_b = (_a = session.handleOffer(offer).then((answer) => {
4319
+ (_b = (_a = session
4320
+ .handleOffer(offer)
4321
+ .then((answer) => {
4313
4322
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
4314
4323
  receiverId: data.clientId,
4315
4324
  message: this._transformOutgoingSdp(answer),
@@ -4514,6 +4523,20 @@ class P2pRtcManager {
4514
4523
  return entry;
4515
4524
  });
4516
4525
  }
4526
+ if (this._features.addGoogleStunServers) {
4527
+ peerConnectionConfig.iceServers = [
4528
+ ...peerConnectionConfig.iceServers,
4529
+ { urls: "stun:stun.l.google.com:19302" },
4530
+ { urls: "stun:stun2.l.google.com:19302" },
4531
+ ];
4532
+ }
4533
+ if (this._features.addCloudflareStunServers) {
4534
+ peerConnectionConfig.iceServers = [
4535
+ ...peerConnectionConfig.iceServers,
4536
+ { urls: "stun:stun.cloudflare.com:3478" },
4537
+ { urls: "stun:stun.cloudflare.com:53" },
4538
+ ];
4539
+ }
4517
4540
  if (this._features.useOnlyTURN) {
4518
4541
  peerConnectionConfig.iceTransportPolicy = "relay";
4519
4542
  const filter = {
@@ -4878,11 +4901,13 @@ class P2pRtcManager {
4878
4901
  }
4879
4902
  if (cleanSdpOn)
4880
4903
  offer.sdp = cleanSdp(offer.sdp);
4881
- pc.setLocalDescription(offer).catch((e) => {
4904
+ pc.setLocalDescription(offer)
4905
+ .catch((e) => {
4882
4906
  logger$3.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4883
4907
  this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4884
4908
  throw e;
4885
- }).then(() => {
4909
+ })
4910
+ .then(() => {
4886
4911
  this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4887
4912
  receiverId: clientId,
4888
4913
  message: this._transformOutgoingSdp(offer),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "1.16.2",
4
+ "version": "1.17.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {