@whereby.com/media 1.25.0 → 1.25.1

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
@@ -4897,6 +4897,21 @@ function createVegaConnectionManager(config) {
4897
4897
  let connectionsToResolve = targetHostList.length;
4898
4898
  let hasNotifiedDisconnect = false;
4899
4899
  let wasConnected = false;
4900
+ const beforeNetworkPossiblyDownTime = lastNetworkPossiblyDownTime;
4901
+ const handleFailedOrAbortedConnection = () => {
4902
+ var _a;
4903
+ connectionsToResolve--;
4904
+ if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4905
+ connectionAttemptInProgress = false;
4906
+ if (hasPendingConnectionAttempt) {
4907
+ setTimeout(connect, 0);
4908
+ }
4909
+ else {
4910
+ (_a = config.onFailed) === null || _a === void 0 ? void 0 : _a.call(config);
4911
+ }
4912
+ }
4913
+ };
4914
+ const timers = [];
4900
4915
  targetHostList.forEach(({ host, dc }, index) => {
4901
4916
  if (index > 0) {
4902
4917
  timeBeforeConnect += timeNextServer;
@@ -4904,10 +4919,19 @@ function createVegaConnectionManager(config) {
4904
4919
  timeBeforeConnect = Math.max(timeBeforeConnect, minTimeBeforeConnect);
4905
4920
  }
4906
4921
  prevTimeBeforeConnectByDC[dc] = timeBeforeConnect;
4907
- setTimeout(() => {
4922
+ timers.push(setTimeout(() => {
4908
4923
  var _a;
4924
+ timers.shift();
4909
4925
  if (wasConnected)
4910
4926
  return;
4927
+ if (beforeNetworkPossiblyDownTime !== lastNetworkPossiblyDownTime) {
4928
+ handleFailedOrAbortedConnection();
4929
+ timers.forEach((timeoutId) => {
4930
+ clearTimeout(timeoutId);
4931
+ handleFailedOrAbortedConnection();
4932
+ });
4933
+ return;
4934
+ }
4911
4935
  const vegaConnection = new VegaConnection(((_a = config.getUrlForHost) === null || _a === void 0 ? void 0 : _a.call(config, host)) || host);
4912
4936
  let wasClosed = false;
4913
4937
  vegaConnection.on("open", () => {
@@ -4971,7 +4995,7 @@ function createVegaConnectionManager(config) {
4971
4995
  }, timeToWaitForEarlyServerClose);
4972
4996
  });
4973
4997
  vegaConnection.on("close", () => {
4974
- var _a, _b;
4998
+ var _a;
4975
4999
  wasClosed = true;
4976
5000
  if (vegaConnection === nominatedConnection) {
4977
5001
  nominatedConnection = undefined;
@@ -4979,18 +5003,9 @@ function createVegaConnectionManager(config) {
4979
5003
  hasNotifiedDisconnect = true;
4980
5004
  (_a = config.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(config);
4981
5005
  }
4982
- connectionsToResolve--;
4983
- if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4984
- connectionAttemptInProgress = false;
4985
- if (hasPendingConnectionAttempt) {
4986
- setTimeout(connect, 0);
4987
- }
4988
- else {
4989
- (_b = config.onFailed) === null || _b === void 0 ? void 0 : _b.call(config);
4990
- }
4991
- }
5006
+ handleFailedOrAbortedConnection();
4992
5007
  });
4993
- }, timeBeforeConnect);
5008
+ }, timeBeforeConnect));
4994
5009
  });
4995
5010
  };
4996
5011
  updateHostList(config.initialHostList);
package/dist/index.mjs CHANGED
@@ -4872,6 +4872,21 @@ function createVegaConnectionManager(config) {
4872
4872
  let connectionsToResolve = targetHostList.length;
4873
4873
  let hasNotifiedDisconnect = false;
4874
4874
  let wasConnected = false;
4875
+ const beforeNetworkPossiblyDownTime = lastNetworkPossiblyDownTime;
4876
+ const handleFailedOrAbortedConnection = () => {
4877
+ var _a;
4878
+ connectionsToResolve--;
4879
+ if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4880
+ connectionAttemptInProgress = false;
4881
+ if (hasPendingConnectionAttempt) {
4882
+ setTimeout(connect, 0);
4883
+ }
4884
+ else {
4885
+ (_a = config.onFailed) === null || _a === void 0 ? void 0 : _a.call(config);
4886
+ }
4887
+ }
4888
+ };
4889
+ const timers = [];
4875
4890
  targetHostList.forEach(({ host, dc }, index) => {
4876
4891
  if (index > 0) {
4877
4892
  timeBeforeConnect += timeNextServer;
@@ -4879,10 +4894,19 @@ function createVegaConnectionManager(config) {
4879
4894
  timeBeforeConnect = Math.max(timeBeforeConnect, minTimeBeforeConnect);
4880
4895
  }
4881
4896
  prevTimeBeforeConnectByDC[dc] = timeBeforeConnect;
4882
- setTimeout(() => {
4897
+ timers.push(setTimeout(() => {
4883
4898
  var _a;
4899
+ timers.shift();
4884
4900
  if (wasConnected)
4885
4901
  return;
4902
+ if (beforeNetworkPossiblyDownTime !== lastNetworkPossiblyDownTime) {
4903
+ handleFailedOrAbortedConnection();
4904
+ timers.forEach((timeoutId) => {
4905
+ clearTimeout(timeoutId);
4906
+ handleFailedOrAbortedConnection();
4907
+ });
4908
+ return;
4909
+ }
4886
4910
  const vegaConnection = new VegaConnection(((_a = config.getUrlForHost) === null || _a === void 0 ? void 0 : _a.call(config, host)) || host);
4887
4911
  let wasClosed = false;
4888
4912
  vegaConnection.on("open", () => {
@@ -4946,7 +4970,7 @@ function createVegaConnectionManager(config) {
4946
4970
  }, timeToWaitForEarlyServerClose);
4947
4971
  });
4948
4972
  vegaConnection.on("close", () => {
4949
- var _a, _b;
4973
+ var _a;
4950
4974
  wasClosed = true;
4951
4975
  if (vegaConnection === nominatedConnection) {
4952
4976
  nominatedConnection = undefined;
@@ -4954,18 +4978,9 @@ function createVegaConnectionManager(config) {
4954
4978
  hasNotifiedDisconnect = true;
4955
4979
  (_a = config.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(config);
4956
4980
  }
4957
- connectionsToResolve--;
4958
- if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4959
- connectionAttemptInProgress = false;
4960
- if (hasPendingConnectionAttempt) {
4961
- setTimeout(connect, 0);
4962
- }
4963
- else {
4964
- (_b = config.onFailed) === null || _b === void 0 ? void 0 : _b.call(config);
4965
- }
4966
- }
4981
+ handleFailedOrAbortedConnection();
4967
4982
  });
4968
- }, timeBeforeConnect);
4983
+ }, timeBeforeConnect));
4969
4984
  });
4970
4985
  };
4971
4986
  updateHostList(config.initialHostList);
@@ -4872,6 +4872,21 @@ function createVegaConnectionManager(config) {
4872
4872
  let connectionsToResolve = targetHostList.length;
4873
4873
  let hasNotifiedDisconnect = false;
4874
4874
  let wasConnected = false;
4875
+ const beforeNetworkPossiblyDownTime = lastNetworkPossiblyDownTime;
4876
+ const handleFailedOrAbortedConnection = () => {
4877
+ var _a;
4878
+ connectionsToResolve--;
4879
+ if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4880
+ connectionAttemptInProgress = false;
4881
+ if (hasPendingConnectionAttempt) {
4882
+ setTimeout(connect, 0);
4883
+ }
4884
+ else {
4885
+ (_a = config.onFailed) === null || _a === void 0 ? void 0 : _a.call(config);
4886
+ }
4887
+ }
4888
+ };
4889
+ const timers = [];
4875
4890
  targetHostList.forEach(({ host, dc }, index) => {
4876
4891
  if (index > 0) {
4877
4892
  timeBeforeConnect += timeNextServer;
@@ -4879,10 +4894,19 @@ function createVegaConnectionManager(config) {
4879
4894
  timeBeforeConnect = Math.max(timeBeforeConnect, minTimeBeforeConnect);
4880
4895
  }
4881
4896
  prevTimeBeforeConnectByDC[dc] = timeBeforeConnect;
4882
- setTimeout(() => {
4897
+ timers.push(setTimeout(() => {
4883
4898
  var _a;
4899
+ timers.shift();
4884
4900
  if (wasConnected)
4885
4901
  return;
4902
+ if (beforeNetworkPossiblyDownTime !== lastNetworkPossiblyDownTime) {
4903
+ handleFailedOrAbortedConnection();
4904
+ timers.forEach((timeoutId) => {
4905
+ clearTimeout(timeoutId);
4906
+ handleFailedOrAbortedConnection();
4907
+ });
4908
+ return;
4909
+ }
4886
4910
  const vegaConnection = new VegaConnection(((_a = config.getUrlForHost) === null || _a === void 0 ? void 0 : _a.call(config, host)) || host);
4887
4911
  let wasClosed = false;
4888
4912
  vegaConnection.on("open", () => {
@@ -4946,7 +4970,7 @@ function createVegaConnectionManager(config) {
4946
4970
  }, timeToWaitForEarlyServerClose);
4947
4971
  });
4948
4972
  vegaConnection.on("close", () => {
4949
- var _a, _b;
4973
+ var _a;
4950
4974
  wasClosed = true;
4951
4975
  if (vegaConnection === nominatedConnection) {
4952
4976
  nominatedConnection = undefined;
@@ -4954,18 +4978,9 @@ function createVegaConnectionManager(config) {
4954
4978
  hasNotifiedDisconnect = true;
4955
4979
  (_a = config.onDisconnected) === null || _a === void 0 ? void 0 : _a.call(config);
4956
4980
  }
4957
- connectionsToResolve--;
4958
- if (connectionsToResolve === 0 && !hasNotifiedDisconnect) {
4959
- connectionAttemptInProgress = false;
4960
- if (hasPendingConnectionAttempt) {
4961
- setTimeout(connect, 0);
4962
- }
4963
- else {
4964
- (_b = config.onFailed) === null || _b === void 0 ? void 0 : _b.call(config);
4965
- }
4966
- }
4981
+ handleFailedOrAbortedConnection();
4967
4982
  });
4968
- }, timeBeforeConnect);
4983
+ }, timeBeforeConnect));
4969
4984
  });
4970
4985
  };
4971
4986
  updateHostList(config.initialHostList);
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.25.0",
4
+ "version": "1.25.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {