@whereby.com/media 2.6.1 → 2.6.3

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
@@ -4548,6 +4548,14 @@ class VegaRtcManager {
4548
4548
  });
4549
4549
  this._networkIsDetectedUpBySignal = false;
4550
4550
  this._cpuOveruseDetected = false;
4551
+ this.analytics = {
4552
+ vegaJoinFailed: 0,
4553
+ vegaJoinWithoutVegaConnection: 0,
4554
+ vegaCreateTransportWithoutVegaConnection: 0,
4555
+ vegaIceRestarts: 0,
4556
+ vegaIceRestartMissingTransport: 0,
4557
+ vegaIceRestartWrongTransportId: 0,
4558
+ };
4551
4559
  }
4552
4560
  _updateAndScheduleMediaServersRefresh({ iceServers, turnServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }) {
4553
4561
  var _a, _b, _c;
@@ -4570,8 +4578,10 @@ class VegaRtcManager {
4570
4578
  iceServers: this._features.turnServersOn ? this._turnServers : this._iceServers,
4571
4579
  };
4572
4580
  iceServersList.iceServers = turnServerOverride(iceServersList.iceServers, this._features.turnServerOverrideHost);
4573
- (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4574
- (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4581
+ if (browserName !== "firefox") {
4582
+ (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4583
+ (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4584
+ }
4575
4585
  this._clearMediaServersRefresh();
4576
4586
  if (!mediaserverConfigTtlSeconds) {
4577
4587
  return;
@@ -4689,10 +4699,16 @@ class VegaRtcManager {
4689
4699
  _join() {
4690
4700
  return __awaiter(this, void 0, void 0, function* () {
4691
4701
  var _a, _b;
4692
- logger$2.info("join()");
4702
+ logger$2.info("_join()");
4693
4703
  this._emitToPWA(rtcManagerEvents.SFU_CONNECTION_OPEN);
4694
4704
  try {
4695
- const { routerRtpCapabilities } = yield this._vegaConnection.request("getCapabilities");
4705
+ if (!this._vegaConnection) {
4706
+ logger$2.error("_join() No VegaConnection found");
4707
+ this.analytics.vegaJoinWithoutVegaConnection++;
4708
+ rtcStats.sendEvent("JoinWithoutVegaConnection", {});
4709
+ throw new Error("No VegaConnection found");
4710
+ }
4711
+ const { routerRtpCapabilities } = (yield this._vegaConnection.request("getCapabilities"));
4696
4712
  if (!this._routerRtpCapabilities) {
4697
4713
  const modifiedCapabilities = modifyMediaCapabilities(routerRtpCapabilities, Object.assign(Object.assign({}, this._features), { vp9On: this._features.sfuVp9On }));
4698
4714
  this._routerRtpCapabilities = modifiedCapabilities;
@@ -4717,14 +4733,22 @@ class VegaRtcManager {
4717
4733
  }
4718
4734
  catch (error) {
4719
4735
  logger$2.error("_join() [error:%o]", error);
4736
+ this.analytics.vegaJoinFailed++;
4737
+ rtcStats.sendEvent("VegaJoinFailed", { error });
4720
4738
  }
4721
4739
  });
4722
4740
  }
4723
4741
  _createTransport(send) {
4724
4742
  return __awaiter(this, void 0, void 0, function* () {
4725
4743
  var _a;
4744
+ if (!this._vegaConnection) {
4745
+ logger$2.error("_createTransport() No VegaConnection found");
4746
+ this.analytics.vegaCreateTransportWithoutVegaConnection++;
4747
+ rtcStats.sendEvent("CreateTransportWithoutVegaConnection", {});
4748
+ throw new Error("No VegaConnection found");
4749
+ }
4726
4750
  const creator = send ? "createSendTransport" : "createRecvTransport";
4727
- const transportOptions = yield this._vegaConnection.request("createTransport", {
4751
+ const optionsFromSfu = (yield this._vegaConnection.request("createTransport", {
4728
4752
  producing: send,
4729
4753
  consuming: !send,
4730
4754
  enableTcp: true,
@@ -4739,7 +4763,8 @@ class VegaRtcManager {
4739
4763
  maxSctpMessageSize: 262144,
4740
4764
  sctpSendBufferSize: 262144,
4741
4765
  },
4742
- });
4766
+ }));
4767
+ const transportOptions = Object.assign({}, optionsFromSfu);
4743
4768
  transportOptions.iceServers = turnServerOverride(this._features.turnServersOn ? this._turnServers : this._iceServers, this._features.turnServerOverrideHost);
4744
4769
  maybeTurnOnly(transportOptions, this._features);
4745
4770
  const transport = (_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
@@ -4749,18 +4774,22 @@ class VegaRtcManager {
4749
4774
  return;
4750
4775
  }
4751
4776
  if (send) {
4752
- if (this._sndTransportIceRestartPromise) {
4777
+ if (this._sndTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4753
4778
  return;
4754
4779
  }
4755
- this._sndTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4780
+ this._sndTransportIceRestartPromise = this._restartIce("send", transport.id)
4781
+ .catch((e) => logger$2.error(e))
4782
+ .finally(() => {
4756
4783
  this._sndTransportIceRestartPromise = null;
4757
4784
  });
4758
4785
  }
4759
4786
  else {
4760
- if (this._rcvTransportIceRestartPromise) {
4787
+ if (this._rcvTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4761
4788
  return;
4762
4789
  }
4763
- this._rcvTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4790
+ this._rcvTransportIceRestartPromise = this._restartIce("recv", transport.id)
4791
+ .catch((e) => logger$2.error(e))
4792
+ .finally(() => {
4764
4793
  this._rcvTransportIceRestartPromise = null;
4765
4794
  });
4766
4795
  }
@@ -4781,13 +4810,13 @@ class VegaRtcManager {
4781
4810
  var _b;
4782
4811
  try {
4783
4812
  const { paused } = appData;
4784
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4813
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4785
4814
  transportId: transport.id,
4786
4815
  kind,
4787
4816
  rtpParameters,
4788
4817
  paused,
4789
4818
  appData,
4790
- }));
4819
+ })));
4791
4820
  callback({ id });
4792
4821
  }
4793
4822
  catch (error) {
@@ -4797,11 +4826,11 @@ class VegaRtcManager {
4797
4826
  transport === null || transport === void 0 ? void 0 : transport.on("producedata", (_a, callback_1, errback_1) => __awaiter(this, [_a, callback_1, errback_1], void 0, function* ({ appData, sctpStreamParameters, }, callback, errback) {
4798
4827
  var _b;
4799
4828
  try {
4800
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4829
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4801
4830
  transportId: transport.id,
4802
4831
  sctpStreamParameters,
4803
4832
  appData,
4804
- }));
4833
+ })));
4805
4834
  callback({ id });
4806
4835
  }
4807
4836
  catch (error) {
@@ -4815,10 +4844,22 @@ class VegaRtcManager {
4815
4844
  }
4816
4845
  });
4817
4846
  }
4818
- _restartIce(transport_1) {
4819
- return __awaiter(this, arguments, void 0, function* (transport, retried = 0) {
4820
- if (!transport || !("closed" in transport) || !("connectionState" in transport)) {
4821
- logger$2.info("_restartIce: No transport or property closed or connectionState!");
4847
+ _restartIce(direction_1, transportId_1) {
4848
+ return __awaiter(this, arguments, void 0, function* (direction, transportId, retried = 0) {
4849
+ this.analytics.vegaIceRestarts++;
4850
+ const transport = direction === "send" ? this._sendTransport : this._receiveTransport;
4851
+ if (!transport) {
4852
+ logger$2.info(`_restartIce: No transport found with id ${transportId}`);
4853
+ this.analytics.vegaIceRestartMissingTransport++;
4854
+ return;
4855
+ }
4856
+ if (transport.id !== transportId) {
4857
+ logger$2.info(`_restartIce: Transport ids does not match [expected: ${transportId}, actual: ${transport.id}]`);
4858
+ this.analytics.vegaIceRestartWrongTransportId++;
4859
+ return;
4860
+ }
4861
+ if (!("closed" in transport) || !("connectionState" in transport)) {
4862
+ logger$2.info("_restartIce: Transport is missing closed or connectionState property");
4822
4863
  return;
4823
4864
  }
4824
4865
  if (transport.closed) {
@@ -4843,7 +4884,9 @@ class VegaRtcManager {
4843
4884
  logger$2.info(`_restartIce: Connection is undefined`);
4844
4885
  return;
4845
4886
  }
4846
- const { iceParameters } = yield this._vegaConnection.request("restartIce", { transportId: transport.id });
4887
+ const { iceParameters } = (yield this._vegaConnection.request("restartIce", {
4888
+ transportId: transport.id,
4889
+ }));
4847
4890
  logger$2.info("_restartIce: ICE restart iceParameters received from SFU: ", iceParameters);
4848
4891
  const error = yield transport
4849
4892
  .restartIce({ iceParameters })
@@ -4861,7 +4904,7 @@ class VegaRtcManager {
4861
4904
  resolve(undefined);
4862
4905
  }, Math.min(RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS * Math.pow(2, retried), 60000));
4863
4906
  });
4864
- yield this._restartIce(transport, retried + 1);
4907
+ yield this._restartIce(direction, transportId, retried + 1);
4865
4908
  break;
4866
4909
  }
4867
4910
  return;
@@ -4872,7 +4915,7 @@ class VegaRtcManager {
4872
4915
  }, 60000 * Math.min(8, retried + 1));
4873
4916
  });
4874
4917
  if (transport.connectionState === "failed" || transport.connectionState === "disconnected") {
4875
- yield this._restartIce(transport, retried + 1);
4918
+ yield this._restartIce(direction, transportId, retried + 1);
4876
4919
  return;
4877
4920
  }
4878
4921
  });
package/dist/index.d.cts CHANGED
@@ -1483,19 +1483,30 @@ declare function createVegaConnectionManager(config: {
1483
1483
  networkIsPossiblyDown: () => void;
1484
1484
  };
1485
1485
 
1486
- type MediaSteamWhichMayHaveInboundId = MediaStream & {
1487
- inboundId?: string;
1486
+ type VegaTransportDirection = "send" | "recv";
1487
+
1488
+ type VegaAnalytics = {
1489
+ vegaJoinFailed: number;
1490
+ vegaJoinWithoutVegaConnection: number;
1491
+ vegaCreateTransportWithoutVegaConnection: number;
1492
+ vegaIceRestarts: number;
1493
+ vegaIceRestartMissingTransport: number;
1494
+ vegaIceRestartWrongTransportId: number;
1488
1495
  };
1496
+
1497
+ type MediaStreamWhichMayHaveInboundId = MediaStream & { inboundId?: string };
1498
+
1489
1499
  type ClientState = {
1490
1500
  hasAcceptedWebcamStream: Boolean;
1491
1501
  hasAcceptedScreenStream: Boolean;
1492
1502
  hasEmittedWebcamStream: Boolean;
1493
1503
  hasEmittedScreenStream: Boolean;
1494
- webcamStream?: MediaSteamWhichMayHaveInboundId;
1495
- screenStream?: MediaSteamWhichMayHaveInboundId;
1504
+ webcamStream?: MediaStreamWhichMayHaveInboundId;
1505
+ screenStream?: MediaStreamWhichMayHaveInboundId;
1496
1506
  screenShareStreamId?: string;
1497
1507
  camStreamId?: string;
1498
1508
  };
1509
+
1499
1510
  declare class VegaRtcManager implements RtcManager {
1500
1511
  _selfId: any;
1501
1512
  _room: any;
@@ -1505,7 +1516,7 @@ declare class VegaRtcManager implements RtcManager {
1505
1516
  _webrtcProvider: any;
1506
1517
  _features: any;
1507
1518
  _eventClaim?: any;
1508
- _vegaConnection: any;
1519
+ _vegaConnection: VegaConnection | null;
1509
1520
  _micAnalyser: any;
1510
1521
  _micAnalyserDebugger: any;
1511
1522
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1559,6 +1570,7 @@ declare class VegaRtcManager implements RtcManager {
1559
1570
  _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1560
1571
  _networkIsDetectedUpBySignal: boolean;
1561
1572
  _cpuOveruseDetected: boolean;
1573
+ analytics: VegaAnalytics;
1562
1574
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1563
1575
  selfId: any;
1564
1576
  room: any;
@@ -1584,7 +1596,7 @@ declare class VegaRtcManager implements RtcManager {
1584
1596
  _onClose(): void;
1585
1597
  _join(): Promise<void>;
1586
1598
  _createTransport(send: any): Promise<void>;
1587
- _restartIce(transport: any, retried?: number): Promise<void>;
1599
+ _restartIce(direction: VegaTransportDirection, transportId: string, retried?: number): Promise<void>;
1588
1600
  _internalSendMic(): Promise<void>;
1589
1601
  _internalSetupMicScore(): Promise<void>;
1590
1602
  _stopMicScoreProducer(): void;
package/dist/index.d.mts CHANGED
@@ -1483,19 +1483,30 @@ declare function createVegaConnectionManager(config: {
1483
1483
  networkIsPossiblyDown: () => void;
1484
1484
  };
1485
1485
 
1486
- type MediaSteamWhichMayHaveInboundId = MediaStream & {
1487
- inboundId?: string;
1486
+ type VegaTransportDirection = "send" | "recv";
1487
+
1488
+ type VegaAnalytics = {
1489
+ vegaJoinFailed: number;
1490
+ vegaJoinWithoutVegaConnection: number;
1491
+ vegaCreateTransportWithoutVegaConnection: number;
1492
+ vegaIceRestarts: number;
1493
+ vegaIceRestartMissingTransport: number;
1494
+ vegaIceRestartWrongTransportId: number;
1488
1495
  };
1496
+
1497
+ type MediaStreamWhichMayHaveInboundId = MediaStream & { inboundId?: string };
1498
+
1489
1499
  type ClientState = {
1490
1500
  hasAcceptedWebcamStream: Boolean;
1491
1501
  hasAcceptedScreenStream: Boolean;
1492
1502
  hasEmittedWebcamStream: Boolean;
1493
1503
  hasEmittedScreenStream: Boolean;
1494
- webcamStream?: MediaSteamWhichMayHaveInboundId;
1495
- screenStream?: MediaSteamWhichMayHaveInboundId;
1504
+ webcamStream?: MediaStreamWhichMayHaveInboundId;
1505
+ screenStream?: MediaStreamWhichMayHaveInboundId;
1496
1506
  screenShareStreamId?: string;
1497
1507
  camStreamId?: string;
1498
1508
  };
1509
+
1499
1510
  declare class VegaRtcManager implements RtcManager {
1500
1511
  _selfId: any;
1501
1512
  _room: any;
@@ -1505,7 +1516,7 @@ declare class VegaRtcManager implements RtcManager {
1505
1516
  _webrtcProvider: any;
1506
1517
  _features: any;
1507
1518
  _eventClaim?: any;
1508
- _vegaConnection: any;
1519
+ _vegaConnection: VegaConnection | null;
1509
1520
  _micAnalyser: any;
1510
1521
  _micAnalyserDebugger: any;
1511
1522
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1559,6 +1570,7 @@ declare class VegaRtcManager implements RtcManager {
1559
1570
  _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1560
1571
  _networkIsDetectedUpBySignal: boolean;
1561
1572
  _cpuOveruseDetected: boolean;
1573
+ analytics: VegaAnalytics;
1562
1574
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1563
1575
  selfId: any;
1564
1576
  room: any;
@@ -1584,7 +1596,7 @@ declare class VegaRtcManager implements RtcManager {
1584
1596
  _onClose(): void;
1585
1597
  _join(): Promise<void>;
1586
1598
  _createTransport(send: any): Promise<void>;
1587
- _restartIce(transport: any, retried?: number): Promise<void>;
1599
+ _restartIce(direction: VegaTransportDirection, transportId: string, retried?: number): Promise<void>;
1588
1600
  _internalSendMic(): Promise<void>;
1589
1601
  _internalSetupMicScore(): Promise<void>;
1590
1602
  _stopMicScoreProducer(): void;
package/dist/index.d.ts CHANGED
@@ -1483,19 +1483,30 @@ declare function createVegaConnectionManager(config: {
1483
1483
  networkIsPossiblyDown: () => void;
1484
1484
  };
1485
1485
 
1486
- type MediaSteamWhichMayHaveInboundId = MediaStream & {
1487
- inboundId?: string;
1486
+ type VegaTransportDirection = "send" | "recv";
1487
+
1488
+ type VegaAnalytics = {
1489
+ vegaJoinFailed: number;
1490
+ vegaJoinWithoutVegaConnection: number;
1491
+ vegaCreateTransportWithoutVegaConnection: number;
1492
+ vegaIceRestarts: number;
1493
+ vegaIceRestartMissingTransport: number;
1494
+ vegaIceRestartWrongTransportId: number;
1488
1495
  };
1496
+
1497
+ type MediaStreamWhichMayHaveInboundId = MediaStream & { inboundId?: string };
1498
+
1489
1499
  type ClientState = {
1490
1500
  hasAcceptedWebcamStream: Boolean;
1491
1501
  hasAcceptedScreenStream: Boolean;
1492
1502
  hasEmittedWebcamStream: Boolean;
1493
1503
  hasEmittedScreenStream: Boolean;
1494
- webcamStream?: MediaSteamWhichMayHaveInboundId;
1495
- screenStream?: MediaSteamWhichMayHaveInboundId;
1504
+ webcamStream?: MediaStreamWhichMayHaveInboundId;
1505
+ screenStream?: MediaStreamWhichMayHaveInboundId;
1496
1506
  screenShareStreamId?: string;
1497
1507
  camStreamId?: string;
1498
1508
  };
1509
+
1499
1510
  declare class VegaRtcManager implements RtcManager {
1500
1511
  _selfId: any;
1501
1512
  _room: any;
@@ -1505,7 +1516,7 @@ declare class VegaRtcManager implements RtcManager {
1505
1516
  _webrtcProvider: any;
1506
1517
  _features: any;
1507
1518
  _eventClaim?: any;
1508
- _vegaConnection: any;
1519
+ _vegaConnection: VegaConnection | null;
1509
1520
  _micAnalyser: any;
1510
1521
  _micAnalyserDebugger: any;
1511
1522
  _mediasoupDeviceInitializedAsync: Promise<Device | null>;
@@ -1559,6 +1570,7 @@ declare class VegaRtcManager implements RtcManager {
1559
1570
  _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1560
1571
  _networkIsDetectedUpBySignal: boolean;
1561
1572
  _cpuOveruseDetected: boolean;
1573
+ analytics: VegaAnalytics;
1562
1574
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1563
1575
  selfId: any;
1564
1576
  room: any;
@@ -1584,7 +1596,7 @@ declare class VegaRtcManager implements RtcManager {
1584
1596
  _onClose(): void;
1585
1597
  _join(): Promise<void>;
1586
1598
  _createTransport(send: any): Promise<void>;
1587
- _restartIce(transport: any, retried?: number): Promise<void>;
1599
+ _restartIce(direction: VegaTransportDirection, transportId: string, retried?: number): Promise<void>;
1588
1600
  _internalSendMic(): Promise<void>;
1589
1601
  _internalSetupMicScore(): Promise<void>;
1590
1602
  _stopMicScoreProducer(): void;
package/dist/index.mjs CHANGED
@@ -4527,6 +4527,14 @@ class VegaRtcManager {
4527
4527
  });
4528
4528
  this._networkIsDetectedUpBySignal = false;
4529
4529
  this._cpuOveruseDetected = false;
4530
+ this.analytics = {
4531
+ vegaJoinFailed: 0,
4532
+ vegaJoinWithoutVegaConnection: 0,
4533
+ vegaCreateTransportWithoutVegaConnection: 0,
4534
+ vegaIceRestarts: 0,
4535
+ vegaIceRestartMissingTransport: 0,
4536
+ vegaIceRestartWrongTransportId: 0,
4537
+ };
4530
4538
  }
4531
4539
  _updateAndScheduleMediaServersRefresh({ iceServers, turnServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }) {
4532
4540
  var _a, _b, _c;
@@ -4549,8 +4557,10 @@ class VegaRtcManager {
4549
4557
  iceServers: this._features.turnServersOn ? this._turnServers : this._iceServers,
4550
4558
  };
4551
4559
  iceServersList.iceServers = turnServerOverride(iceServersList.iceServers, this._features.turnServerOverrideHost);
4552
- (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4553
- (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4560
+ if (browserName !== "firefox") {
4561
+ (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4562
+ (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4563
+ }
4554
4564
  this._clearMediaServersRefresh();
4555
4565
  if (!mediaserverConfigTtlSeconds) {
4556
4566
  return;
@@ -4668,10 +4678,16 @@ class VegaRtcManager {
4668
4678
  _join() {
4669
4679
  return __awaiter(this, void 0, void 0, function* () {
4670
4680
  var _a, _b;
4671
- logger$2.info("join()");
4681
+ logger$2.info("_join()");
4672
4682
  this._emitToPWA(rtcManagerEvents.SFU_CONNECTION_OPEN);
4673
4683
  try {
4674
- const { routerRtpCapabilities } = yield this._vegaConnection.request("getCapabilities");
4684
+ if (!this._vegaConnection) {
4685
+ logger$2.error("_join() No VegaConnection found");
4686
+ this.analytics.vegaJoinWithoutVegaConnection++;
4687
+ rtcStats.sendEvent("JoinWithoutVegaConnection", {});
4688
+ throw new Error("No VegaConnection found");
4689
+ }
4690
+ const { routerRtpCapabilities } = (yield this._vegaConnection.request("getCapabilities"));
4675
4691
  if (!this._routerRtpCapabilities) {
4676
4692
  const modifiedCapabilities = modifyMediaCapabilities(routerRtpCapabilities, Object.assign(Object.assign({}, this._features), { vp9On: this._features.sfuVp9On }));
4677
4693
  this._routerRtpCapabilities = modifiedCapabilities;
@@ -4696,14 +4712,22 @@ class VegaRtcManager {
4696
4712
  }
4697
4713
  catch (error) {
4698
4714
  logger$2.error("_join() [error:%o]", error);
4715
+ this.analytics.vegaJoinFailed++;
4716
+ rtcStats.sendEvent("VegaJoinFailed", { error });
4699
4717
  }
4700
4718
  });
4701
4719
  }
4702
4720
  _createTransport(send) {
4703
4721
  return __awaiter(this, void 0, void 0, function* () {
4704
4722
  var _a;
4723
+ if (!this._vegaConnection) {
4724
+ logger$2.error("_createTransport() No VegaConnection found");
4725
+ this.analytics.vegaCreateTransportWithoutVegaConnection++;
4726
+ rtcStats.sendEvent("CreateTransportWithoutVegaConnection", {});
4727
+ throw new Error("No VegaConnection found");
4728
+ }
4705
4729
  const creator = send ? "createSendTransport" : "createRecvTransport";
4706
- const transportOptions = yield this._vegaConnection.request("createTransport", {
4730
+ const optionsFromSfu = (yield this._vegaConnection.request("createTransport", {
4707
4731
  producing: send,
4708
4732
  consuming: !send,
4709
4733
  enableTcp: true,
@@ -4718,7 +4742,8 @@ class VegaRtcManager {
4718
4742
  maxSctpMessageSize: 262144,
4719
4743
  sctpSendBufferSize: 262144,
4720
4744
  },
4721
- });
4745
+ }));
4746
+ const transportOptions = Object.assign({}, optionsFromSfu);
4722
4747
  transportOptions.iceServers = turnServerOverride(this._features.turnServersOn ? this._turnServers : this._iceServers, this._features.turnServerOverrideHost);
4723
4748
  maybeTurnOnly(transportOptions, this._features);
4724
4749
  const transport = (_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
@@ -4728,18 +4753,22 @@ class VegaRtcManager {
4728
4753
  return;
4729
4754
  }
4730
4755
  if (send) {
4731
- if (this._sndTransportIceRestartPromise) {
4756
+ if (this._sndTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4732
4757
  return;
4733
4758
  }
4734
- this._sndTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4759
+ this._sndTransportIceRestartPromise = this._restartIce("send", transport.id)
4760
+ .catch((e) => logger$2.error(e))
4761
+ .finally(() => {
4735
4762
  this._sndTransportIceRestartPromise = null;
4736
4763
  });
4737
4764
  }
4738
4765
  else {
4739
- if (this._rcvTransportIceRestartPromise) {
4766
+ if (this._rcvTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4740
4767
  return;
4741
4768
  }
4742
- this._rcvTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4769
+ this._rcvTransportIceRestartPromise = this._restartIce("recv", transport.id)
4770
+ .catch((e) => logger$2.error(e))
4771
+ .finally(() => {
4743
4772
  this._rcvTransportIceRestartPromise = null;
4744
4773
  });
4745
4774
  }
@@ -4760,13 +4789,13 @@ class VegaRtcManager {
4760
4789
  var _b;
4761
4790
  try {
4762
4791
  const { paused } = appData;
4763
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4792
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4764
4793
  transportId: transport.id,
4765
4794
  kind,
4766
4795
  rtpParameters,
4767
4796
  paused,
4768
4797
  appData,
4769
- }));
4798
+ })));
4770
4799
  callback({ id });
4771
4800
  }
4772
4801
  catch (error) {
@@ -4776,11 +4805,11 @@ class VegaRtcManager {
4776
4805
  transport === null || transport === void 0 ? void 0 : transport.on("producedata", (_a, callback_1, errback_1) => __awaiter(this, [_a, callback_1, errback_1], void 0, function* ({ appData, sctpStreamParameters, }, callback, errback) {
4777
4806
  var _b;
4778
4807
  try {
4779
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4808
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4780
4809
  transportId: transport.id,
4781
4810
  sctpStreamParameters,
4782
4811
  appData,
4783
- }));
4812
+ })));
4784
4813
  callback({ id });
4785
4814
  }
4786
4815
  catch (error) {
@@ -4794,10 +4823,22 @@ class VegaRtcManager {
4794
4823
  }
4795
4824
  });
4796
4825
  }
4797
- _restartIce(transport_1) {
4798
- return __awaiter(this, arguments, void 0, function* (transport, retried = 0) {
4799
- if (!transport || !("closed" in transport) || !("connectionState" in transport)) {
4800
- logger$2.info("_restartIce: No transport or property closed or connectionState!");
4826
+ _restartIce(direction_1, transportId_1) {
4827
+ return __awaiter(this, arguments, void 0, function* (direction, transportId, retried = 0) {
4828
+ this.analytics.vegaIceRestarts++;
4829
+ const transport = direction === "send" ? this._sendTransport : this._receiveTransport;
4830
+ if (!transport) {
4831
+ logger$2.info(`_restartIce: No transport found with id ${transportId}`);
4832
+ this.analytics.vegaIceRestartMissingTransport++;
4833
+ return;
4834
+ }
4835
+ if (transport.id !== transportId) {
4836
+ logger$2.info(`_restartIce: Transport ids does not match [expected: ${transportId}, actual: ${transport.id}]`);
4837
+ this.analytics.vegaIceRestartWrongTransportId++;
4838
+ return;
4839
+ }
4840
+ if (!("closed" in transport) || !("connectionState" in transport)) {
4841
+ logger$2.info("_restartIce: Transport is missing closed or connectionState property");
4801
4842
  return;
4802
4843
  }
4803
4844
  if (transport.closed) {
@@ -4822,7 +4863,9 @@ class VegaRtcManager {
4822
4863
  logger$2.info(`_restartIce: Connection is undefined`);
4823
4864
  return;
4824
4865
  }
4825
- const { iceParameters } = yield this._vegaConnection.request("restartIce", { transportId: transport.id });
4866
+ const { iceParameters } = (yield this._vegaConnection.request("restartIce", {
4867
+ transportId: transport.id,
4868
+ }));
4826
4869
  logger$2.info("_restartIce: ICE restart iceParameters received from SFU: ", iceParameters);
4827
4870
  const error = yield transport
4828
4871
  .restartIce({ iceParameters })
@@ -4840,7 +4883,7 @@ class VegaRtcManager {
4840
4883
  resolve(undefined);
4841
4884
  }, Math.min(RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS * Math.pow(2, retried), 60000));
4842
4885
  });
4843
- yield this._restartIce(transport, retried + 1);
4886
+ yield this._restartIce(direction, transportId, retried + 1);
4844
4887
  break;
4845
4888
  }
4846
4889
  return;
@@ -4851,7 +4894,7 @@ class VegaRtcManager {
4851
4894
  }, 60000 * Math.min(8, retried + 1));
4852
4895
  });
4853
4896
  if (transport.connectionState === "failed" || transport.connectionState === "disconnected") {
4854
- yield this._restartIce(transport, retried + 1);
4897
+ yield this._restartIce(direction, transportId, retried + 1);
4855
4898
  return;
4856
4899
  }
4857
4900
  });
@@ -4527,6 +4527,14 @@ class VegaRtcManager {
4527
4527
  });
4528
4528
  this._networkIsDetectedUpBySignal = false;
4529
4529
  this._cpuOveruseDetected = false;
4530
+ this.analytics = {
4531
+ vegaJoinFailed: 0,
4532
+ vegaJoinWithoutVegaConnection: 0,
4533
+ vegaCreateTransportWithoutVegaConnection: 0,
4534
+ vegaIceRestarts: 0,
4535
+ vegaIceRestartMissingTransport: 0,
4536
+ vegaIceRestartWrongTransportId: 0,
4537
+ };
4530
4538
  }
4531
4539
  _updateAndScheduleMediaServersRefresh({ iceServers, turnServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }) {
4532
4540
  var _a, _b, _c;
@@ -4549,8 +4557,10 @@ class VegaRtcManager {
4549
4557
  iceServers: this._features.turnServersOn ? this._turnServers : this._iceServers,
4550
4558
  };
4551
4559
  iceServersList.iceServers = turnServerOverride(iceServersList.iceServers, this._features.turnServerOverrideHost);
4552
- (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4553
- (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4560
+ if (browserName !== "firefox") {
4561
+ (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers(iceServersList);
4562
+ (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers(iceServersList);
4563
+ }
4554
4564
  this._clearMediaServersRefresh();
4555
4565
  if (!mediaserverConfigTtlSeconds) {
4556
4566
  return;
@@ -4668,10 +4678,16 @@ class VegaRtcManager {
4668
4678
  _join() {
4669
4679
  return __awaiter(this, void 0, void 0, function* () {
4670
4680
  var _a, _b;
4671
- logger$2.info("join()");
4681
+ logger$2.info("_join()");
4672
4682
  this._emitToPWA(rtcManagerEvents.SFU_CONNECTION_OPEN);
4673
4683
  try {
4674
- const { routerRtpCapabilities } = yield this._vegaConnection.request("getCapabilities");
4684
+ if (!this._vegaConnection) {
4685
+ logger$2.error("_join() No VegaConnection found");
4686
+ this.analytics.vegaJoinWithoutVegaConnection++;
4687
+ rtcStats.sendEvent("JoinWithoutVegaConnection", {});
4688
+ throw new Error("No VegaConnection found");
4689
+ }
4690
+ const { routerRtpCapabilities } = (yield this._vegaConnection.request("getCapabilities"));
4675
4691
  if (!this._routerRtpCapabilities) {
4676
4692
  const modifiedCapabilities = modifyMediaCapabilities(routerRtpCapabilities, Object.assign(Object.assign({}, this._features), { vp9On: this._features.sfuVp9On }));
4677
4693
  this._routerRtpCapabilities = modifiedCapabilities;
@@ -4696,14 +4712,22 @@ class VegaRtcManager {
4696
4712
  }
4697
4713
  catch (error) {
4698
4714
  logger$2.error("_join() [error:%o]", error);
4715
+ this.analytics.vegaJoinFailed++;
4716
+ rtcStats.sendEvent("VegaJoinFailed", { error });
4699
4717
  }
4700
4718
  });
4701
4719
  }
4702
4720
  _createTransport(send) {
4703
4721
  return __awaiter(this, void 0, void 0, function* () {
4704
4722
  var _a;
4723
+ if (!this._vegaConnection) {
4724
+ logger$2.error("_createTransport() No VegaConnection found");
4725
+ this.analytics.vegaCreateTransportWithoutVegaConnection++;
4726
+ rtcStats.sendEvent("CreateTransportWithoutVegaConnection", {});
4727
+ throw new Error("No VegaConnection found");
4728
+ }
4705
4729
  const creator = send ? "createSendTransport" : "createRecvTransport";
4706
- const transportOptions = yield this._vegaConnection.request("createTransport", {
4730
+ const optionsFromSfu = (yield this._vegaConnection.request("createTransport", {
4707
4731
  producing: send,
4708
4732
  consuming: !send,
4709
4733
  enableTcp: true,
@@ -4718,7 +4742,8 @@ class VegaRtcManager {
4718
4742
  maxSctpMessageSize: 262144,
4719
4743
  sctpSendBufferSize: 262144,
4720
4744
  },
4721
- });
4745
+ }));
4746
+ const transportOptions = Object.assign({}, optionsFromSfu);
4722
4747
  transportOptions.iceServers = turnServerOverride(this._features.turnServersOn ? this._turnServers : this._iceServers, this._features.turnServerOverrideHost);
4723
4748
  maybeTurnOnly(transportOptions, this._features);
4724
4749
  const transport = (_a = (yield this._mediasoupDeviceInitializedAsync)) === null || _a === void 0 ? void 0 : _a[creator](transportOptions);
@@ -4728,18 +4753,22 @@ class VegaRtcManager {
4728
4753
  return;
4729
4754
  }
4730
4755
  if (send) {
4731
- if (this._sndTransportIceRestartPromise) {
4756
+ if (this._sndTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4732
4757
  return;
4733
4758
  }
4734
- this._sndTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4759
+ this._sndTransportIceRestartPromise = this._restartIce("send", transport.id)
4760
+ .catch((e) => logger$2.error(e))
4761
+ .finally(() => {
4735
4762
  this._sndTransportIceRestartPromise = null;
4736
4763
  });
4737
4764
  }
4738
4765
  else {
4739
- if (this._rcvTransportIceRestartPromise) {
4766
+ if (this._rcvTransportIceRestartPromise || !(transport === null || transport === void 0 ? void 0 : transport.id)) {
4740
4767
  return;
4741
4768
  }
4742
- this._rcvTransportIceRestartPromise = this._restartIce(transport).finally(() => {
4769
+ this._rcvTransportIceRestartPromise = this._restartIce("recv", transport.id)
4770
+ .catch((e) => logger$2.error(e))
4771
+ .finally(() => {
4743
4772
  this._rcvTransportIceRestartPromise = null;
4744
4773
  });
4745
4774
  }
@@ -4760,13 +4789,13 @@ class VegaRtcManager {
4760
4789
  var _b;
4761
4790
  try {
4762
4791
  const { paused } = appData;
4763
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4792
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produce", {
4764
4793
  transportId: transport.id,
4765
4794
  kind,
4766
4795
  rtpParameters,
4767
4796
  paused,
4768
4797
  appData,
4769
- }));
4798
+ })));
4770
4799
  callback({ id });
4771
4800
  }
4772
4801
  catch (error) {
@@ -4776,11 +4805,11 @@ class VegaRtcManager {
4776
4805
  transport === null || transport === void 0 ? void 0 : transport.on("producedata", (_a, callback_1, errback_1) => __awaiter(this, [_a, callback_1, errback_1], void 0, function* ({ appData, sctpStreamParameters, }, callback, errback) {
4777
4806
  var _b;
4778
4807
  try {
4779
- const { id } = yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4808
+ const { id } = (yield ((_b = this._vegaConnection) === null || _b === void 0 ? void 0 : _b.request("produceData", {
4780
4809
  transportId: transport.id,
4781
4810
  sctpStreamParameters,
4782
4811
  appData,
4783
- }));
4812
+ })));
4784
4813
  callback({ id });
4785
4814
  }
4786
4815
  catch (error) {
@@ -4794,10 +4823,22 @@ class VegaRtcManager {
4794
4823
  }
4795
4824
  });
4796
4825
  }
4797
- _restartIce(transport_1) {
4798
- return __awaiter(this, arguments, void 0, function* (transport, retried = 0) {
4799
- if (!transport || !("closed" in transport) || !("connectionState" in transport)) {
4800
- logger$2.info("_restartIce: No transport or property closed or connectionState!");
4826
+ _restartIce(direction_1, transportId_1) {
4827
+ return __awaiter(this, arguments, void 0, function* (direction, transportId, retried = 0) {
4828
+ this.analytics.vegaIceRestarts++;
4829
+ const transport = direction === "send" ? this._sendTransport : this._receiveTransport;
4830
+ if (!transport) {
4831
+ logger$2.info(`_restartIce: No transport found with id ${transportId}`);
4832
+ this.analytics.vegaIceRestartMissingTransport++;
4833
+ return;
4834
+ }
4835
+ if (transport.id !== transportId) {
4836
+ logger$2.info(`_restartIce: Transport ids does not match [expected: ${transportId}, actual: ${transport.id}]`);
4837
+ this.analytics.vegaIceRestartWrongTransportId++;
4838
+ return;
4839
+ }
4840
+ if (!("closed" in transport) || !("connectionState" in transport)) {
4841
+ logger$2.info("_restartIce: Transport is missing closed or connectionState property");
4801
4842
  return;
4802
4843
  }
4803
4844
  if (transport.closed) {
@@ -4822,7 +4863,9 @@ class VegaRtcManager {
4822
4863
  logger$2.info(`_restartIce: Connection is undefined`);
4823
4864
  return;
4824
4865
  }
4825
- const { iceParameters } = yield this._vegaConnection.request("restartIce", { transportId: transport.id });
4866
+ const { iceParameters } = (yield this._vegaConnection.request("restartIce", {
4867
+ transportId: transport.id,
4868
+ }));
4826
4869
  logger$2.info("_restartIce: ICE restart iceParameters received from SFU: ", iceParameters);
4827
4870
  const error = yield transport
4828
4871
  .restartIce({ iceParameters })
@@ -4840,7 +4883,7 @@ class VegaRtcManager {
4840
4883
  resolve(undefined);
4841
4884
  }, Math.min(RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS * Math.pow(2, retried), 60000));
4842
4885
  });
4843
- yield this._restartIce(transport, retried + 1);
4886
+ yield this._restartIce(direction, transportId, retried + 1);
4844
4887
  break;
4845
4888
  }
4846
4889
  return;
@@ -4851,7 +4894,7 @@ class VegaRtcManager {
4851
4894
  }, 60000 * Math.min(8, retried + 1));
4852
4895
  });
4853
4896
  if (transport.connectionState === "failed" || transport.connectionState === "disconnected") {
4854
- yield this._restartIce(transport, retried + 1);
4897
+ yield this._restartIce(direction, transportId, retried + 1);
4855
4898
  return;
4856
4899
  }
4857
4900
  });
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": "2.6.1",
4
+ "version": "2.6.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {