@stream-io/video-client 1.7.2 → 1.7.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [1.7.3](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.7.2...@stream-io/video-client-1.7.3) (2024-09-24)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * do not always error out api calls when web socket initially failed ([#1495](https://github.com/GetStream/stream-video-js/issues/1495)) ([7cdb62e](https://github.com/GetStream/stream-video-js/commit/7cdb62e75cad56098ee81eabbcc63382f93fd218))
11
+
5
12
  ## [1.7.2](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.7.1...@stream-io/video-client-1.7.2) (2024-09-20)
6
13
 
7
14
 
@@ -2875,6 +2875,13 @@ function convertErrorToJson(err) {
2875
2875
  }
2876
2876
  return jsonObj;
2877
2877
  }
2878
+ /**
2879
+ * Informs if a promise is yet to be resolved or rejected
2880
+ */
2881
+ async function isPromisePending(promise) {
2882
+ const emptyObj = {};
2883
+ return Promise.race([promise, emptyObj]).then((value) => (value === emptyObj ? true : false), () => false);
2884
+ }
2878
2885
  /**
2879
2886
  * isOnline safely return the navigator.online value for browser env
2880
2887
  * if navigator is not in global object, it always return true
@@ -3013,7 +3020,7 @@ const retryable = async (rpc, signal) => {
3013
3020
  return result;
3014
3021
  };
3015
3022
 
3016
- const version = "1.7.2";
3023
+ const version = "1.7.3";
3017
3024
  const [major, minor, patch] = version.split('.');
3018
3025
  let sdkInfo = {
3019
3026
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -11365,6 +11372,15 @@ class StableWSConnection {
11365
11372
  this._log(`_connect() - tokenProvider failed before, so going to retry`);
11366
11373
  await this.client.tokenManager.loadToken();
11367
11374
  }
11375
+ let mustSetupConnectionIdPromise = true;
11376
+ if (this.client.connectionIdPromise) {
11377
+ if (await isPromisePending(this.client.connectionIdPromise)) {
11378
+ mustSetupConnectionIdPromise = false;
11379
+ }
11380
+ }
11381
+ if (mustSetupConnectionIdPromise) {
11382
+ this.client._setupConnectionIdPromise();
11383
+ }
11368
11384
  this._setupConnectionPromise();
11369
11385
  const wsURL = this._buildUrl();
11370
11386
  this._log(`_connect() - Connecting to ${wsURL}`, {
@@ -11390,6 +11406,7 @@ class StableWSConnection {
11390
11406
  }
11391
11407
  }
11392
11408
  catch (err) {
11409
+ await this.client._setupConnectionIdPromise();
11393
11410
  this.isConnecting = false;
11394
11411
  // @ts-ignore
11395
11412
  this._log(`_connect() - Error - `, err);
@@ -12047,10 +12064,7 @@ class StreamClient {
12047
12064
  this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists');
12048
12065
  return Promise.resolve();
12049
12066
  }
12050
- this.connectionIdPromise = new Promise((resolve, reject) => {
12051
- this.resolveConnectionId = resolve;
12052
- this.rejectConnectionId = reject;
12053
- });
12067
+ this._setupConnectionIdPromise();
12054
12068
  this.clientID = `${this.userID}--${randomId()}`;
12055
12069
  this.wsPromise = this.connect();
12056
12070
  return this.wsPromise;
@@ -12090,10 +12104,7 @@ class StreamClient {
12090
12104
  */
12091
12105
  this.connectAnonymousUser = async (user, tokenOrProvider) => {
12092
12106
  addConnectionEventListeners(this.updateNetworkConnectionStatus);
12093
- this.connectionIdPromise = new Promise((resolve, reject) => {
12094
- this.resolveConnectionId = resolve;
12095
- this.rejectConnectionId = reject;
12096
- });
12107
+ this._setupConnectionIdPromise();
12097
12108
  this.anonymous = true;
12098
12109
  await this._setToken(user, tokenOrProvider, this.anonymous);
12099
12110
  this._setUser(user);
@@ -12132,6 +12143,16 @@ class StreamClient {
12132
12143
  this.logger('debug', `Removing listener for ${eventName} event`);
12133
12144
  this.listeners[eventName] = this.listeners[eventName]?.filter((value) => value !== callback);
12134
12145
  };
12146
+ /**
12147
+ * sets up the this.connectionIdPromise
12148
+ */
12149
+ this._setupConnectionIdPromise = async () => {
12150
+ /** a promise that is resolved once connection id is set */
12151
+ this.connectionIdPromise = new Promise((resolve, reject) => {
12152
+ this.resolveConnectionId = resolve;
12153
+ this.rejectConnectionId = reject;
12154
+ });
12155
+ };
12135
12156
  this._logApiRequest = (type, url, data, config) => {
12136
12157
  this.logger('trace', `client: ${type} - Request - ${url}`, {
12137
12158
  payload: data,
@@ -12154,8 +12175,18 @@ class StreamClient {
12154
12175
  await Promise.all([
12155
12176
  this.tokenManager.tokenReady(),
12156
12177
  this.guestUserCreatePromise,
12157
- this.connectionIdPromise,
12158
12178
  ]);
12179
+ // we need to wait for presence of connection id before making requests
12180
+ try {
12181
+ await this.connectionIdPromise;
12182
+ }
12183
+ catch (e) {
12184
+ // in case connection id was rejected
12185
+ // reconnection maybe in progress
12186
+ // we can wait for healthy connection to resolve, which rejects when 15s timeout is reached
12187
+ await this.wsConnection?._waitForHealthy();
12188
+ await this.connectionIdPromise;
12189
+ }
12159
12190
  }
12160
12191
  const requestConfig = this._enrichAxiosOptions(options);
12161
12192
  try {
@@ -12338,7 +12369,7 @@ class StreamClient {
12338
12369
  });
12339
12370
  };
12340
12371
  this.getUserAgent = () => {
12341
- const version = "1.7.2";
12372
+ const version = "1.7.3";
12342
12373
  return (this.userAgent ||
12343
12374
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
12344
12375
  };