@whereby.com/media 2.5.3 → 2.5.5

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
@@ -640,6 +640,7 @@ function rtcStatsConnection(wsURL, logger = console) {
640
640
  let featureFlags;
641
641
  const connection = {
642
642
  connected: false,
643
+ attemptedConnectedAtLeastOnce: false,
643
644
  trace: (...args) => {
644
645
  args.push(Date.now());
645
646
  if (args[0] === "customEvent" && args[2].type === "roomSessionId") {
@@ -712,6 +713,7 @@ function rtcStatsConnection(wsURL, logger = console) {
712
713
  connectionAttempt += 1;
713
714
  ws === null || ws === void 0 ? void 0 : ws.close();
714
715
  connection.connected = true;
716
+ connection.attemptedConnectedAtLeastOnce = true;
715
717
  ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
716
718
  ws.onerror = (e) => {
717
719
  connection.connected = false;
@@ -1564,16 +1566,28 @@ const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6
1564
1566
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1565
1567
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1566
1568
  class ServerSocket {
1567
- constructor(hostName, optionsOverrides, glitchFree = false) {
1569
+ constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1568
1570
  this._wasConnectedUsingWebsocket = false;
1571
+ this._disconnectDurationLimitOn = disconnectDurationLimitOn;
1572
+ this.disconnectDurationLimitExceeded = false;
1569
1573
  this._reconnectManager = null;
1570
1574
  this._socket = socket_ioClient.io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1571
1575
  this.joinRoomFinished = false;
1572
1576
  this._socket.io.on("reconnect", () => {
1577
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1578
+ this._socket.close();
1579
+ this.disconnectDurationLimitExceeded = true;
1580
+ return;
1581
+ }
1573
1582
  this._socket.sendBuffer = [];
1574
1583
  });
1575
1584
  this._socket.io.on("reconnect_attempt", () => {
1576
1585
  var _a;
1586
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1587
+ this._socket.close();
1588
+ this.disconnectDurationLimitExceeded = true;
1589
+ return;
1590
+ }
1577
1591
  if (this._wasConnectedUsingWebsocket) {
1578
1592
  this._socket.io.opts.transports = ["websocket"];
1579
1593
  if (((_a = adapter$6.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) !== "safari") {
@@ -1600,6 +1614,9 @@ class ServerSocket {
1600
1614
  this.noopKeepaliveInterval = setInterval(() => {
1601
1615
  try {
1602
1616
  if (this._socket.connected) {
1617
+ if (this._disconnectDurationLimitOn) {
1618
+ this._noopKeepaliveTimestamp = Date.now();
1619
+ }
1603
1620
  this._socket.io.engine.sendPacket("noop");
1604
1621
  }
1605
1622
  }
@@ -1608,6 +1625,11 @@ class ServerSocket {
1608
1625
  }
1609
1626
  });
1610
1627
  this._socket.on("disconnect", () => {
1628
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1629
+ this._socket.close();
1630
+ this.disconnectDurationLimitExceeded = true;
1631
+ return;
1632
+ }
1611
1633
  this.joinRoomFinished = false;
1612
1634
  this.disconnectTimestamp = Date.now();
1613
1635
  if (this.noopKeepaliveInterval) {
@@ -1616,6 +1638,22 @@ class ServerSocket {
1616
1638
  }
1617
1639
  });
1618
1640
  }
1641
+ _didExceedDisconnectDurationLimit() {
1642
+ if (!this._disconnectDurationLimitOn)
1643
+ return false;
1644
+ if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1645
+ const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1646
+ if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1647
+ return true;
1648
+ }
1649
+ return false;
1650
+ }
1651
+ }
1652
+ setDisconnectDurationLimit(limitInMs) {
1653
+ if (this._disconnectDurationLimitOn) {
1654
+ this._disconnectDurationLimitInMs = limitInMs;
1655
+ }
1656
+ }
1619
1657
  setRtcManager(rtcManager) {
1620
1658
  if (this._reconnectManager) {
1621
1659
  this._reconnectManager.rtcManager = rtcManager;
@@ -2809,11 +2847,16 @@ class P2pRtcManager {
2809
2847
  sendStatsCustomEvent(eventName, data) {
2810
2848
  rtcStats.sendEvent(eventName, data);
2811
2849
  }
2850
+ rtcStatsConnect() {
2851
+ if (!rtcStats.server.connected) {
2852
+ rtcStats.server.connect();
2853
+ }
2854
+ }
2812
2855
  rtcStatsDisconnect() {
2813
2856
  rtcStats.server.close();
2814
2857
  }
2815
2858
  rtcStatsReconnect() {
2816
- if (!rtcStats.server.connected) {
2859
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
2817
2860
  rtcStats.server.connect();
2818
2861
  }
2819
2862
  }
@@ -3203,6 +3246,10 @@ class P2pRtcManager {
3203
3246
  this._videoTrackBeingMonitored = track;
3204
3247
  }
3205
3248
  _connect(clientId) {
3249
+ try {
3250
+ this.rtcStatsReconnect();
3251
+ }
3252
+ catch (_) { }
3206
3253
  let session = this._getSession(clientId);
3207
3254
  let initialBandwidth = (session && session.bandwidth) || 0;
3208
3255
  if (session) {
@@ -5554,11 +5601,16 @@ class VegaRtcManager {
5554
5601
  sendStatsCustomEvent(eventName, data) {
5555
5602
  rtcStats.sendEvent(eventName, data);
5556
5603
  }
5604
+ rtcStatsConnect() {
5605
+ if (!rtcStats.server.connected) {
5606
+ rtcStats.server.connect();
5607
+ }
5608
+ }
5557
5609
  rtcStatsDisconnect() {
5558
5610
  rtcStats.server.close();
5559
5611
  }
5560
5612
  rtcStatsReconnect() {
5561
- if (!rtcStats.server.connected) {
5613
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
5562
5614
  rtcStats.server.connect();
5563
5615
  }
5564
5616
  }
@@ -5884,7 +5936,7 @@ class RtcManagerDispatcher {
5884
5936
  else {
5885
5937
  rtcManager = new P2pRtcManager(config);
5886
5938
  }
5887
- rtcManager.rtcStatsReconnect();
5939
+ rtcManager.rtcStatsConnect();
5888
5940
  rtcManager.setupSocketListeners();
5889
5941
  emitter.emit(EVENTS.RTC_MANAGER_CREATED, { rtcManager });
5890
5942
  this.currentManager = rtcManager;
package/dist/index.d.cts CHANGED
@@ -638,10 +638,16 @@ declare class ServerSocket {
638
638
  _socket: any;
639
639
  _reconnectManager?: ReconnectManager | null;
640
640
  noopKeepaliveInterval: any;
641
+ _noopKeepaliveTimestamp: number | undefined;
641
642
  _wasConnectedUsingWebsocket?: boolean;
642
643
  disconnectTimestamp: number | undefined;
644
+ disconnectDurationLimitExceeded: boolean;
643
645
  joinRoomFinished: boolean;
644
- constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
646
+ _disconnectDurationLimitOn: boolean;
647
+ _disconnectDurationLimitInMs: number | undefined;
648
+ constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
649
+ _didExceedDisconnectDurationLimit(): boolean | undefined;
650
+ setDisconnectDurationLimit(limitInMs: number): void;
645
651
  setRtcManager(rtcManager?: RtcManager): void;
646
652
  connect(): void;
647
653
  disconnect(): void;
@@ -1133,6 +1139,7 @@ declare class P2pRtcManager implements RtcManager {
1133
1139
  sendAudioMutedStats(muted: boolean): void;
1134
1140
  sendVideoMutedStats(muted: boolean): void;
1135
1141
  sendStatsCustomEvent(eventName: string, data: any): void;
1142
+ rtcStatsConnect(): void;
1136
1143
  rtcStatsDisconnect(): void;
1137
1144
  rtcStatsReconnect(): void;
1138
1145
  setAudioOnly(audioOnly: any): void;
@@ -1254,6 +1261,7 @@ declare const rtcStats: {
1254
1261
  sendVideoMuted: (muted: boolean) => void;
1255
1262
  server: {
1256
1263
  connected: boolean;
1264
+ attemptedConnectedAtLeastOnce: boolean;
1257
1265
  trace: (...args: any) => void;
1258
1266
  close: () => void;
1259
1267
  connect: () => void;
@@ -1633,6 +1641,7 @@ declare class VegaRtcManager implements RtcManager {
1633
1641
  sendAudioMutedStats(muted: boolean): void;
1634
1642
  sendVideoMutedStats(muted: boolean): void;
1635
1643
  sendStatsCustomEvent(eventName: string, data?: any): void;
1644
+ rtcStatsConnect(): void;
1636
1645
  rtcStatsDisconnect(): void;
1637
1646
  rtcStatsReconnect(): void;
1638
1647
  _monitorAudioTrack(track: any): void;
package/dist/index.d.mts CHANGED
@@ -638,10 +638,16 @@ declare class ServerSocket {
638
638
  _socket: any;
639
639
  _reconnectManager?: ReconnectManager | null;
640
640
  noopKeepaliveInterval: any;
641
+ _noopKeepaliveTimestamp: number | undefined;
641
642
  _wasConnectedUsingWebsocket?: boolean;
642
643
  disconnectTimestamp: number | undefined;
644
+ disconnectDurationLimitExceeded: boolean;
643
645
  joinRoomFinished: boolean;
644
- constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
646
+ _disconnectDurationLimitOn: boolean;
647
+ _disconnectDurationLimitInMs: number | undefined;
648
+ constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
649
+ _didExceedDisconnectDurationLimit(): boolean | undefined;
650
+ setDisconnectDurationLimit(limitInMs: number): void;
645
651
  setRtcManager(rtcManager?: RtcManager): void;
646
652
  connect(): void;
647
653
  disconnect(): void;
@@ -1133,6 +1139,7 @@ declare class P2pRtcManager implements RtcManager {
1133
1139
  sendAudioMutedStats(muted: boolean): void;
1134
1140
  sendVideoMutedStats(muted: boolean): void;
1135
1141
  sendStatsCustomEvent(eventName: string, data: any): void;
1142
+ rtcStatsConnect(): void;
1136
1143
  rtcStatsDisconnect(): void;
1137
1144
  rtcStatsReconnect(): void;
1138
1145
  setAudioOnly(audioOnly: any): void;
@@ -1254,6 +1261,7 @@ declare const rtcStats: {
1254
1261
  sendVideoMuted: (muted: boolean) => void;
1255
1262
  server: {
1256
1263
  connected: boolean;
1264
+ attemptedConnectedAtLeastOnce: boolean;
1257
1265
  trace: (...args: any) => void;
1258
1266
  close: () => void;
1259
1267
  connect: () => void;
@@ -1633,6 +1641,7 @@ declare class VegaRtcManager implements RtcManager {
1633
1641
  sendAudioMutedStats(muted: boolean): void;
1634
1642
  sendVideoMutedStats(muted: boolean): void;
1635
1643
  sendStatsCustomEvent(eventName: string, data?: any): void;
1644
+ rtcStatsConnect(): void;
1636
1645
  rtcStatsDisconnect(): void;
1637
1646
  rtcStatsReconnect(): void;
1638
1647
  _monitorAudioTrack(track: any): void;
package/dist/index.d.ts CHANGED
@@ -638,10 +638,16 @@ declare class ServerSocket {
638
638
  _socket: any;
639
639
  _reconnectManager?: ReconnectManager | null;
640
640
  noopKeepaliveInterval: any;
641
+ _noopKeepaliveTimestamp: number | undefined;
641
642
  _wasConnectedUsingWebsocket?: boolean;
642
643
  disconnectTimestamp: number | undefined;
644
+ disconnectDurationLimitExceeded: boolean;
643
645
  joinRoomFinished: boolean;
644
- constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
646
+ _disconnectDurationLimitOn: boolean;
647
+ _disconnectDurationLimitInMs: number | undefined;
648
+ constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
649
+ _didExceedDisconnectDurationLimit(): boolean | undefined;
650
+ setDisconnectDurationLimit(limitInMs: number): void;
645
651
  setRtcManager(rtcManager?: RtcManager): void;
646
652
  connect(): void;
647
653
  disconnect(): void;
@@ -1133,6 +1139,7 @@ declare class P2pRtcManager implements RtcManager {
1133
1139
  sendAudioMutedStats(muted: boolean): void;
1134
1140
  sendVideoMutedStats(muted: boolean): void;
1135
1141
  sendStatsCustomEvent(eventName: string, data: any): void;
1142
+ rtcStatsConnect(): void;
1136
1143
  rtcStatsDisconnect(): void;
1137
1144
  rtcStatsReconnect(): void;
1138
1145
  setAudioOnly(audioOnly: any): void;
@@ -1254,6 +1261,7 @@ declare const rtcStats: {
1254
1261
  sendVideoMuted: (muted: boolean) => void;
1255
1262
  server: {
1256
1263
  connected: boolean;
1264
+ attemptedConnectedAtLeastOnce: boolean;
1257
1265
  trace: (...args: any) => void;
1258
1266
  close: () => void;
1259
1267
  connect: () => void;
@@ -1633,6 +1641,7 @@ declare class VegaRtcManager implements RtcManager {
1633
1641
  sendAudioMutedStats(muted: boolean): void;
1634
1642
  sendVideoMutedStats(muted: boolean): void;
1635
1643
  sendStatsCustomEvent(eventName: string, data?: any): void;
1644
+ rtcStatsConnect(): void;
1636
1645
  rtcStatsDisconnect(): void;
1637
1646
  rtcStatsReconnect(): void;
1638
1647
  _monitorAudioTrack(track: any): void;
package/dist/index.mjs CHANGED
@@ -619,6 +619,7 @@ function rtcStatsConnection(wsURL, logger = console) {
619
619
  let featureFlags;
620
620
  const connection = {
621
621
  connected: false,
622
+ attemptedConnectedAtLeastOnce: false,
622
623
  trace: (...args) => {
623
624
  args.push(Date.now());
624
625
  if (args[0] === "customEvent" && args[2].type === "roomSessionId") {
@@ -691,6 +692,7 @@ function rtcStatsConnection(wsURL, logger = console) {
691
692
  connectionAttempt += 1;
692
693
  ws === null || ws === void 0 ? void 0 : ws.close();
693
694
  connection.connected = true;
695
+ connection.attemptedConnectedAtLeastOnce = true;
694
696
  ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
695
697
  ws.onerror = (e) => {
696
698
  connection.connected = false;
@@ -1543,16 +1545,28 @@ const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6
1543
1545
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1544
1546
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1545
1547
  class ServerSocket {
1546
- constructor(hostName, optionsOverrides, glitchFree = false) {
1548
+ constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1547
1549
  this._wasConnectedUsingWebsocket = false;
1550
+ this._disconnectDurationLimitOn = disconnectDurationLimitOn;
1551
+ this.disconnectDurationLimitExceeded = false;
1548
1552
  this._reconnectManager = null;
1549
1553
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1550
1554
  this.joinRoomFinished = false;
1551
1555
  this._socket.io.on("reconnect", () => {
1556
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1557
+ this._socket.close();
1558
+ this.disconnectDurationLimitExceeded = true;
1559
+ return;
1560
+ }
1552
1561
  this._socket.sendBuffer = [];
1553
1562
  });
1554
1563
  this._socket.io.on("reconnect_attempt", () => {
1555
1564
  var _a;
1565
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1566
+ this._socket.close();
1567
+ this.disconnectDurationLimitExceeded = true;
1568
+ return;
1569
+ }
1556
1570
  if (this._wasConnectedUsingWebsocket) {
1557
1571
  this._socket.io.opts.transports = ["websocket"];
1558
1572
  if (((_a = adapter$6.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) !== "safari") {
@@ -1579,6 +1593,9 @@ class ServerSocket {
1579
1593
  this.noopKeepaliveInterval = setInterval(() => {
1580
1594
  try {
1581
1595
  if (this._socket.connected) {
1596
+ if (this._disconnectDurationLimitOn) {
1597
+ this._noopKeepaliveTimestamp = Date.now();
1598
+ }
1582
1599
  this._socket.io.engine.sendPacket("noop");
1583
1600
  }
1584
1601
  }
@@ -1587,6 +1604,11 @@ class ServerSocket {
1587
1604
  }
1588
1605
  });
1589
1606
  this._socket.on("disconnect", () => {
1607
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1608
+ this._socket.close();
1609
+ this.disconnectDurationLimitExceeded = true;
1610
+ return;
1611
+ }
1590
1612
  this.joinRoomFinished = false;
1591
1613
  this.disconnectTimestamp = Date.now();
1592
1614
  if (this.noopKeepaliveInterval) {
@@ -1595,6 +1617,22 @@ class ServerSocket {
1595
1617
  }
1596
1618
  });
1597
1619
  }
1620
+ _didExceedDisconnectDurationLimit() {
1621
+ if (!this._disconnectDurationLimitOn)
1622
+ return false;
1623
+ if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1624
+ const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1625
+ if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1626
+ return true;
1627
+ }
1628
+ return false;
1629
+ }
1630
+ }
1631
+ setDisconnectDurationLimit(limitInMs) {
1632
+ if (this._disconnectDurationLimitOn) {
1633
+ this._disconnectDurationLimitInMs = limitInMs;
1634
+ }
1635
+ }
1598
1636
  setRtcManager(rtcManager) {
1599
1637
  if (this._reconnectManager) {
1600
1638
  this._reconnectManager.rtcManager = rtcManager;
@@ -2788,11 +2826,16 @@ class P2pRtcManager {
2788
2826
  sendStatsCustomEvent(eventName, data) {
2789
2827
  rtcStats.sendEvent(eventName, data);
2790
2828
  }
2829
+ rtcStatsConnect() {
2830
+ if (!rtcStats.server.connected) {
2831
+ rtcStats.server.connect();
2832
+ }
2833
+ }
2791
2834
  rtcStatsDisconnect() {
2792
2835
  rtcStats.server.close();
2793
2836
  }
2794
2837
  rtcStatsReconnect() {
2795
- if (!rtcStats.server.connected) {
2838
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
2796
2839
  rtcStats.server.connect();
2797
2840
  }
2798
2841
  }
@@ -3182,6 +3225,10 @@ class P2pRtcManager {
3182
3225
  this._videoTrackBeingMonitored = track;
3183
3226
  }
3184
3227
  _connect(clientId) {
3228
+ try {
3229
+ this.rtcStatsReconnect();
3230
+ }
3231
+ catch (_) { }
3185
3232
  let session = this._getSession(clientId);
3186
3233
  let initialBandwidth = (session && session.bandwidth) || 0;
3187
3234
  if (session) {
@@ -5533,11 +5580,16 @@ class VegaRtcManager {
5533
5580
  sendStatsCustomEvent(eventName, data) {
5534
5581
  rtcStats.sendEvent(eventName, data);
5535
5582
  }
5583
+ rtcStatsConnect() {
5584
+ if (!rtcStats.server.connected) {
5585
+ rtcStats.server.connect();
5586
+ }
5587
+ }
5536
5588
  rtcStatsDisconnect() {
5537
5589
  rtcStats.server.close();
5538
5590
  }
5539
5591
  rtcStatsReconnect() {
5540
- if (!rtcStats.server.connected) {
5592
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
5541
5593
  rtcStats.server.connect();
5542
5594
  }
5543
5595
  }
@@ -5863,7 +5915,7 @@ class RtcManagerDispatcher {
5863
5915
  else {
5864
5916
  rtcManager = new P2pRtcManager(config);
5865
5917
  }
5866
- rtcManager.rtcStatsReconnect();
5918
+ rtcManager.rtcStatsConnect();
5867
5919
  rtcManager.setupSocketListeners();
5868
5920
  emitter.emit(EVENTS.RTC_MANAGER_CREATED, { rtcManager });
5869
5921
  this.currentManager = rtcManager;
@@ -619,6 +619,7 @@ function rtcStatsConnection(wsURL, logger = console) {
619
619
  let featureFlags;
620
620
  const connection = {
621
621
  connected: false,
622
+ attemptedConnectedAtLeastOnce: false,
622
623
  trace: (...args) => {
623
624
  args.push(Date.now());
624
625
  if (args[0] === "customEvent" && args[2].type === "roomSessionId") {
@@ -691,6 +692,7 @@ function rtcStatsConnection(wsURL, logger = console) {
691
692
  connectionAttempt += 1;
692
693
  ws === null || ws === void 0 ? void 0 : ws.close();
693
694
  connection.connected = true;
695
+ connection.attemptedConnectedAtLeastOnce = true;
694
696
  ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);
695
697
  ws.onerror = (e) => {
696
698
  connection.connected = false;
@@ -1543,16 +1545,28 @@ const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6
1543
1545
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1544
1546
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1545
1547
  class ServerSocket {
1546
- constructor(hostName, optionsOverrides, glitchFree = false) {
1548
+ constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1547
1549
  this._wasConnectedUsingWebsocket = false;
1550
+ this._disconnectDurationLimitOn = disconnectDurationLimitOn;
1551
+ this.disconnectDurationLimitExceeded = false;
1548
1552
  this._reconnectManager = null;
1549
1553
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1550
1554
  this.joinRoomFinished = false;
1551
1555
  this._socket.io.on("reconnect", () => {
1556
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1557
+ this._socket.close();
1558
+ this.disconnectDurationLimitExceeded = true;
1559
+ return;
1560
+ }
1552
1561
  this._socket.sendBuffer = [];
1553
1562
  });
1554
1563
  this._socket.io.on("reconnect_attempt", () => {
1555
1564
  var _a;
1565
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1566
+ this._socket.close();
1567
+ this.disconnectDurationLimitExceeded = true;
1568
+ return;
1569
+ }
1556
1570
  if (this._wasConnectedUsingWebsocket) {
1557
1571
  this._socket.io.opts.transports = ["websocket"];
1558
1572
  if (((_a = adapter$6.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) !== "safari") {
@@ -1579,6 +1593,9 @@ class ServerSocket {
1579
1593
  this.noopKeepaliveInterval = setInterval(() => {
1580
1594
  try {
1581
1595
  if (this._socket.connected) {
1596
+ if (this._disconnectDurationLimitOn) {
1597
+ this._noopKeepaliveTimestamp = Date.now();
1598
+ }
1582
1599
  this._socket.io.engine.sendPacket("noop");
1583
1600
  }
1584
1601
  }
@@ -1587,6 +1604,11 @@ class ServerSocket {
1587
1604
  }
1588
1605
  });
1589
1606
  this._socket.on("disconnect", () => {
1607
+ if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1608
+ this._socket.close();
1609
+ this.disconnectDurationLimitExceeded = true;
1610
+ return;
1611
+ }
1590
1612
  this.joinRoomFinished = false;
1591
1613
  this.disconnectTimestamp = Date.now();
1592
1614
  if (this.noopKeepaliveInterval) {
@@ -1595,6 +1617,22 @@ class ServerSocket {
1595
1617
  }
1596
1618
  });
1597
1619
  }
1620
+ _didExceedDisconnectDurationLimit() {
1621
+ if (!this._disconnectDurationLimitOn)
1622
+ return false;
1623
+ if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1624
+ const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1625
+ if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1626
+ return true;
1627
+ }
1628
+ return false;
1629
+ }
1630
+ }
1631
+ setDisconnectDurationLimit(limitInMs) {
1632
+ if (this._disconnectDurationLimitOn) {
1633
+ this._disconnectDurationLimitInMs = limitInMs;
1634
+ }
1635
+ }
1598
1636
  setRtcManager(rtcManager) {
1599
1637
  if (this._reconnectManager) {
1600
1638
  this._reconnectManager.rtcManager = rtcManager;
@@ -2788,11 +2826,16 @@ class P2pRtcManager {
2788
2826
  sendStatsCustomEvent(eventName, data) {
2789
2827
  rtcStats.sendEvent(eventName, data);
2790
2828
  }
2829
+ rtcStatsConnect() {
2830
+ if (!rtcStats.server.connected) {
2831
+ rtcStats.server.connect();
2832
+ }
2833
+ }
2791
2834
  rtcStatsDisconnect() {
2792
2835
  rtcStats.server.close();
2793
2836
  }
2794
2837
  rtcStatsReconnect() {
2795
- if (!rtcStats.server.connected) {
2838
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
2796
2839
  rtcStats.server.connect();
2797
2840
  }
2798
2841
  }
@@ -3182,6 +3225,10 @@ class P2pRtcManager {
3182
3225
  this._videoTrackBeingMonitored = track;
3183
3226
  }
3184
3227
  _connect(clientId) {
3228
+ try {
3229
+ this.rtcStatsReconnect();
3230
+ }
3231
+ catch (_) { }
3185
3232
  let session = this._getSession(clientId);
3186
3233
  let initialBandwidth = (session && session.bandwidth) || 0;
3187
3234
  if (session) {
@@ -5533,11 +5580,16 @@ class VegaRtcManager {
5533
5580
  sendStatsCustomEvent(eventName, data) {
5534
5581
  rtcStats.sendEvent(eventName, data);
5535
5582
  }
5583
+ rtcStatsConnect() {
5584
+ if (!rtcStats.server.connected) {
5585
+ rtcStats.server.connect();
5586
+ }
5587
+ }
5536
5588
  rtcStatsDisconnect() {
5537
5589
  rtcStats.server.close();
5538
5590
  }
5539
5591
  rtcStatsReconnect() {
5540
- if (!rtcStats.server.connected) {
5592
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
5541
5593
  rtcStats.server.connect();
5542
5594
  }
5543
5595
  }
@@ -5863,7 +5915,7 @@ class RtcManagerDispatcher {
5863
5915
  else {
5864
5916
  rtcManager = new P2pRtcManager(config);
5865
5917
  }
5866
- rtcManager.rtcStatsReconnect();
5918
+ rtcManager.rtcStatsConnect();
5867
5919
  rtcManager.setupSocketListeners();
5868
5920
  emitter.emit(EVENTS.RTC_MANAGER_CREATED, { rtcManager });
5869
5921
  this.currentManager = rtcManager;
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.5.3",
4
+ "version": "2.5.5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {
@@ -64,7 +64,7 @@
64
64
  "@whereby.com/eslint-config": "0.1.0",
65
65
  "@whereby.com/jest-config": "0.1.0",
66
66
  "@whereby.com/prettier-config": "0.1.0",
67
- "@whereby.com/rollup-config": "0.1.0",
67
+ "@whereby.com/rollup-config": "0.1.1",
68
68
  "@whereby.com/tsconfig": "0.1.0"
69
69
  },
70
70
  "engines": {