@whereby.com/media 1.12.2 → 1.13.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
@@ -1421,6 +1421,10 @@ class VegaConnection extends EventEmitter.EventEmitter {
1421
1421
  var _a;
1422
1422
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
1423
1423
  }
1424
+ isConnected() {
1425
+ var _a, _b;
1426
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN || ((_b = this.socket) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.CONNECTING;
1427
+ }
1424
1428
  _onOpen() {
1425
1429
  logger$9.info("Connected");
1426
1430
  this.emit("open");
@@ -5119,6 +5123,9 @@ class VegaRtcManager {
5119
5123
  }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5120
5124
  if (this._screenVideoTrack)
5121
5125
  this._emitScreenshareStarted();
5126
+ if (this._features.sfuReconnectV2On && !this._vegaConnection.isConnected() && this._reconnect) {
5127
+ this._connect();
5128
+ }
5122
5129
  }));
5123
5130
  this._connect();
5124
5131
  }
@@ -5129,6 +5136,17 @@ class VegaRtcManager {
5129
5136
  });
5130
5137
  }
5131
5138
  _connect() {
5139
+ if (this._features.sfuReconnectV2On) {
5140
+ if (!this._serverSocket.isConnected()) {
5141
+ const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5142
+ if (!reconnectThresholdInMs)
5143
+ return;
5144
+ if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
5145
+ return;
5146
+ }
5147
+ if (this._reconnectTimeOut)
5148
+ clearTimeout(this._reconnectTimeOut);
5149
+ }
5132
5150
  const host = this._features.sfuServerOverrideHost || [this._sfuServer.url];
5133
5151
  const searchParams = new URLSearchParams(Object.assign({ clientId: this._selfId, organizationId: this._room.organizationId, roomName: this._room.name, eventClaim: this._room.isClaimed ? this._eventClaim : null, lowBw: "true" }, Object.keys(this._features || {})
5134
5152
  .filter((featureKey) => this._features[featureKey] && /^sfu/.test(featureKey))
@@ -6473,6 +6491,7 @@ const logger = new Logger();
6473
6491
  class ReconnectManager extends EventEmitter {
6474
6492
  constructor(socket) {
6475
6493
  super();
6494
+ this.reconnectThresholdInMs = 0;
6476
6495
  this._socket = socket;
6477
6496
  this._clients = {};
6478
6497
  this._signalDisconnectTime = undefined;
@@ -6498,6 +6517,7 @@ class ReconnectManager extends EventEmitter {
6498
6517
  _onRoomJoined(payload) {
6499
6518
  var _a, _b;
6500
6519
  return __awaiter(this, void 0, void 0, function* () {
6520
+ this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
6501
6521
  if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
6502
6522
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
6503
6523
  return;
@@ -6751,6 +6771,7 @@ class ServerSocket {
6751
6771
  }
6752
6772
  });
6753
6773
  this._socket.on("disconnect", () => {
6774
+ this.disconnectTimestamp = Date.now();
6754
6775
  if (this.noopKeepaliveInterval) {
6755
6776
  clearInterval(this.noopKeepaliveInterval);
6756
6777
  this.noopKeepaliveInterval = null;
@@ -6834,6 +6855,10 @@ class ServerSocket {
6834
6855
  var _a;
6835
6856
  return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.metrics;
6836
6857
  }
6858
+ getReconnectThreshold() {
6859
+ var _a;
6860
+ return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.reconnectThresholdInMs;
6861
+ }
6837
6862
  }
6838
6863
 
6839
6864
  const defaultSubdomainPattern = /^(?:([^.]+)[.])?((:?[^.]+[.]){1,}[^.]+)$/;
package/dist/index.d.cts CHANGED
@@ -159,6 +159,7 @@ declare class ReconnectManager extends EventEmitter {
159
159
  evaluationFailed: number;
160
160
  roomJoined: number;
161
161
  };
162
+ reconnectThresholdInMs: number;
162
163
  constructor(socket: any);
163
164
  _onRoomJoined(payload: any): Promise<void>;
164
165
  _onClientLeft(payload: any): void;
@@ -187,6 +188,7 @@ declare class ServerSocket {
187
188
  _reconnectManager?: ReconnectManager | null;
188
189
  noopKeepaliveInterval: any;
189
190
  _wasConnectedUsingWebsocket?: boolean;
191
+ disconnectTimestamp: number | undefined;
190
192
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
191
193
  setRtcManager(rtcManager?: RtcManager): void;
192
194
  connect(): void;
@@ -208,6 +210,7 @@ declare class ServerSocket {
208
210
  evaluationFailed: number;
209
211
  roomJoined: number;
210
212
  } | undefined;
213
+ getReconnectThreshold(): number | undefined;
211
214
  }
212
215
 
213
216
  declare const maybeTurnOnly: (transportConfig: any, features: {
@@ -1008,6 +1011,7 @@ declare class VegaConnection extends EventEmitter$1 {
1008
1011
  _setupSocket(): void;
1009
1012
  _tearDown(): void;
1010
1013
  close(): void;
1014
+ isConnected(): boolean;
1011
1015
  _onOpen(): void;
1012
1016
  _onMessage(event: MessageEvent): void;
1013
1017
  _onClose(): void;
@@ -1083,7 +1087,7 @@ declare class VegaRtcManager implements RtcManager {
1083
1087
  _room: any;
1084
1088
  _roomSessionId: any;
1085
1089
  _emitter: any;
1086
- _serverSocket: any;
1090
+ _serverSocket: ServerSocket;
1087
1091
  _webrtcProvider: any;
1088
1092
  _features: any;
1089
1093
  _eventClaim?: any;
package/dist/index.d.mts CHANGED
@@ -159,6 +159,7 @@ declare class ReconnectManager extends EventEmitter {
159
159
  evaluationFailed: number;
160
160
  roomJoined: number;
161
161
  };
162
+ reconnectThresholdInMs: number;
162
163
  constructor(socket: any);
163
164
  _onRoomJoined(payload: any): Promise<void>;
164
165
  _onClientLeft(payload: any): void;
@@ -187,6 +188,7 @@ declare class ServerSocket {
187
188
  _reconnectManager?: ReconnectManager | null;
188
189
  noopKeepaliveInterval: any;
189
190
  _wasConnectedUsingWebsocket?: boolean;
191
+ disconnectTimestamp: number | undefined;
190
192
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
191
193
  setRtcManager(rtcManager?: RtcManager): void;
192
194
  connect(): void;
@@ -208,6 +210,7 @@ declare class ServerSocket {
208
210
  evaluationFailed: number;
209
211
  roomJoined: number;
210
212
  } | undefined;
213
+ getReconnectThreshold(): number | undefined;
211
214
  }
212
215
 
213
216
  declare const maybeTurnOnly: (transportConfig: any, features: {
@@ -1008,6 +1011,7 @@ declare class VegaConnection extends EventEmitter$1 {
1008
1011
  _setupSocket(): void;
1009
1012
  _tearDown(): void;
1010
1013
  close(): void;
1014
+ isConnected(): boolean;
1011
1015
  _onOpen(): void;
1012
1016
  _onMessage(event: MessageEvent): void;
1013
1017
  _onClose(): void;
@@ -1083,7 +1087,7 @@ declare class VegaRtcManager implements RtcManager {
1083
1087
  _room: any;
1084
1088
  _roomSessionId: any;
1085
1089
  _emitter: any;
1086
- _serverSocket: any;
1090
+ _serverSocket: ServerSocket;
1087
1091
  _webrtcProvider: any;
1088
1092
  _features: any;
1089
1093
  _eventClaim?: any;
package/dist/index.d.ts CHANGED
@@ -159,6 +159,7 @@ declare class ReconnectManager extends EventEmitter {
159
159
  evaluationFailed: number;
160
160
  roomJoined: number;
161
161
  };
162
+ reconnectThresholdInMs: number;
162
163
  constructor(socket: any);
163
164
  _onRoomJoined(payload: any): Promise<void>;
164
165
  _onClientLeft(payload: any): void;
@@ -187,6 +188,7 @@ declare class ServerSocket {
187
188
  _reconnectManager?: ReconnectManager | null;
188
189
  noopKeepaliveInterval: any;
189
190
  _wasConnectedUsingWebsocket?: boolean;
191
+ disconnectTimestamp: number | undefined;
190
192
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean);
191
193
  setRtcManager(rtcManager?: RtcManager): void;
192
194
  connect(): void;
@@ -208,6 +210,7 @@ declare class ServerSocket {
208
210
  evaluationFailed: number;
209
211
  roomJoined: number;
210
212
  } | undefined;
213
+ getReconnectThreshold(): number | undefined;
211
214
  }
212
215
 
213
216
  declare const maybeTurnOnly: (transportConfig: any, features: {
@@ -1008,6 +1011,7 @@ declare class VegaConnection extends EventEmitter$1 {
1008
1011
  _setupSocket(): void;
1009
1012
  _tearDown(): void;
1010
1013
  close(): void;
1014
+ isConnected(): boolean;
1011
1015
  _onOpen(): void;
1012
1016
  _onMessage(event: MessageEvent): void;
1013
1017
  _onClose(): void;
@@ -1083,7 +1087,7 @@ declare class VegaRtcManager implements RtcManager {
1083
1087
  _room: any;
1084
1088
  _roomSessionId: any;
1085
1089
  _emitter: any;
1086
- _serverSocket: any;
1090
+ _serverSocket: ServerSocket;
1087
1091
  _webrtcProvider: any;
1088
1092
  _features: any;
1089
1093
  _eventClaim?: any;
package/dist/index.mjs CHANGED
@@ -1400,6 +1400,10 @@ class VegaConnection extends EventEmitter {
1400
1400
  var _a;
1401
1401
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
1402
1402
  }
1403
+ isConnected() {
1404
+ var _a, _b;
1405
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN || ((_b = this.socket) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.CONNECTING;
1406
+ }
1403
1407
  _onOpen() {
1404
1408
  logger$9.info("Connected");
1405
1409
  this.emit("open");
@@ -5098,6 +5102,9 @@ class VegaRtcManager {
5098
5102
  }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5099
5103
  if (this._screenVideoTrack)
5100
5104
  this._emitScreenshareStarted();
5105
+ if (this._features.sfuReconnectV2On && !this._vegaConnection.isConnected() && this._reconnect) {
5106
+ this._connect();
5107
+ }
5101
5108
  }));
5102
5109
  this._connect();
5103
5110
  }
@@ -5108,6 +5115,17 @@ class VegaRtcManager {
5108
5115
  });
5109
5116
  }
5110
5117
  _connect() {
5118
+ if (this._features.sfuReconnectV2On) {
5119
+ if (!this._serverSocket.isConnected()) {
5120
+ const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5121
+ if (!reconnectThresholdInMs)
5122
+ return;
5123
+ if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
5124
+ return;
5125
+ }
5126
+ if (this._reconnectTimeOut)
5127
+ clearTimeout(this._reconnectTimeOut);
5128
+ }
5111
5129
  const host = this._features.sfuServerOverrideHost || [this._sfuServer.url];
5112
5130
  const searchParams = new URLSearchParams(Object.assign({ clientId: this._selfId, organizationId: this._room.organizationId, roomName: this._room.name, eventClaim: this._room.isClaimed ? this._eventClaim : null, lowBw: "true" }, Object.keys(this._features || {})
5113
5131
  .filter((featureKey) => this._features[featureKey] && /^sfu/.test(featureKey))
@@ -6452,6 +6470,7 @@ const logger = new Logger();
6452
6470
  class ReconnectManager extends EventEmitter$1 {
6453
6471
  constructor(socket) {
6454
6472
  super();
6473
+ this.reconnectThresholdInMs = 0;
6455
6474
  this._socket = socket;
6456
6475
  this._clients = {};
6457
6476
  this._signalDisconnectTime = undefined;
@@ -6477,6 +6496,7 @@ class ReconnectManager extends EventEmitter$1 {
6477
6496
  _onRoomJoined(payload) {
6478
6497
  var _a, _b;
6479
6498
  return __awaiter(this, void 0, void 0, function* () {
6499
+ this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
6480
6500
  if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
6481
6501
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
6482
6502
  return;
@@ -6730,6 +6750,7 @@ class ServerSocket {
6730
6750
  }
6731
6751
  });
6732
6752
  this._socket.on("disconnect", () => {
6753
+ this.disconnectTimestamp = Date.now();
6733
6754
  if (this.noopKeepaliveInterval) {
6734
6755
  clearInterval(this.noopKeepaliveInterval);
6735
6756
  this.noopKeepaliveInterval = null;
@@ -6813,6 +6834,10 @@ class ServerSocket {
6813
6834
  var _a;
6814
6835
  return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.metrics;
6815
6836
  }
6837
+ getReconnectThreshold() {
6838
+ var _a;
6839
+ return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.reconnectThresholdInMs;
6840
+ }
6816
6841
  }
6817
6842
 
6818
6843
  const defaultSubdomainPattern = /^(?:([^.]+)[.])?((:?[^.]+[.]){1,}[^.]+)$/;
@@ -1400,6 +1400,10 @@ class VegaConnection extends EventEmitter {
1400
1400
  var _a;
1401
1401
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
1402
1402
  }
1403
+ isConnected() {
1404
+ var _a, _b;
1405
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN || ((_b = this.socket) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.CONNECTING;
1406
+ }
1403
1407
  _onOpen() {
1404
1408
  logger$9.info("Connected");
1405
1409
  this.emit("open");
@@ -5098,6 +5102,9 @@ class VegaRtcManager {
5098
5102
  }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5099
5103
  if (this._screenVideoTrack)
5100
5104
  this._emitScreenshareStarted();
5105
+ if (this._features.sfuReconnectV2On && !this._vegaConnection.isConnected() && this._reconnect) {
5106
+ this._connect();
5107
+ }
5101
5108
  }));
5102
5109
  this._connect();
5103
5110
  }
@@ -5108,6 +5115,17 @@ class VegaRtcManager {
5108
5115
  });
5109
5116
  }
5110
5117
  _connect() {
5118
+ if (this._features.sfuReconnectV2On) {
5119
+ if (!this._serverSocket.isConnected()) {
5120
+ const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5121
+ if (!reconnectThresholdInMs)
5122
+ return;
5123
+ if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
5124
+ return;
5125
+ }
5126
+ if (this._reconnectTimeOut)
5127
+ clearTimeout(this._reconnectTimeOut);
5128
+ }
5111
5129
  const host = this._features.sfuServerOverrideHost || [this._sfuServer.url];
5112
5130
  const searchParams = new URLSearchParams(Object.assign({ clientId: this._selfId, organizationId: this._room.organizationId, roomName: this._room.name, eventClaim: this._room.isClaimed ? this._eventClaim : null, lowBw: "true" }, Object.keys(this._features || {})
5113
5131
  .filter((featureKey) => this._features[featureKey] && /^sfu/.test(featureKey))
@@ -6452,6 +6470,7 @@ const logger = new Logger();
6452
6470
  class ReconnectManager extends EventEmitter$1 {
6453
6471
  constructor(socket) {
6454
6472
  super();
6473
+ this.reconnectThresholdInMs = 0;
6455
6474
  this._socket = socket;
6456
6475
  this._clients = {};
6457
6476
  this._signalDisconnectTime = undefined;
@@ -6477,6 +6496,7 @@ class ReconnectManager extends EventEmitter$1 {
6477
6496
  _onRoomJoined(payload) {
6478
6497
  var _a, _b;
6479
6498
  return __awaiter(this, void 0, void 0, function* () {
6499
+ this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
6480
6500
  if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
6481
6501
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
6482
6502
  return;
@@ -6730,6 +6750,7 @@ class ServerSocket {
6730
6750
  }
6731
6751
  });
6732
6752
  this._socket.on("disconnect", () => {
6753
+ this.disconnectTimestamp = Date.now();
6733
6754
  if (this.noopKeepaliveInterval) {
6734
6755
  clearInterval(this.noopKeepaliveInterval);
6735
6756
  this.noopKeepaliveInterval = null;
@@ -6813,6 +6834,10 @@ class ServerSocket {
6813
6834
  var _a;
6814
6835
  return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.metrics;
6815
6836
  }
6837
+ getReconnectThreshold() {
6838
+ var _a;
6839
+ return (_a = this._reconnectManager) === null || _a === void 0 ? void 0 : _a.reconnectThresholdInMs;
6840
+ }
6816
6841
  }
6817
6842
 
6818
6843
  const defaultSubdomainPattern = /^(?:([^.]+)[.])?((:?[^.]+[.]){1,}[^.]+)$/;
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.12.2",
4
+ "version": "1.13.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {