@whereby.com/media 1.17.15 → 1.18.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
@@ -12,14 +12,14 @@ var EventEmitter = require('events');
12
12
  var mediasoupClient = require('mediasoup-client');
13
13
  var uaParserJs = require('ua-parser-js');
14
14
  var Logger_js = require('mediasoup-client/lib/Logger.js');
15
- var utils = require('mediasoup-client/lib/utils');
16
- var ortc = require('mediasoup-client/lib/ortc');
17
- var sdpCommonUtils = require('mediasoup-client/lib/handlers/sdp/commonUtils');
18
- var ortcUtils = require('mediasoup-client/lib/handlers/ortc/utils');
19
- var errors = require('mediasoup-client/lib/errors');
20
- var HandlerInterface = require('mediasoup-client/lib/handlers/HandlerInterface');
21
- var RemoteSdp = require('mediasoup-client/lib/handlers/sdp/RemoteSdp');
22
- var scalabilityModes = require('mediasoup-client/lib/scalabilityModes');
15
+ var utils = require('mediasoup-client/lib/utils.js');
16
+ var ortc = require('mediasoup-client/lib/ortc.js');
17
+ var sdpCommonUtils = require('mediasoup-client/lib/handlers/sdp/commonUtils.js');
18
+ var ortcUtils = require('mediasoup-client/lib/handlers/ortc/utils.js');
19
+ var errors_js = require('mediasoup-client/lib/errors.js');
20
+ var HandlerInterface_js = require('mediasoup-client/lib/handlers/HandlerInterface.js');
21
+ var RemoteSdp_js = require('mediasoup-client/lib/handlers/sdp/RemoteSdp.js');
22
+ var scalabilityModes_js = require('mediasoup-client/lib/scalabilityModes.js');
23
23
  var Safari12_js = require('mediasoup-client/lib/handlers/Safari12.js');
24
24
  var socket_ioClient = require('socket.io-client');
25
25
 
@@ -1741,6 +1741,7 @@ var rtcManagerEvents = {
1741
1741
  NEW_PC: "new_pc",
1742
1742
  SFU_CONNECTION_OPEN: "sfu_connection_open",
1743
1743
  SFU_CONNECTION_CLOSED: "sfu_connection_closed",
1744
+ SFU_CONNECTION_INFO: "sfu_connection_info",
1744
1745
  COLOCATION_SPEAKER: "colocation_speaker",
1745
1746
  DOMINANT_SPEAKER: "dominant_speaker",
1746
1747
  PC_SLD_FAILURE: "pc_sld_failure",
@@ -3513,7 +3514,7 @@ const modifyMediaCapabilities = (routerRtpCapabilities, features) => {
3513
3514
  const logger$5 = new Logger_js.Logger("Safari17");
3514
3515
  const NAME = "Safari17";
3515
3516
  const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
3516
- class Safari17 extends HandlerInterface.HandlerInterface {
3517
+ class Safari17 extends HandlerInterface_js.HandlerInterface {
3517
3518
  static createFactory() {
3518
3519
  return () => new Safari17();
3519
3520
  }
@@ -3588,7 +3589,7 @@ class Safari17 extends HandlerInterface.HandlerInterface {
3588
3589
  this.assertNotClosed();
3589
3590
  logger$5.debug("run()");
3590
3591
  this._direction = direction;
3591
- this._remoteSdp = new RemoteSdp.RemoteSdp({
3592
+ this._remoteSdp = new RemoteSdp_js.RemoteSdp({
3592
3593
  iceParameters,
3593
3594
  iceCandidates,
3594
3595
  dtlsParameters,
@@ -3704,7 +3705,7 @@ class Safari17 extends HandlerInterface.HandlerInterface {
3704
3705
  }
3705
3706
  Object.assign(sendingRtpParameters.encodings, encodings);
3706
3707
  }
3707
- const layers = scalabilityModes.parse((encodings !== null && encodings !== void 0 ? encodings : [{}])[0].scalabilityMode);
3708
+ const layers = scalabilityModes_js.parse((encodings !== null && encodings !== void 0 ? encodings : [{}])[0].scalabilityMode);
3708
3709
  if (sendingRtpParameters.encodings &&
3709
3710
  sendingRtpParameters.encodings.length > 1 &&
3710
3711
  (sendingRtpParameters.codecs[0].mimeType.toLowerCase() === "video/vp8" ||
@@ -4156,7 +4157,7 @@ class Safari17 extends HandlerInterface.HandlerInterface {
4156
4157
  }
4157
4158
  assertNotClosed() {
4158
4159
  if (this._closed) {
4159
- throw new errors.InvalidStateError("method called in a closed handler");
4160
+ throw new errors_js.InvalidStateError("method called in a closed handler");
4160
4161
  }
4161
4162
  }
4162
4163
  assertSendDirection() {
@@ -4249,6 +4250,167 @@ function getNumberOfTemporalLayers(consumer) {
4249
4250
  return /T3/.test(((_c = (_b = (_a = consumer._rtpParameters) === null || _a === void 0 ? void 0 : _a.encodings) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.scalabilityMode) || "") ? 3 : 2;
4250
4251
  }
4251
4252
 
4253
+ const timeNextServer = 500;
4254
+ const minTimeNextServerSameDC = 2000;
4255
+ const timeToWaitForEarlyServerClose = 100;
4256
+ function convertToProperHostList(hostList) {
4257
+ if (typeof hostList === "string") {
4258
+ return hostList
4259
+ .split(",")
4260
+ .filter(Boolean)
4261
+ .map((hostString) => {
4262
+ const [dc, host] = /\|/.test(hostString) ? hostString.split("|") : ["", hostString];
4263
+ return { host, dc };
4264
+ });
4265
+ }
4266
+ return hostList.filter((item) => item.host).map((item) => ({ host: item.host, dc: item.dc || "" }));
4267
+ }
4268
+ function createVegaConnectionManager(config) {
4269
+ let connectionInfo;
4270
+ let lastDisconnectTime;
4271
+ let lastNetworkUpTime;
4272
+ let lastNetworkPossiblyDownTime;
4273
+ let hostList = [];
4274
+ const updateHostList = (updatedHostList) => {
4275
+ hostList = convertToProperHostList(updatedHostList);
4276
+ };
4277
+ let connectionAttemptInProgress = false;
4278
+ let hasPendingConnectionAttempt = false;
4279
+ const connect = () => {
4280
+ if (connectionAttemptInProgress) {
4281
+ hasPendingConnectionAttempt = true;
4282
+ return;
4283
+ }
4284
+ connectionAttemptInProgress = true;
4285
+ hasPendingConnectionAttempt = false;
4286
+ let targetHostList = hostList;
4287
+ if (connectionInfo) {
4288
+ const now = Date.now();
4289
+ const isLongEnoughSinceDisconnect = now - 3000 > (lastDisconnectTime || 0);
4290
+ const isNetworkUp = !lastNetworkPossiblyDownTime || (lastNetworkUpTime || 0) > lastNetworkPossiblyDownTime;
4291
+ const hasNetworkBeenUpLongEnough = isNetworkUp && now - 3000 > (lastNetworkUpTime || 0);
4292
+ if (!isLongEnoughSinceDisconnect || !hasNetworkBeenUpLongEnough) {
4293
+ targetHostList = [{ host: connectionInfo.host, dc: connectionInfo.dc }];
4294
+ }
4295
+ }
4296
+ const dcIndexByDC = {};
4297
+ let currentDCIndex = 0;
4298
+ targetHostList.forEach(({ dc }) => {
4299
+ if (typeof dcIndexByDC[dc] === "undefined")
4300
+ dcIndexByDC[dc] = currentDCIndex++;
4301
+ });
4302
+ let timeBeforeConnect = 0;
4303
+ const prevTimeBeforeConnectByDC = {};
4304
+ let nominatedConnection;
4305
+ let connectionsToResolve = targetHostList.length;
4306
+ let hasNotifiedDisconnect = false;
4307
+ let wasConnected = false;
4308
+ targetHostList.forEach(({ host, dc }, index) => {
4309
+ if (index > 0) {
4310
+ timeBeforeConnect += timeNextServer;
4311
+ const minTimeBeforeConnect = (prevTimeBeforeConnectByDC[dc] || 0) + minTimeNextServerSameDC;
4312
+ timeBeforeConnect = Math.max(timeBeforeConnect, minTimeBeforeConnect);
4313
+ }
4314
+ prevTimeBeforeConnectByDC[dc] = timeBeforeConnect;
4315
+ setTimeout(() => {
4316
+ var _a;
4317
+ if (wasConnected)
4318
+ return;
4319
+ const vegaConnection = new VegaConnection(((_a = config.getUrlForHost) === null || _a === void 0 ? void 0 : _a.call(config, host)) || host);
4320
+ let wasClosed = false;
4321
+ vegaConnection.on("open", () => {
4322
+ setTimeout(() => {
4323
+ var _a;
4324
+ if (wasClosed)
4325
+ return;
4326
+ if (!nominatedConnection && !wasConnected) {
4327
+ nominatedConnection = vegaConnection;
4328
+ wasConnected = true;
4329
+ const thisRoundFailedHosts = [
4330
+ ...new Set(targetHostList
4331
+ .slice(0, index)
4332
+ .filter((o) => o.host !== host)
4333
+ .map((o) => o.host)),
4334
+ ];
4335
+ const thisRoundFailedDCs = [
4336
+ ...new Set(targetHostList
4337
+ .slice(0, index)
4338
+ .filter((o) => o.dc !== dc)
4339
+ .map((o) => o.dc)),
4340
+ ];
4341
+ if (!connectionInfo) {
4342
+ connectionInfo = {
4343
+ host,
4344
+ dc,
4345
+ initialHost: host,
4346
+ initialDC: dc,
4347
+ initialHostIndex: index,
4348
+ initialDCIndex: dcIndexByDC[dc],
4349
+ failedHosts: thisRoundFailedHosts,
4350
+ failedDCs: thisRoundFailedDCs,
4351
+ usedHosts: [host],
4352
+ usedDCs: [dc],
4353
+ numConnections: 1,
4354
+ numUsedDCs: 1,
4355
+ numUsedHosts: 1,
4356
+ numFailedDCs: 0,
4357
+ numFailedHosts: 0,
4358
+ };
4359
+ }
4360
+ else {
4361
+ connectionInfo = Object.assign(Object.assign({}, connectionInfo), { host,
4362
+ dc, failedHosts: [
4363
+ ...new Set([...thisRoundFailedHosts, ...connectionInfo.failedHosts]),
4364
+ ].filter((failedHost) => failedHost !== host && !connectionInfo.usedHosts.includes(failedHost)), failedDCs: [
4365
+ ...new Set([...thisRoundFailedDCs, ...connectionInfo.failedDCs]),
4366
+ ].filter((failedDC) => failedDC !== dc && !connectionInfo.usedDCs.includes(failedDC)), usedHosts: [...new Set([...connectionInfo.usedHosts, host])], usedDCs: [...new Set([...connectionInfo.usedDCs, dc])], numConnections: connectionInfo.numConnections + 1 });
4367
+ }
4368
+ connectionInfo.numUsedDCs = connectionInfo.usedDCs.length;
4369
+ connectionInfo.numUsedHosts = connectionInfo.usedHosts.length;
4370
+ connectionInfo.numFailedDCs = connectionInfo.failedDCs.length;
4371
+ connectionInfo.numFailedHosts = connectionInfo.failedHosts.length;
4372
+ hasPendingConnectionAttempt = false;
4373
+ connectionAttemptInProgress = false;
4374
+ (_a = config.onConnected) === null || _a === void 0 ? void 0 : _a.call(config, vegaConnection, connectionInfo);
4375
+ }
4376
+ else {
4377
+ vegaConnection.close();
4378
+ }
4379
+ }, timeToWaitForEarlyServerClose);
4380
+ });
4381
+ vegaConnection.on("close", () => {
4382
+ var _a, _b;
4383
+ wasClosed = true;
4384
+ if (vegaConnection === nominatedConnection) {
4385
+ nominatedConnection = undefined;
4386
+ lastDisconnectTime = Date.now();
4387
+ hasNotifiedDisconnect = true;
4388
+ (_a = config.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(config);
4389
+ }
4390
+ connectionsToResolve--;
4391
+ if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4392
+ connectionAttemptInProgress = false;
4393
+ if (hasPendingConnectionAttempt) {
4394
+ setTimeout(connect, 0);
4395
+ }
4396
+ else {
4397
+ (_b = config.onFailed) === null || _b === void 0 ? void 0 : _b.call(config);
4398
+ }
4399
+ }
4400
+ });
4401
+ }, timeBeforeConnect);
4402
+ });
4403
+ };
4404
+ updateHostList(config.initialHostList);
4405
+ const networkIsUp = () => {
4406
+ lastNetworkUpTime = Math.max(Date.now(), lastNetworkUpTime || 0);
4407
+ };
4408
+ const networkIsPossiblyDown = () => {
4409
+ lastNetworkPossiblyDownTime = Date.now();
4410
+ };
4411
+ return { connect, updateHostList, networkIsUp, networkIsPossiblyDown };
4412
+ }
4413
+
4252
4414
  var _a$2;
4253
4415
  const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
4254
4416
  const logger$4 = new Logger();
@@ -4262,7 +4424,7 @@ if (browserName === "chrome")
4262
4424
  window.document.addEventListener("beforeunload", () => (unloading = true));
4263
4425
  class VegaRtcManager {
4264
4426
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }) {
4265
- const { session, iceServers, sfuServer, mediaserverConfigTtlSeconds } = room;
4427
+ const { session, iceServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds } = room;
4266
4428
  this._selfId = selfId;
4267
4429
  this._room = room;
4268
4430
  this._roomSessionId = session === null || session === void 0 ? void 0 : session.id;
@@ -4314,6 +4476,7 @@ class VegaRtcManager {
4314
4476
  };
4315
4477
  this._updateAndScheduleMediaServersRefresh({
4316
4478
  sfuServer,
4479
+ sfuServers,
4317
4480
  iceServers: iceServers.iceServers || [],
4318
4481
  mediaserverConfigTtlSeconds,
4319
4482
  });
@@ -4321,18 +4484,31 @@ class VegaRtcManager {
4321
4484
  this._reconnect = true;
4322
4485
  this._reconnectTimeOut = null;
4323
4486
  this._hasVegaConnection = false;
4487
+ this._isConnectingOrConnected = false;
4324
4488
  this._qualityMonitor = new VegaMediaQualityMonitor();
4325
4489
  this._qualityMonitor.on(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, (payload) => {
4326
4490
  this._emitToPWA(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, payload);
4327
4491
  });
4492
+ this._networkIsDetectedUpBySignal = false;
4328
4493
  }
4329
- _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, mediaserverConfigTtlSeconds, }) {
4330
- var _a, _b;
4494
+ _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }) {
4495
+ var _a, _b, _c;
4331
4496
  this._iceServers = iceServers;
4332
4497
  this._sfuServer = sfuServer;
4498
+ this._sfuServers = sfuServers;
4499
+ if (!sfuServers && (sfuServer === null || sfuServer === void 0 ? void 0 : sfuServer.fallbackServers)) {
4500
+ this._sfuServers = sfuServer.fallbackServers.map((entry) => ({
4501
+ host: entry.host || entry.fqdn,
4502
+ dc: entry.dc,
4503
+ }));
4504
+ }
4333
4505
  this._mediaserverConfigTtlSeconds = mediaserverConfigTtlSeconds;
4334
- (_a = this._sendTransport) === null || _a === void 0 ? void 0 : _a.updateIceServers({ iceServers: this._iceServers });
4335
- (_b = this._receiveTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers({ iceServers: this._iceServers });
4506
+ (_a = this._vegaConnectionManager) === null || _a === void 0 ? void 0 : _a.updateHostList(this._features.sfuServersOverride ||
4507
+ this._sfuServers ||
4508
+ this._features.sfuServerOverrideHost ||
4509
+ sfuServer.url);
4510
+ (_b = this._sendTransport) === null || _b === void 0 ? void 0 : _b.updateIceServers({ iceServers: this._iceServers });
4511
+ (_c = this._receiveTransport) === null || _c === void 0 ? void 0 : _c.updateIceServers({ iceServers: this._iceServers });
4336
4512
  this._clearMediaServersRefresh();
4337
4513
  if (!mediaserverConfigTtlSeconds) {
4338
4514
  return;
@@ -4345,6 +4521,20 @@ class VegaRtcManager {
4345
4521
  clearTimeout(this._fetchMediaServersTimer);
4346
4522
  this._fetchMediaServersTimer = null;
4347
4523
  }
4524
+ _onNetworkIsDetectedUpBySignal() {
4525
+ var _a;
4526
+ if (!this._networkIsDetectedUpBySignal) {
4527
+ this._networkIsDetectedUpBySignal = true;
4528
+ (_a = this._vegaConnectionManager) === null || _a === void 0 ? void 0 : _a.networkIsUp();
4529
+ }
4530
+ }
4531
+ _onNetworkIsDetectedPossiblyDownBySignal() {
4532
+ var _a;
4533
+ if (this._networkIsDetectedUpBySignal) {
4534
+ this._networkIsDetectedUpBySignal = false;
4535
+ (_a = this._vegaConnectionManager) === null || _a === void 0 ? void 0 : _a.networkIsPossiblyDown();
4536
+ }
4537
+ }
4348
4538
  setupSocketListeners() {
4349
4539
  this._socketListenerDeregisterFunctions.push(() => this._clearMediaServersRefresh(), this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
4350
4540
  if (data.error) {
@@ -4358,7 +4548,7 @@ class VegaRtcManager {
4358
4548
  if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
4359
4549
  this._connect();
4360
4550
  }
4361
- }));
4551
+ }), this._serverSocket.on("connect", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.onEngineEvent("packet", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.on("disconnect", () => this._onNetworkIsDetectedPossiblyDownBySignal()));
4362
4552
  this._connect();
4363
4553
  }
4364
4554
  _emitScreenshareStarted() {
@@ -4368,6 +4558,8 @@ class VegaRtcManager {
4368
4558
  });
4369
4559
  }
4370
4560
  _connect() {
4561
+ if (this._features.sfuConnectionManagerOn)
4562
+ return this._connect_v2();
4371
4563
  if (this._features.sfuReconnectV2On) {
4372
4564
  if (this._hasVegaConnection)
4373
4565
  return;
@@ -4393,6 +4585,56 @@ class VegaRtcManager {
4393
4585
  this._vegaConnection.on("close", () => this._onClose());
4394
4586
  this._vegaConnection.on("message", (message) => this._onMessage(message));
4395
4587
  }
4588
+ _connect_v2() {
4589
+ if (this._features.sfuReconnectV2On) {
4590
+ if (this._isConnectingOrConnected)
4591
+ return;
4592
+ if (!this._serverSocket.isConnected()) {
4593
+ const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
4594
+ if (!reconnectThresholdInMs)
4595
+ return;
4596
+ if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
4597
+ return;
4598
+ }
4599
+ if (this._reconnectTimeOut)
4600
+ clearTimeout(this._reconnectTimeOut);
4601
+ }
4602
+ if (!this._vegaConnectionManager) {
4603
+ const hostList = this._features.sfuServersOverride ||
4604
+ this._sfuServers ||
4605
+ this._features.sfuServerOverrideHost ||
4606
+ this._sfuServer.url;
4607
+ this._vegaConnectionManager = createVegaConnectionManager({
4608
+ initialHostList: hostList,
4609
+ getUrlForHost: (host) => {
4610
+ 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 || {})
4611
+ .filter((featureKey) => this._features[featureKey] && /^sfu/.test(featureKey))
4612
+ .reduce((prev, current) => (Object.assign(Object.assign({}, prev), { [current]: this._features[current] })), {})));
4613
+ const queryString = searchParams.toString();
4614
+ const wsUrl = `wss://${host}?${queryString}`;
4615
+ return wsUrl;
4616
+ },
4617
+ onConnected: (vegaConnection, info) => {
4618
+ this._vegaConnection = vegaConnection;
4619
+ this._vegaConnection.on("message", (message) => this._onMessage(message));
4620
+ this._emitToPWA(rtcManagerEvents.SFU_CONNECTION_INFO, info);
4621
+ this._join();
4622
+ },
4623
+ onDisconnected: () => {
4624
+ this._vegaConnection = null;
4625
+ this._isConnectingOrConnected = false;
4626
+ this._onClose();
4627
+ },
4628
+ onFailed: () => {
4629
+ this._vegaConnection = null;
4630
+ this._isConnectingOrConnected = false;
4631
+ this._onClose();
4632
+ },
4633
+ });
4634
+ }
4635
+ this._vegaConnectionManager.connect();
4636
+ this._isConnectingOrConnected = true;
4637
+ }
4396
4638
  _onClose() {
4397
4639
  var _a, _b;
4398
4640
  logger$4.info("_onClose()");
@@ -6086,6 +6328,14 @@ class ServerSocket {
6086
6328
  this._socket.off(eventName, handler);
6087
6329
  };
6088
6330
  }
6331
+ onEngineEvent(eventName, handler) {
6332
+ var _a;
6333
+ (_a = this._socket.io) === null || _a === void 0 ? void 0 : _a.on(eventName, handler);
6334
+ return () => {
6335
+ var _a;
6336
+ (_a = this._socket.io) === null || _a === void 0 ? void 0 : _a.off(eventName, handler);
6337
+ };
6338
+ }
6089
6339
  once(eventName, handler) {
6090
6340
  this._socket.once(eventName, handler);
6091
6341
  }
package/dist/index.d.cts CHANGED
@@ -655,6 +655,7 @@ declare class ServerSocket {
655
655
  isConnecting(): any;
656
656
  isConnected(): any;
657
657
  on(eventName: string, handler: Function): () => void;
658
+ onEngineEvent(eventName: string, handler: Function): () => void;
658
659
  once(eventName: string, handler: Function): void;
659
660
  off(eventName: string, handler: Function): void;
660
661
  _interceptEvent(eventName: string, handler: any): () => void;
@@ -1045,6 +1046,7 @@ declare const _default: {
1045
1046
  NEW_PC: string;
1046
1047
  SFU_CONNECTION_OPEN: string;
1047
1048
  SFU_CONNECTION_CLOSED: string;
1049
+ SFU_CONNECTION_INFO: string;
1048
1050
  COLOCATION_SPEAKER: string;
1049
1051
  DOMINANT_SPEAKER: string;
1050
1052
  PC_SLD_FAILURE: string;
@@ -1252,6 +1254,40 @@ declare const standardDeviation: (arr: any[]) => {
1252
1254
  };
1253
1255
  declare const variance: (arr: any[], usePopulation?: boolean) => number;
1254
1256
 
1257
+ type ConnectionInfo = {
1258
+ host: string;
1259
+ dc: string;
1260
+ initialHost: string;
1261
+ initialDC: string;
1262
+ initialHostIndex: number;
1263
+ initialDCIndex: number;
1264
+ failedDCs: string[];
1265
+ numFailedDCs: number;
1266
+ failedHosts: string[];
1267
+ numFailedHosts: number;
1268
+ usedDCs: string[];
1269
+ numUsedDCs: number;
1270
+ usedHosts: string[];
1271
+ numUsedHosts: number;
1272
+ numConnections: number;
1273
+ };
1274
+ type HostListEntryOptionalDC = {
1275
+ host: string;
1276
+ dc?: string;
1277
+ };
1278
+ declare function createVegaConnectionManager(config: {
1279
+ initialHostList: string | any[];
1280
+ getUrlForHost?: (host: string) => string;
1281
+ onConnected?: (vegaConnection: VegaConnection, info: ConnectionInfo) => void;
1282
+ onDisconnected?: () => void;
1283
+ onFailed?: () => void;
1284
+ }): {
1285
+ connect: () => void;
1286
+ updateHostList: (updatedHostList: string | HostListEntryOptionalDC[]) => void;
1287
+ networkIsUp: () => void;
1288
+ networkIsPossiblyDown: () => void;
1289
+ };
1290
+
1255
1291
  declare class VegaRtcManager implements RtcManager {
1256
1292
  _selfId: any;
1257
1293
  _room: any;
@@ -1306,10 +1342,14 @@ declare class VegaRtcManager implements RtcManager {
1306
1342
  _fetchMediaServersTimer: any;
1307
1343
  _iceServers: any;
1308
1344
  _sfuServer: any;
1345
+ _sfuServers?: HostListEntryOptionalDC[];
1309
1346
  _mediaserverConfigTtlSeconds: any;
1310
1347
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
1311
1348
  _audioTrackBeingMonitored?: CustomMediaStreamTrack;
1312
1349
  _hasVegaConnection: boolean;
1350
+ _isConnectingOrConnected: boolean;
1351
+ _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1352
+ _networkIsDetectedUpBySignal: boolean;
1313
1353
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1314
1354
  selfId: any;
1315
1355
  room: any;
@@ -1319,15 +1359,19 @@ declare class VegaRtcManager implements RtcManager {
1319
1359
  features?: any;
1320
1360
  eventClaim?: string;
1321
1361
  });
1322
- _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, mediaserverConfigTtlSeconds, }: {
1362
+ _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }: {
1323
1363
  iceServers: any;
1324
1364
  sfuServer: any;
1365
+ sfuServers: any;
1325
1366
  mediaserverConfigTtlSeconds: any;
1326
1367
  }): void;
1327
1368
  _clearMediaServersRefresh(): void;
1369
+ _onNetworkIsDetectedUpBySignal(): void;
1370
+ _onNetworkIsDetectedPossiblyDownBySignal(): void;
1328
1371
  setupSocketListeners(): void;
1329
1372
  _emitScreenshareStarted(): void;
1330
1373
  _connect(): void;
1374
+ _connect_v2(): void;
1331
1375
  _onClose(): void;
1332
1376
  _join(): Promise<void>;
1333
1377
  _createTransport(send: any): Promise<void>;
package/dist/index.d.mts CHANGED
@@ -655,6 +655,7 @@ declare class ServerSocket {
655
655
  isConnecting(): any;
656
656
  isConnected(): any;
657
657
  on(eventName: string, handler: Function): () => void;
658
+ onEngineEvent(eventName: string, handler: Function): () => void;
658
659
  once(eventName: string, handler: Function): void;
659
660
  off(eventName: string, handler: Function): void;
660
661
  _interceptEvent(eventName: string, handler: any): () => void;
@@ -1045,6 +1046,7 @@ declare const _default: {
1045
1046
  NEW_PC: string;
1046
1047
  SFU_CONNECTION_OPEN: string;
1047
1048
  SFU_CONNECTION_CLOSED: string;
1049
+ SFU_CONNECTION_INFO: string;
1048
1050
  COLOCATION_SPEAKER: string;
1049
1051
  DOMINANT_SPEAKER: string;
1050
1052
  PC_SLD_FAILURE: string;
@@ -1252,6 +1254,40 @@ declare const standardDeviation: (arr: any[]) => {
1252
1254
  };
1253
1255
  declare const variance: (arr: any[], usePopulation?: boolean) => number;
1254
1256
 
1257
+ type ConnectionInfo = {
1258
+ host: string;
1259
+ dc: string;
1260
+ initialHost: string;
1261
+ initialDC: string;
1262
+ initialHostIndex: number;
1263
+ initialDCIndex: number;
1264
+ failedDCs: string[];
1265
+ numFailedDCs: number;
1266
+ failedHosts: string[];
1267
+ numFailedHosts: number;
1268
+ usedDCs: string[];
1269
+ numUsedDCs: number;
1270
+ usedHosts: string[];
1271
+ numUsedHosts: number;
1272
+ numConnections: number;
1273
+ };
1274
+ type HostListEntryOptionalDC = {
1275
+ host: string;
1276
+ dc?: string;
1277
+ };
1278
+ declare function createVegaConnectionManager(config: {
1279
+ initialHostList: string | any[];
1280
+ getUrlForHost?: (host: string) => string;
1281
+ onConnected?: (vegaConnection: VegaConnection, info: ConnectionInfo) => void;
1282
+ onDisconnected?: () => void;
1283
+ onFailed?: () => void;
1284
+ }): {
1285
+ connect: () => void;
1286
+ updateHostList: (updatedHostList: string | HostListEntryOptionalDC[]) => void;
1287
+ networkIsUp: () => void;
1288
+ networkIsPossiblyDown: () => void;
1289
+ };
1290
+
1255
1291
  declare class VegaRtcManager implements RtcManager {
1256
1292
  _selfId: any;
1257
1293
  _room: any;
@@ -1306,10 +1342,14 @@ declare class VegaRtcManager implements RtcManager {
1306
1342
  _fetchMediaServersTimer: any;
1307
1343
  _iceServers: any;
1308
1344
  _sfuServer: any;
1345
+ _sfuServers?: HostListEntryOptionalDC[];
1309
1346
  _mediaserverConfigTtlSeconds: any;
1310
1347
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
1311
1348
  _audioTrackBeingMonitored?: CustomMediaStreamTrack;
1312
1349
  _hasVegaConnection: boolean;
1350
+ _isConnectingOrConnected: boolean;
1351
+ _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1352
+ _networkIsDetectedUpBySignal: boolean;
1313
1353
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1314
1354
  selfId: any;
1315
1355
  room: any;
@@ -1319,15 +1359,19 @@ declare class VegaRtcManager implements RtcManager {
1319
1359
  features?: any;
1320
1360
  eventClaim?: string;
1321
1361
  });
1322
- _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, mediaserverConfigTtlSeconds, }: {
1362
+ _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }: {
1323
1363
  iceServers: any;
1324
1364
  sfuServer: any;
1365
+ sfuServers: any;
1325
1366
  mediaserverConfigTtlSeconds: any;
1326
1367
  }): void;
1327
1368
  _clearMediaServersRefresh(): void;
1369
+ _onNetworkIsDetectedUpBySignal(): void;
1370
+ _onNetworkIsDetectedPossiblyDownBySignal(): void;
1328
1371
  setupSocketListeners(): void;
1329
1372
  _emitScreenshareStarted(): void;
1330
1373
  _connect(): void;
1374
+ _connect_v2(): void;
1331
1375
  _onClose(): void;
1332
1376
  _join(): Promise<void>;
1333
1377
  _createTransport(send: any): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -655,6 +655,7 @@ declare class ServerSocket {
655
655
  isConnecting(): any;
656
656
  isConnected(): any;
657
657
  on(eventName: string, handler: Function): () => void;
658
+ onEngineEvent(eventName: string, handler: Function): () => void;
658
659
  once(eventName: string, handler: Function): void;
659
660
  off(eventName: string, handler: Function): void;
660
661
  _interceptEvent(eventName: string, handler: any): () => void;
@@ -1045,6 +1046,7 @@ declare const _default: {
1045
1046
  NEW_PC: string;
1046
1047
  SFU_CONNECTION_OPEN: string;
1047
1048
  SFU_CONNECTION_CLOSED: string;
1049
+ SFU_CONNECTION_INFO: string;
1048
1050
  COLOCATION_SPEAKER: string;
1049
1051
  DOMINANT_SPEAKER: string;
1050
1052
  PC_SLD_FAILURE: string;
@@ -1252,6 +1254,40 @@ declare const standardDeviation: (arr: any[]) => {
1252
1254
  };
1253
1255
  declare const variance: (arr: any[], usePopulation?: boolean) => number;
1254
1256
 
1257
+ type ConnectionInfo = {
1258
+ host: string;
1259
+ dc: string;
1260
+ initialHost: string;
1261
+ initialDC: string;
1262
+ initialHostIndex: number;
1263
+ initialDCIndex: number;
1264
+ failedDCs: string[];
1265
+ numFailedDCs: number;
1266
+ failedHosts: string[];
1267
+ numFailedHosts: number;
1268
+ usedDCs: string[];
1269
+ numUsedDCs: number;
1270
+ usedHosts: string[];
1271
+ numUsedHosts: number;
1272
+ numConnections: number;
1273
+ };
1274
+ type HostListEntryOptionalDC = {
1275
+ host: string;
1276
+ dc?: string;
1277
+ };
1278
+ declare function createVegaConnectionManager(config: {
1279
+ initialHostList: string | any[];
1280
+ getUrlForHost?: (host: string) => string;
1281
+ onConnected?: (vegaConnection: VegaConnection, info: ConnectionInfo) => void;
1282
+ onDisconnected?: () => void;
1283
+ onFailed?: () => void;
1284
+ }): {
1285
+ connect: () => void;
1286
+ updateHostList: (updatedHostList: string | HostListEntryOptionalDC[]) => void;
1287
+ networkIsUp: () => void;
1288
+ networkIsPossiblyDown: () => void;
1289
+ };
1290
+
1255
1291
  declare class VegaRtcManager implements RtcManager {
1256
1292
  _selfId: any;
1257
1293
  _room: any;
@@ -1306,10 +1342,14 @@ declare class VegaRtcManager implements RtcManager {
1306
1342
  _fetchMediaServersTimer: any;
1307
1343
  _iceServers: any;
1308
1344
  _sfuServer: any;
1345
+ _sfuServers?: HostListEntryOptionalDC[];
1309
1346
  _mediaserverConfigTtlSeconds: any;
1310
1347
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
1311
1348
  _audioTrackBeingMonitored?: CustomMediaStreamTrack;
1312
1349
  _hasVegaConnection: boolean;
1350
+ _isConnectingOrConnected: boolean;
1351
+ _vegaConnectionManager?: ReturnType<typeof createVegaConnectionManager>;
1352
+ _networkIsDetectedUpBySignal: boolean;
1313
1353
  constructor({ selfId, room, emitter, serverSocket, webrtcProvider, features, eventClaim, }: {
1314
1354
  selfId: any;
1315
1355
  room: any;
@@ -1319,15 +1359,19 @@ declare class VegaRtcManager implements RtcManager {
1319
1359
  features?: any;
1320
1360
  eventClaim?: string;
1321
1361
  });
1322
- _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, mediaserverConfigTtlSeconds, }: {
1362
+ _updateAndScheduleMediaServersRefresh({ iceServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }: {
1323
1363
  iceServers: any;
1324
1364
  sfuServer: any;
1365
+ sfuServers: any;
1325
1366
  mediaserverConfigTtlSeconds: any;
1326
1367
  }): void;
1327
1368
  _clearMediaServersRefresh(): void;
1369
+ _onNetworkIsDetectedUpBySignal(): void;
1370
+ _onNetworkIsDetectedPossiblyDownBySignal(): void;
1328
1371
  setupSocketListeners(): void;
1329
1372
  _emitScreenshareStarted(): void;
1330
1373
  _connect(): void;
1374
+ _connect_v2(): void;
1331
1375
  _onClose(): void;
1332
1376
  _join(): Promise<void>;
1333
1377
  _createTransport(send: any): Promise<void>;