@whereby.com/media 2.5.2 → 2.5.4

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.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;
@@ -1547,6 +1549,7 @@ class ServerSocket {
1547
1549
  this._wasConnectedUsingWebsocket = false;
1548
1550
  this._reconnectManager = null;
1549
1551
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1552
+ this.joinRoomFinished = false;
1550
1553
  this._socket.io.on("reconnect", () => {
1551
1554
  this._socket.sendBuffer = [];
1552
1555
  });
@@ -1564,6 +1567,12 @@ class ServerSocket {
1564
1567
  });
1565
1568
  if (glitchFree)
1566
1569
  this._reconnectManager = new ReconnectManager(this._socket);
1570
+ this._socket.on("room_joined", (payload) => {
1571
+ const { error } = payload;
1572
+ if (!error) {
1573
+ this.joinRoomFinished = true;
1574
+ }
1575
+ });
1567
1576
  this._socket.on("connect", () => {
1568
1577
  const transport = this.getTransport();
1569
1578
  if (transport === "websocket") {
@@ -1580,6 +1589,7 @@ class ServerSocket {
1580
1589
  }
1581
1590
  });
1582
1591
  this._socket.on("disconnect", () => {
1592
+ this.joinRoomFinished = false;
1583
1593
  this.disconnectTimestamp = Date.now();
1584
1594
  if (this.noopKeepaliveInterval) {
1585
1595
  clearInterval(this.noopKeepaliveInterval);
@@ -1601,26 +1611,12 @@ class ServerSocket {
1601
1611
  disconnect() {
1602
1612
  this._socket.disconnect();
1603
1613
  }
1604
- disconnectOnConnect() {
1605
- this._socket.once("connect", () => {
1606
- this._socket.disconnect();
1607
- });
1608
- }
1609
1614
  emit(eventName, ...args) {
1610
1615
  this._socket.emit.apply(this._socket, arguments);
1611
1616
  }
1612
- emitIfConnected(eventName, data) {
1613
- if (!this.isConnected()) {
1614
- return;
1615
- }
1616
- this.emit(eventName, data);
1617
- }
1618
1617
  getTransport() {
1619
- return (this._socket &&
1620
- this._socket.io &&
1621
- this._socket.io.engine &&
1622
- this._socket.io.engine.transport &&
1623
- this._socket.io.engine.transport.name);
1618
+ var _a, _b, _c, _d;
1619
+ return (_d = (_c = (_b = (_a = this._socket) === null || _a === void 0 ? void 0 : _a.io) === null || _b === void 0 ? void 0 : _b.engine) === null || _c === void 0 ? void 0 : _c.transport) === null || _d === void 0 ? void 0 : _d.name;
1624
1620
  }
1625
1621
  getManager() {
1626
1622
  return this._socket.io;
@@ -2582,6 +2578,8 @@ class P2pRtcManager {
2582
2578
  this._webrtcProvider = webrtcProvider;
2583
2579
  this._features = features || {};
2584
2580
  this._isAudioOnlyMode = false;
2581
+ this._closed = false;
2582
+ this.skipEmittingServerMessageCount = 0;
2585
2583
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
2586
2584
  this._pendingActionsForConnectedPeerConnections = [];
2587
2585
  this._audioTrackOnEnded = () => {
@@ -2663,6 +2661,10 @@ class P2pRtcManager {
2663
2661
  }
2664
2662
  return this._replaceTrackToPeerConnections(oldTrack, newTrack);
2665
2663
  }
2664
+ close() {
2665
+ this._closed = true;
2666
+ this.disconnectAll();
2667
+ }
2666
2668
  disconnectAll() {
2667
2669
  Object.keys(this.peerConnections).forEach((peerConnectionId) => {
2668
2670
  this.disconnect(peerConnectionId);
@@ -2788,11 +2790,16 @@ class P2pRtcManager {
2788
2790
  sendStatsCustomEvent(eventName, data) {
2789
2791
  rtcStats.sendEvent(eventName, data);
2790
2792
  }
2793
+ rtcStatsConnect() {
2794
+ if (!rtcStats.server.connected) {
2795
+ rtcStats.server.connect();
2796
+ }
2797
+ }
2791
2798
  rtcStatsDisconnect() {
2792
2799
  rtcStats.server.close();
2793
2800
  }
2794
2801
  rtcStatsReconnect() {
2795
- if (!rtcStats.server.connected) {
2802
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
2796
2803
  rtcStats.server.connect();
2797
2804
  }
2798
2805
  }
@@ -2848,8 +2855,18 @@ class P2pRtcManager {
2848
2855
  logger$6.error("Error during setting jitter buffer target:", error);
2849
2856
  }
2850
2857
  }
2851
- _emitServerEvent(eventName, data, callback) {
2852
- this._serverSocket.emit(eventName, data, callback);
2858
+ _emitServerEvent(eventName, data) {
2859
+ if (this._closed) {
2860
+ logger$6.warn("RtcManager closed. Will not send event", eventName, data);
2861
+ return;
2862
+ }
2863
+ if (this._features.awaitJoinRoomFinished && !this._serverSocket.joinRoomFinished) {
2864
+ rtcStats.sendEvent("skip_emitting_server_message", { eventName });
2865
+ this.skipEmittingServerMessageCount++;
2866
+ }
2867
+ else {
2868
+ this._serverSocket.emit(eventName, data);
2869
+ }
2853
2870
  }
2854
2871
  _emit(eventName, data) {
2855
2872
  this._emitter.emit(eventName, data);
@@ -3172,6 +3189,10 @@ class P2pRtcManager {
3172
3189
  this._videoTrackBeingMonitored = track;
3173
3190
  }
3174
3191
  _connect(clientId) {
3192
+ try {
3193
+ this.rtcStatsReconnect();
3194
+ }
3195
+ catch (_) { }
3175
3196
  let session = this._getSession(clientId);
3176
3197
  let initialBandwidth = (session && session.bandwidth) || 0;
3177
3198
  if (session) {
@@ -5485,6 +5506,9 @@ class VegaRtcManager {
5485
5506
  });
5486
5507
  }
5487
5508
  }
5509
+ close() {
5510
+ this.disconnectAll();
5511
+ }
5488
5512
  disconnectAll() {
5489
5513
  var _a, _b, _c, _d;
5490
5514
  this._reconnect = false;
@@ -5520,11 +5544,16 @@ class VegaRtcManager {
5520
5544
  sendStatsCustomEvent(eventName, data) {
5521
5545
  rtcStats.sendEvent(eventName, data);
5522
5546
  }
5547
+ rtcStatsConnect() {
5548
+ if (!rtcStats.server.connected) {
5549
+ rtcStats.server.connect();
5550
+ }
5551
+ }
5523
5552
  rtcStatsDisconnect() {
5524
5553
  rtcStats.server.close();
5525
5554
  }
5526
5555
  rtcStatsReconnect() {
5527
- if (!rtcStats.server.connected) {
5556
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
5528
5557
  rtcStats.server.connect();
5529
5558
  }
5530
5559
  }
@@ -5850,7 +5879,7 @@ class RtcManagerDispatcher {
5850
5879
  else {
5851
5880
  rtcManager = new P2pRtcManager(config);
5852
5881
  }
5853
- rtcManager.rtcStatsReconnect();
5882
+ rtcManager.rtcStatsConnect();
5854
5883
  rtcManager.setupSocketListeners();
5855
5884
  emitter.emit(EVENTS.RTC_MANAGER_CREATED, { rtcManager });
5856
5885
  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;
@@ -1547,6 +1549,7 @@ class ServerSocket {
1547
1549
  this._wasConnectedUsingWebsocket = false;
1548
1550
  this._reconnectManager = null;
1549
1551
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1552
+ this.joinRoomFinished = false;
1550
1553
  this._socket.io.on("reconnect", () => {
1551
1554
  this._socket.sendBuffer = [];
1552
1555
  });
@@ -1564,6 +1567,12 @@ class ServerSocket {
1564
1567
  });
1565
1568
  if (glitchFree)
1566
1569
  this._reconnectManager = new ReconnectManager(this._socket);
1570
+ this._socket.on("room_joined", (payload) => {
1571
+ const { error } = payload;
1572
+ if (!error) {
1573
+ this.joinRoomFinished = true;
1574
+ }
1575
+ });
1567
1576
  this._socket.on("connect", () => {
1568
1577
  const transport = this.getTransport();
1569
1578
  if (transport === "websocket") {
@@ -1580,6 +1589,7 @@ class ServerSocket {
1580
1589
  }
1581
1590
  });
1582
1591
  this._socket.on("disconnect", () => {
1592
+ this.joinRoomFinished = false;
1583
1593
  this.disconnectTimestamp = Date.now();
1584
1594
  if (this.noopKeepaliveInterval) {
1585
1595
  clearInterval(this.noopKeepaliveInterval);
@@ -1601,26 +1611,12 @@ class ServerSocket {
1601
1611
  disconnect() {
1602
1612
  this._socket.disconnect();
1603
1613
  }
1604
- disconnectOnConnect() {
1605
- this._socket.once("connect", () => {
1606
- this._socket.disconnect();
1607
- });
1608
- }
1609
1614
  emit(eventName, ...args) {
1610
1615
  this._socket.emit.apply(this._socket, arguments);
1611
1616
  }
1612
- emitIfConnected(eventName, data) {
1613
- if (!this.isConnected()) {
1614
- return;
1615
- }
1616
- this.emit(eventName, data);
1617
- }
1618
1617
  getTransport() {
1619
- return (this._socket &&
1620
- this._socket.io &&
1621
- this._socket.io.engine &&
1622
- this._socket.io.engine.transport &&
1623
- this._socket.io.engine.transport.name);
1618
+ var _a, _b, _c, _d;
1619
+ return (_d = (_c = (_b = (_a = this._socket) === null || _a === void 0 ? void 0 : _a.io) === null || _b === void 0 ? void 0 : _b.engine) === null || _c === void 0 ? void 0 : _c.transport) === null || _d === void 0 ? void 0 : _d.name;
1624
1620
  }
1625
1621
  getManager() {
1626
1622
  return this._socket.io;
@@ -2582,6 +2578,8 @@ class P2pRtcManager {
2582
2578
  this._webrtcProvider = webrtcProvider;
2583
2579
  this._features = features || {};
2584
2580
  this._isAudioOnlyMode = false;
2581
+ this._closed = false;
2582
+ this.skipEmittingServerMessageCount = 0;
2585
2583
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
2586
2584
  this._pendingActionsForConnectedPeerConnections = [];
2587
2585
  this._audioTrackOnEnded = () => {
@@ -2663,6 +2661,10 @@ class P2pRtcManager {
2663
2661
  }
2664
2662
  return this._replaceTrackToPeerConnections(oldTrack, newTrack);
2665
2663
  }
2664
+ close() {
2665
+ this._closed = true;
2666
+ this.disconnectAll();
2667
+ }
2666
2668
  disconnectAll() {
2667
2669
  Object.keys(this.peerConnections).forEach((peerConnectionId) => {
2668
2670
  this.disconnect(peerConnectionId);
@@ -2788,11 +2790,16 @@ class P2pRtcManager {
2788
2790
  sendStatsCustomEvent(eventName, data) {
2789
2791
  rtcStats.sendEvent(eventName, data);
2790
2792
  }
2793
+ rtcStatsConnect() {
2794
+ if (!rtcStats.server.connected) {
2795
+ rtcStats.server.connect();
2796
+ }
2797
+ }
2791
2798
  rtcStatsDisconnect() {
2792
2799
  rtcStats.server.close();
2793
2800
  }
2794
2801
  rtcStatsReconnect() {
2795
- if (!rtcStats.server.connected) {
2802
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
2796
2803
  rtcStats.server.connect();
2797
2804
  }
2798
2805
  }
@@ -2848,8 +2855,18 @@ class P2pRtcManager {
2848
2855
  logger$6.error("Error during setting jitter buffer target:", error);
2849
2856
  }
2850
2857
  }
2851
- _emitServerEvent(eventName, data, callback) {
2852
- this._serverSocket.emit(eventName, data, callback);
2858
+ _emitServerEvent(eventName, data) {
2859
+ if (this._closed) {
2860
+ logger$6.warn("RtcManager closed. Will not send event", eventName, data);
2861
+ return;
2862
+ }
2863
+ if (this._features.awaitJoinRoomFinished && !this._serverSocket.joinRoomFinished) {
2864
+ rtcStats.sendEvent("skip_emitting_server_message", { eventName });
2865
+ this.skipEmittingServerMessageCount++;
2866
+ }
2867
+ else {
2868
+ this._serverSocket.emit(eventName, data);
2869
+ }
2853
2870
  }
2854
2871
  _emit(eventName, data) {
2855
2872
  this._emitter.emit(eventName, data);
@@ -3172,6 +3189,10 @@ class P2pRtcManager {
3172
3189
  this._videoTrackBeingMonitored = track;
3173
3190
  }
3174
3191
  _connect(clientId) {
3192
+ try {
3193
+ this.rtcStatsReconnect();
3194
+ }
3195
+ catch (_) { }
3175
3196
  let session = this._getSession(clientId);
3176
3197
  let initialBandwidth = (session && session.bandwidth) || 0;
3177
3198
  if (session) {
@@ -5485,6 +5506,9 @@ class VegaRtcManager {
5485
5506
  });
5486
5507
  }
5487
5508
  }
5509
+ close() {
5510
+ this.disconnectAll();
5511
+ }
5488
5512
  disconnectAll() {
5489
5513
  var _a, _b, _c, _d;
5490
5514
  this._reconnect = false;
@@ -5520,11 +5544,16 @@ class VegaRtcManager {
5520
5544
  sendStatsCustomEvent(eventName, data) {
5521
5545
  rtcStats.sendEvent(eventName, data);
5522
5546
  }
5547
+ rtcStatsConnect() {
5548
+ if (!rtcStats.server.connected) {
5549
+ rtcStats.server.connect();
5550
+ }
5551
+ }
5523
5552
  rtcStatsDisconnect() {
5524
5553
  rtcStats.server.close();
5525
5554
  }
5526
5555
  rtcStatsReconnect() {
5527
- if (!rtcStats.server.connected) {
5556
+ if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
5528
5557
  rtcStats.server.connect();
5529
5558
  }
5530
5559
  }
@@ -5850,7 +5879,7 @@ class RtcManagerDispatcher {
5850
5879
  else {
5851
5880
  rtcManager = new P2pRtcManager(config);
5852
5881
  }
5853
- rtcManager.rtcStatsReconnect();
5882
+ rtcManager.rtcStatsConnect();
5854
5883
  rtcManager.setupSocketListeners();
5855
5884
  emitter.emit(EVENTS.RTC_MANAGER_CREATED, { rtcManager });
5856
5885
  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.2",
4
+ "version": "2.5.4",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {