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