@stream-io/video-client 0.0.5 → 0.0.7

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,20 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ### [0.0.7](https://github.com/GetStream/stream-video-js/compare/client0.0.6...client0.0.7) (2023-06-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * StreamCall signature, video client creation ([#596](https://github.com/GetStream/stream-video-js/issues/596)) ([5c3000c](https://github.com/GetStream/stream-video-js/commit/5c3000cc6fc3f8b7904609d7b11fa025b7458cad))
11
+
12
+ ### [0.0.6](https://github.com/GetStream/stream-video-js/compare/client0.0.5...client0.0.6) (2023-06-07)
13
+
14
+
15
+ ### Features
16
+
17
+ * Add token creation to client ([#607](https://github.com/GetStream/stream-video-js/issues/607)) ([5f95420](https://github.com/GetStream/stream-video-js/commit/5f9542029a64ddaf6ee7912ea7b364fc74c93bf0))
18
+
5
19
  ### [0.0.5](https://github.com/GetStream/stream-video-js/compare/client0.0.4...client0.0.5) (2023-06-06)
6
20
 
7
21
 
@@ -10993,7 +10993,7 @@ class StreamClient {
10993
10993
  }
10994
10994
  getUserAgent() {
10995
10995
  return (this.userAgent ||
10996
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.4"}`);
10996
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.6"}`);
10997
10997
  }
10998
10998
  setUserAgent(userAgent) {
10999
10999
  this.userAgent = userAgent;
@@ -11027,6 +11027,32 @@ class StreamClient {
11027
11027
  createAbortControllerForNextRequest() {
11028
11028
  return (this.nextRequestAbortController = new AbortController());
11029
11029
  }
11030
+ /**
11031
+ * createToken - Creates a token to authenticate this user. This function is used server side.
11032
+ * The resulting token should be passed to the client side when the users registers or logs in.
11033
+ *
11034
+ * @param {string} userID The User ID
11035
+ * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
11036
+ * @param call_cids for anonymous tokens you have to provide the call cids the use can join
11037
+ *
11038
+ * @return {string} Returns a token
11039
+ */
11040
+ createToken(userID, exp, iat, call_cids) {
11041
+ if (this.secret == null) {
11042
+ throw Error(`tokens can only be created server-side using the API Secret`);
11043
+ }
11044
+ const extra = {};
11045
+ if (exp) {
11046
+ extra.exp = exp;
11047
+ }
11048
+ if (iat) {
11049
+ extra.iat = iat;
11050
+ }
11051
+ if (call_cids) {
11052
+ extra.call_cids = call_cids;
11053
+ }
11054
+ return JWTUserToken(this.secret, userID, extra, {});
11055
+ }
11030
11056
  }
11031
11057
 
11032
11058
  /**
@@ -11049,9 +11075,17 @@ class StreamVideoClient {
11049
11075
  * @param tokenOrProvider a token or a function that returns a token.
11050
11076
  */
11051
11077
  this.connectUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
11052
- const connectUserResponse = yield this.streamClient.connectUser(
11053
- // @ts-expect-error
11054
- user, tokenOrProvider);
11078
+ var _a;
11079
+ const connectUser = () => {
11080
+ return this.streamClient.connectUser(
11081
+ // @ts-expect-error
11082
+ user, tokenOrProvider);
11083
+ };
11084
+ this.connectionPromise = this.disconnectionPromise
11085
+ ? this.disconnectionPromise.then(() => connectUser())
11086
+ : connectUser();
11087
+ (_a = this.connectionPromise) === null || _a === void 0 ? void 0 : _a.finally(() => (this.connectionPromise = undefined));
11088
+ const connectUserResponse = yield this.connectionPromise;
11055
11089
  this.writeableStateStore.setConnectedUser(user);
11056
11090
  this.eventHandlersToUnregister.push(this.on('connection.changed', (e) => {
11057
11091
  const event = e;
@@ -11125,8 +11159,14 @@ class StreamVideoClient {
11125
11159
  * @param tokenOrProvider a token or a function that returns a token.
11126
11160
  */
11127
11161
  this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
11162
+ const connectAnonymousUser = () =>
11128
11163
  // @ts-expect-error
11129
- return this.streamClient.connectAnonymousUser(user, tokenOrProvider);
11164
+ this.streamClient.connectAnonymousUser(user, tokenOrProvider);
11165
+ this.connectionPromise = this.disconnectionPromise
11166
+ ? this.disconnectionPromise.then(() => connectAnonymousUser())
11167
+ : connectAnonymousUser();
11168
+ this.connectionPromise.finally(() => (this.connectionPromise = undefined));
11169
+ return this.connectionPromise;
11130
11170
  });
11131
11171
  /**
11132
11172
  * Disconnects the currently connected user from the client.
@@ -11137,7 +11177,12 @@ class StreamVideoClient {
11137
11177
  * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
11138
11178
  */
11139
11179
  this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
11140
- yield this.streamClient.disconnectUser(timeout);
11180
+ const disconnectUser = () => this.streamClient.disconnectUser(timeout);
11181
+ this.disconnectionPromise = this.connectionPromise
11182
+ ? this.connectionPromise.then(() => disconnectUser())
11183
+ : disconnectUser();
11184
+ this.disconnectionPromise.finally(() => (this.disconnectionPromise = undefined));
11185
+ yield this.disconnectionPromise;
11141
11186
  this.eventHandlersToUnregister.forEach((unregister) => unregister());
11142
11187
  this.eventHandlersToUnregister = [];
11143
11188
  this.writeableStateStore.setConnectedUser(undefined);
@@ -11264,9 +11309,7 @@ class StreamVideoClient {
11264
11309
  this.removeDevice = (id, userID) => __awaiter(this, void 0, void 0, function* () {
11265
11310
  return yield this.streamClient.delete('/devices', Object.assign({ id }, (userID ? { user_id: userID } : {})));
11266
11311
  });
11267
- this.streamClient = new StreamClient(apiKey, Object.assign({
11268
- // FIXME: OL: fix SSR.
11269
- browser: true, persistUserOnConnectionFailure: true }, opts));
11312
+ this.streamClient = new StreamClient(apiKey, Object.assign({ persistUserOnConnectionFailure: true }, opts));
11270
11313
  this.writeableStateStore = new StreamVideoWriteableStateStore();
11271
11314
  this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
11272
11315
  }
@@ -11283,6 +11326,19 @@ class StreamVideoClient {
11283
11326
  return yield this.addDevice(id, push_provider, push_provider_name, userID, true);
11284
11327
  });
11285
11328
  }
11329
+ /**
11330
+ * createToken - Creates a token to authenticate this user. This function is used server side.
11331
+ * The resulting token should be passed to the client side when the users registers or logs in.
11332
+ *
11333
+ * @param {string} userID The User ID
11334
+ * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
11335
+ * @param call_cids for anonymous tokens you have to provide the call cids the use can join
11336
+ *
11337
+ * @return {string} Returns a token
11338
+ */
11339
+ createToken(userID, exp, iat, call_cids) {
11340
+ return this.streamClient.createToken(userID, exp, iat, call_cids);
11341
+ }
11286
11342
  }
11287
11343
 
11288
11344
  const getDevices = (constraints) => {