@stream-io/video-client 0.1.1 → 0.1.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.cjs.js CHANGED
@@ -10746,6 +10746,7 @@ class StableWSConnection {
10746
10746
  * @return {ConnectAPIResponse<ConnectedEvent>} Promise that completes once the first health check message is received
10747
10747
  */
10748
10748
  _connect() {
10749
+ var _a, _b, _c, _d;
10749
10750
  return __awaiter(this, void 0, void 0, function* () {
10750
10751
  if (this.isConnecting ||
10751
10752
  (this.isDisconnected && this.client.options.enableWSFallback))
@@ -10782,7 +10783,7 @@ class StableWSConnection {
10782
10783
  this.isConnecting = false;
10783
10784
  if (response) {
10784
10785
  this.connectionID = response.connection_id;
10785
- this.client.resolveConnectionId(this.connectionID);
10786
+ (_b = (_a = this.client).resolveConnectionId) === null || _b === void 0 ? void 0 : _b.call(_a, this.connectionID);
10786
10787
  if (this.client.insightMetrics.wsConsecutiveFailures > 0 &&
10787
10788
  this.client.options.enableInsights) {
10788
10789
  postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
@@ -10801,7 +10802,7 @@ class StableWSConnection {
10801
10802
  const insights = buildWsFatalInsight(this, convertErrorToJson(err));
10802
10803
  postInsights === null || postInsights === void 0 ? void 0 : postInsights('ws_fatal', insights);
10803
10804
  }
10804
- this.client.rejectConnectionId();
10805
+ (_d = (_c = this.client).rejectConnectionId) === null || _d === void 0 ? void 0 : _d.call(_c);
10805
10806
  throw err;
10806
10807
  }
10807
10808
  });
@@ -11210,6 +11211,7 @@ class WSConnectionFallback {
11210
11211
  undefined, {
11211
11212
  config: Object.assign(Object.assign({}, config), { cancelToken: (_a = this.cancelToken) === null || _a === void 0 ? void 0 : _a.token }),
11212
11213
  params,
11214
+ publicEndpoint: true,
11213
11215
  });
11214
11216
  this.consecutiveFailures = 0; // always reset in case of no error
11215
11217
  return res;
@@ -11266,6 +11268,7 @@ class WSConnectionFallback {
11266
11268
  * @param reconnect should be false for first call and true for subsequent calls to keep the connection alive and call recoverState
11267
11269
  */
11268
11270
  this.connect = (reconnect = false) => __awaiter(this, void 0, void 0, function* () {
11271
+ var _c, _d, _e, _f;
11269
11272
  if (this.state === ConnectionState.Connecting) {
11270
11273
  this._log('connect() - connecting already in progress', { reconnect }, 'warn');
11271
11274
  return;
@@ -11282,7 +11285,7 @@ class WSConnectionFallback {
11282
11285
  }, reconnect);
11283
11286
  this._setState(ConnectionState.Connected);
11284
11287
  this.connectionID = event.connection_id;
11285
- this.client.resolveConnectionId();
11288
+ (_d = (_c = this.client).resolveConnectionId) === null || _d === void 0 ? void 0 : _d.call(_c);
11286
11289
  // @ts-expect-error
11287
11290
  this.client.dispatchEvent(event);
11288
11291
  this._poll();
@@ -11290,7 +11293,7 @@ class WSConnectionFallback {
11290
11293
  }
11291
11294
  catch (err) {
11292
11295
  this._setState(ConnectionState.Closed);
11293
- this.client.rejectConnectionId();
11296
+ (_f = (_e = this.client).rejectConnectionId) === null || _f === void 0 ? void 0 : _f.call(_e);
11294
11297
  throw err;
11295
11298
  }
11296
11299
  });
@@ -11301,10 +11304,10 @@ class WSConnectionFallback {
11301
11304
  return !!this.connectionID && this.state === ConnectionState.Connected;
11302
11305
  };
11303
11306
  this.disconnect = (timeout = 2000) => __awaiter(this, void 0, void 0, function* () {
11304
- var _c;
11307
+ var _g;
11305
11308
  removeConnectionEventListeners(this._onlineStatusChanged);
11306
11309
  this._setState(ConnectionState.Disconnected);
11307
- (_c = this.cancelToken) === null || _c === void 0 ? void 0 : _c.cancel('disconnect() is called');
11310
+ (_g = this.cancelToken) === null || _g === void 0 ? void 0 : _g.cancel('disconnect() is called');
11308
11311
  this.cancelToken = undefined;
11309
11312
  const connection_id = this.connectionID;
11310
11313
  this.connectionID = undefined;
@@ -11341,7 +11344,7 @@ class WSConnectionFallback {
11341
11344
  }
11342
11345
  }
11343
11346
 
11344
- const version = '0.1.1';
11347
+ const version = '0.1.3';
11345
11348
 
11346
11349
  const logger = getLogger(['location']);
11347
11350
  const HINT_URL = `https://hint.stream-io-video.com/`;
@@ -11518,6 +11521,10 @@ class StreamClient {
11518
11521
  this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists');
11519
11522
  return Promise.resolve();
11520
11523
  }
11524
+ this.connectionIdPromise = new Promise((resolve, reject) => {
11525
+ this.resolveConnectionId = resolve;
11526
+ this.rejectConnectionId = reject;
11527
+ });
11521
11528
  this.clientID = `${this.userID}--${randomId()}`;
11522
11529
  this.wsPromise = this.connect();
11523
11530
  return this.wsPromise;
@@ -11546,11 +11553,19 @@ class StreamClient {
11546
11553
  this.anonymous = false;
11547
11554
  yield this.closeConnection(timeout);
11548
11555
  this.tokenManager.reset();
11556
+ this.connectionIdPromise = undefined;
11557
+ this.rejectConnectionId = undefined;
11558
+ this.resolveConnectionId = undefined;
11549
11559
  });
11550
11560
  /**
11551
11561
  * connectAnonymousUser - Set an anonymous user and open a WebSocket connection
11552
11562
  */
11553
11563
  this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
11564
+ var _g;
11565
+ this.connectionIdPromise = new Promise((resolve, reject) => {
11566
+ this.resolveConnectionId = resolve;
11567
+ this.rejectConnectionId = reject;
11568
+ });
11554
11569
  this.anonymous = true;
11555
11570
  yield this._setToken(user, tokenOrProvider, this.anonymous);
11556
11571
  if (this.resolveConnectPromise) {
@@ -11562,7 +11577,7 @@ class StreamClient {
11562
11577
  // some endpoints require a connection_id to be resolved.
11563
11578
  // as anonymous users aren't allowed to open WS connections, we just
11564
11579
  // resolve the connection_id here.
11565
- this.resolveConnectionId();
11580
+ (_g = this.resolveConnectionId) === null || _g === void 0 ? void 0 : _g.call(this);
11566
11581
  });
11567
11582
  /**
11568
11583
  * on - Listen to events on all channels and users your watching
@@ -11625,8 +11640,8 @@ class StreamClient {
11625
11640
  });
11626
11641
  };
11627
11642
  this.doAxiosRequest = (type, url, data, options = {}) => __awaiter(this, void 0, void 0, function* () {
11628
- var _g;
11629
- if (!options.publicEndpoint || this.user) {
11643
+ var _h;
11644
+ if (!options.publicEndpoint) {
11630
11645
  if (this.waitForConnectPromise) {
11631
11646
  yield this.waitForConnectPromise;
11632
11647
  }
@@ -11667,7 +11682,7 @@ class StreamClient {
11667
11682
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11668
11683
  }
11669
11684
  catch (e /**TODO: generalize error types */) {
11670
- e.client_request_id = (_g = requestConfig.headers) === null || _g === void 0 ? void 0 : _g['x-client-request-id'];
11685
+ e.client_request_id = (_h = requestConfig.headers) === null || _h === void 0 ? void 0 : _h['x-client-request-id'];
11671
11686
  this._logApiError(type, url, e);
11672
11687
  this.consecutiveFailures += 1;
11673
11688
  if (e.response) {
@@ -11932,10 +11947,6 @@ class StreamClient {
11932
11947
  keepAliveMsecs: 3000,
11933
11948
  });
11934
11949
  }
11935
- this.connectionIdPromise = new Promise((resolve, reject) => {
11936
- this.resolveConnectionId = resolve;
11937
- this.rejectConnectionId = reject;
11938
- });
11939
11950
  this.setBaseURL(this.options.baseURL || 'https://video.stream-io-api.com/video');
11940
11951
  if (typeof process !== 'undefined' && process.env.STREAM_LOCAL_TEST_RUN) {
11941
11952
  this.setBaseURL('http://localhost:3030/video');
@@ -12068,22 +12079,6 @@ class StreamVideoClient {
12068
12079
  this.edges = () => __awaiter(this, void 0, void 0, function* () {
12069
12080
  return this.streamClient.get(`/edges`);
12070
12081
  });
12071
- // server-side only endpoints
12072
- this.createCallType = (data) => __awaiter(this, void 0, void 0, function* () {
12073
- return this.streamClient.post(`/calltypes`, data);
12074
- });
12075
- this.getCallType = (name) => __awaiter(this, void 0, void 0, function* () {
12076
- return this.streamClient.get(`/calltypes/${name}`);
12077
- });
12078
- this.updateCallType = (name, data) => __awaiter(this, void 0, void 0, function* () {
12079
- return this.streamClient.put(`/calltypes/${name}`, data);
12080
- });
12081
- this.deleteCallType = (name) => __awaiter(this, void 0, void 0, function* () {
12082
- return this.streamClient.delete(`/calltypes/${name}`);
12083
- });
12084
- this.listCallTypes = () => __awaiter(this, void 0, void 0, function* () {
12085
- return this.streamClient.get(`/calltypes`);
12086
- });
12087
12082
  /**
12088
12083
  * addDevice - Adds a push device for a user.
12089
12084
  *
@@ -12303,6 +12298,27 @@ class StreamVideoClient {
12303
12298
  return yield this.addDevice(id, push_provider, push_provider_name, userID, true);
12304
12299
  });
12305
12300
  }
12301
+ }
12302
+
12303
+ class StreamVideoServerClient extends StreamVideoClient {
12304
+ constructor(apiKey, options) {
12305
+ super({ apiKey, options });
12306
+ this.getCallTypes = () => {
12307
+ return this.streamClient.get('/calltypes');
12308
+ };
12309
+ this.getCallType = (name) => {
12310
+ return this.streamClient.get(`/calltypes/${name}`);
12311
+ };
12312
+ this.createCallType = (data) => {
12313
+ return this.streamClient.post('/calltypes', data);
12314
+ };
12315
+ this.deleteCallType = (name) => {
12316
+ return this.streamClient.delete(`/calltypes/${name}`);
12317
+ };
12318
+ this.updateCallType = (name, data) => {
12319
+ return this.streamClient.put(`/calltypes/${name}`, data);
12320
+ };
12321
+ }
12306
12322
  /**
12307
12323
  * createToken - Creates a token to authenticate this user. This function is used server side.
12308
12324
  * The resulting token should be passed to the client side when the users register or logs in.
@@ -12676,6 +12692,7 @@ exports.SfuModels = models;
12676
12692
  exports.StreamSfuClient = StreamSfuClient;
12677
12693
  exports.StreamVideoClient = StreamVideoClient;
12678
12694
  exports.StreamVideoReadOnlyStateStore = StreamVideoReadOnlyStateStore;
12695
+ exports.StreamVideoServerClient = StreamVideoServerClient;
12679
12696
  exports.StreamVideoWriteableStateStore = StreamVideoWriteableStateStore;
12680
12697
  exports.TranscriptionSettingsModeEnum = TranscriptionSettingsModeEnum;
12681
12698
  exports.TranscriptionSettingsRequestModeEnum = TranscriptionSettingsRequestModeEnum;