@stream-io/video-client 0.1.4 → 0.1.5

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
+ ### [0.1.5](https://github.com/GetStream/stream-video-js/compare/client0.1.4...client0.1.5) (2023-07-21)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * strict mode issue ([#740](https://github.com/GetStream/stream-video-js/issues/740)) ([c39e4e4](https://github.com/GetStream/stream-video-js/commit/c39e4e4041a2326393478ad808b2aa791d50f8ce))
11
+
5
12
  ### [0.1.4](https://github.com/GetStream/stream-video-js/compare/client0.1.3...client0.1.4) (2023-07-21)
6
13
 
7
14
 
@@ -4,7 +4,7 @@ import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
4
4
  import axios, { AxiosHeaders } from 'axios';
5
5
  export { AxiosError } from 'axios';
6
6
  import { TwirpFetchTransport } from '@protobuf-ts/twirp-transport';
7
- import { ReplaySubject, BehaviorSubject, takeWhile, pairwise, tap, debounce, timer, map as map$2, Observable, debounceTime, concatMap, from, shareReplay, merge, combineLatest, filter } from 'rxjs';
7
+ import { ReplaySubject, BehaviorSubject, takeWhile, filter, pairwise, tap, debounce, timer, map as map$2, Observable, debounceTime, concatMap, from, shareReplay, merge, combineLatest } from 'rxjs';
8
8
  import * as SDP from 'sdp-transform';
9
9
  import WebSocket from 'isomorphic-ws';
10
10
  import { take, map as map$1, distinctUntilChanged } from 'rxjs/operators';
@@ -9465,11 +9465,13 @@ class Call {
9465
9465
  */
9466
9466
  this.leave = ({ reject = false } = {}) => __awaiter(this, void 0, void 0, function* () {
9467
9467
  var _a, _b, _c, _d;
9468
- // TODO: handle case when leave is called during JOINING
9469
9468
  const callingState = this.state.callingState;
9470
9469
  if (callingState === CallingState.LEFT) {
9471
9470
  throw new Error('Cannot leave call that has already been left.');
9472
9471
  }
9472
+ if (callingState === CallingState.JOINING) {
9473
+ yield this.assertCallJoined();
9474
+ }
9473
9475
  if (this.ringing) {
9474
9476
  // I'm the one who started the call, so I should cancel it.
9475
9477
  const hasOtherParticipants = this.state.remoteParticipants.length > 0;
@@ -9875,13 +9877,6 @@ class Call {
9875
9877
  }, timeout);
9876
9878
  });
9877
9879
  };
9878
- this.assertCallJoined = () => {
9879
- return new Promise((resolve) => {
9880
- this.state.callingState$
9881
- .pipe(takeWhile((state) => state !== CallingState.JOINED, true))
9882
- .subscribe(() => resolve());
9883
- });
9884
- };
9885
9880
  /**
9886
9881
  * Starts publishing the given video stream to the call.
9887
9882
  * The stream will be stopped if the user changes an input device, or if the user leaves the call.
@@ -10112,6 +10107,13 @@ class Call {
10112
10107
  var _h;
10113
10108
  return (_h = this.publisher) === null || _h === void 0 ? void 0 : _h.updateVideoPublishQuality(enabledRids);
10114
10109
  });
10110
+ this.assertCallJoined = () => {
10111
+ return new Promise((resolve) => {
10112
+ this.state.callingState$
10113
+ .pipe(takeWhile((state) => state !== CallingState.JOINED, true), filter((s) => s === CallingState.JOINED))
10114
+ .subscribe(() => resolve());
10115
+ });
10116
+ };
10115
10117
  /**
10116
10118
  * Sends a reaction to the other call participants.
10117
10119
  *
@@ -11634,7 +11636,7 @@ class WSConnectionFallback {
11634
11636
  }
11635
11637
  }
11636
11638
 
11637
- const version = '0.1.4';
11639
+ const version = '0.1.5';
11638
11640
 
11639
11641
  const logger = getLogger(['location']);
11640
11642
  const HINT_URL = `https://hint.stream-io-video.com/`;
@@ -11697,14 +11699,6 @@ class StreamClient {
11697
11699
  });
11698
11700
  this._getConnectionID = () => { var _a, _b; return ((_a = this.wsConnection) === null || _a === void 0 ? void 0 : _a.connectionID) || ((_b = this.wsFallback) === null || _b === void 0 ? void 0 : _b.connectionID); };
11699
11701
  this._hasConnectionID = () => Boolean(this._getConnectionID());
11700
- /**
11701
- * This will start a promise to hold API calls until `connectUser` is called, useful when user is set in `StreamVideoClient constructor`
11702
- */
11703
- this.startWaitingForConnection = () => {
11704
- this.waitForConnectPromise = new Promise((resolve) => {
11705
- this.resolveConnectPromise = resolve;
11706
- });
11707
- };
11708
11702
  /**
11709
11703
  * connectUser - Set the current user and open a WebSocket connection
11710
11704
  *
@@ -11739,11 +11733,6 @@ class StreamClient {
11739
11733
  this._setUser(user);
11740
11734
  const wsPromise = this.openConnection();
11741
11735
  this.setUserPromise = Promise.all([setTokenPromise, wsPromise]).then((result) => result[1]);
11742
- if (this.resolveConnectPromise) {
11743
- this.resolveConnectPromise();
11744
- this.waitForConnectPromise = undefined;
11745
- this.resolveConnectPromise = undefined;
11746
- }
11747
11736
  try {
11748
11737
  return yield this.setUserPromise;
11749
11738
  }
@@ -11858,11 +11847,6 @@ class StreamClient {
11858
11847
  });
11859
11848
  this.anonymous = true;
11860
11849
  yield this._setToken(user, tokenOrProvider, this.anonymous);
11861
- if (this.resolveConnectPromise) {
11862
- this.resolveConnectPromise();
11863
- this.waitForConnectPromise = undefined;
11864
- this.resolveConnectPromise = undefined;
11865
- }
11866
11850
  this._setUser(user);
11867
11851
  // some endpoints require a connection_id to be resolved.
11868
11852
  // as anonymous users aren't allowed to open WS connections, we just
@@ -11932,9 +11916,6 @@ class StreamClient {
11932
11916
  this.doAxiosRequest = (type, url, data, options = {}) => __awaiter(this, void 0, void 0, function* () {
11933
11917
  var _h;
11934
11918
  if (!options.publicEndpoint) {
11935
- if (this.waitForConnectPromise) {
11936
- yield this.waitForConnectPromise;
11937
- }
11938
11919
  yield Promise.all([
11939
11920
  this.tokenManager.tokenReady(),
11940
11921
  this.connectionIdPromise,
@@ -12272,6 +12253,7 @@ class StreamClient {
12272
12253
  class StreamVideoClient {
12273
12254
  constructor(apiKeyOrArgs, opts) {
12274
12255
  var _a, _b;
12256
+ this.logLevel = 'warn';
12275
12257
  this.eventHandlersToUnregister = [];
12276
12258
  /**
12277
12259
  * Disconnects the currently connected user from the client.
@@ -12282,7 +12264,7 @@ class StreamVideoClient {
12282
12264
  * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
12283
12265
  */
12284
12266
  this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
12285
- if (!this.streamClient.user) {
12267
+ if (!this.streamClient.user && !this.connectionPromise) {
12286
12268
  return;
12287
12269
  }
12288
12270
  const disconnectUser = () => this.streamClient.disconnectUser(timeout);
@@ -12459,14 +12441,16 @@ class StreamVideoClient {
12459
12441
  this.streamClient.setUserAgent(this.streamClient.getUserAgent() +
12460
12442
  `-video-${SdkType[sdkInfo.type].toLowerCase()}-sdk-${sdkInfo.major}.${sdkInfo.minor}.${sdkInfo.patch}`);
12461
12443
  }
12462
- this.user = apiKeyOrArgs.user;
12463
- this.token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
12464
- if (this.user) {
12465
- this.streamClient.startWaitingForConnection();
12466
- }
12467
12444
  }
12468
12445
  this.writeableStateStore = new StreamVideoWriteableStateStore();
12469
12446
  this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
12447
+ if (typeof apiKeyOrArgs !== 'string') {
12448
+ const user = apiKeyOrArgs.user;
12449
+ const token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
12450
+ if (user) {
12451
+ this.connectUser(user, token);
12452
+ }
12453
+ }
12470
12454
  }
12471
12455
  /**
12472
12456
  * Connects the given user to the client.
@@ -12479,24 +12463,21 @@ class StreamVideoClient {
12479
12463
  connectUser(user, token) {
12480
12464
  var _a;
12481
12465
  return __awaiter(this, void 0, void 0, function* () {
12482
- const userToConnect = user || this.user;
12483
- const tokenToUse = token || this.token;
12484
- if (!userToConnect) {
12485
- throw new Error('Connect user is called without user');
12486
- }
12487
- if (userToConnect.type === 'anonymous') {
12488
- userToConnect.id = '!anon';
12489
- return this.connectAnonymousUser(userToConnect, tokenToUse);
12490
- }
12491
- if (userToConnect.type === 'guest') {
12492
- const response = yield this.createGuestUser({
12493
- user: Object.assign(Object.assign({}, userToConnect), { role: 'guest' }),
12494
- });
12495
- return this.connectUser(response.user, response.access_token);
12466
+ if (user.type === 'anonymous') {
12467
+ user.id = '!anon';
12468
+ return this.connectAnonymousUser(user, token);
12496
12469
  }
12497
- const connectUser = () => {
12498
- return this.streamClient.connectUser(userToConnect, tokenToUse);
12470
+ let connectUser = () => {
12471
+ return this.streamClient.connectUser(user, token);
12499
12472
  };
12473
+ if (user.type === 'guest') {
12474
+ connectUser = () => __awaiter(this, void 0, void 0, function* () {
12475
+ const response = yield this.createGuestUser({
12476
+ user: Object.assign(Object.assign({}, user), { role: 'guest' }),
12477
+ });
12478
+ return this.streamClient.connectUser(response.user, response.access_token);
12479
+ });
12480
+ }
12500
12481
  this.connectionPromise = this.disconnectionPromise
12501
12482
  ? this.disconnectionPromise.then(() => connectUser())
12502
12483
  : connectUser();
@@ -12530,7 +12511,7 @@ class StreamVideoClient {
12530
12511
  if (event.type !== 'call.created')
12531
12512
  return;
12532
12513
  const { call, members } = event;
12533
- if (userToConnect.id === call.created_by.id) {
12514
+ if (user.id === call.created_by.id) {
12534
12515
  this.logger('warn', 'Received `call.created` sent by the current user');
12535
12516
  return;
12536
12517
  }
@@ -12548,7 +12529,7 @@ class StreamVideoClient {
12548
12529
  if (event.type !== 'call.ring')
12549
12530
  return;
12550
12531
  const { call, members } = event;
12551
- if (userToConnect.id === call.created_by.id) {
12532
+ if (user.id === call.created_by.id) {
12552
12533
  this.logger('debug', 'Received `call.ring` sent by the current user so ignoring the event');
12553
12534
  return;
12554
12535
  }