@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 +14 -0
- package/dist/index.browser.es.js +65 -9
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +65 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +65 -9
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamVideoClient.d.ts +16 -3
- package/dist/src/coordinator/connection/client.d.ts +11 -0
- package/package.json +1 -1
- package/src/StreamVideoClient.ts +51 -10
- package/src/coordinator/connection/client.ts +39 -1
package/dist/index.es.js
CHANGED
|
@@ -10997,7 +10997,7 @@ class StreamClient {
|
|
|
10997
10997
|
}
|
|
10998
10998
|
getUserAgent() {
|
|
10999
10999
|
return (this.userAgent ||
|
|
11000
|
-
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.
|
|
11000
|
+
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.6"}`);
|
|
11001
11001
|
}
|
|
11002
11002
|
setUserAgent(userAgent) {
|
|
11003
11003
|
this.userAgent = userAgent;
|
|
@@ -11031,6 +11031,32 @@ class StreamClient {
|
|
|
11031
11031
|
createAbortControllerForNextRequest() {
|
|
11032
11032
|
return (this.nextRequestAbortController = new AbortController());
|
|
11033
11033
|
}
|
|
11034
|
+
/**
|
|
11035
|
+
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
11036
|
+
* The resulting token should be passed to the client side when the users registers or logs in.
|
|
11037
|
+
*
|
|
11038
|
+
* @param {string} userID The User ID
|
|
11039
|
+
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
11040
|
+
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
11041
|
+
*
|
|
11042
|
+
* @return {string} Returns a token
|
|
11043
|
+
*/
|
|
11044
|
+
createToken(userID, exp, iat, call_cids) {
|
|
11045
|
+
if (this.secret == null) {
|
|
11046
|
+
throw Error(`tokens can only be created server-side using the API Secret`);
|
|
11047
|
+
}
|
|
11048
|
+
const extra = {};
|
|
11049
|
+
if (exp) {
|
|
11050
|
+
extra.exp = exp;
|
|
11051
|
+
}
|
|
11052
|
+
if (iat) {
|
|
11053
|
+
extra.iat = iat;
|
|
11054
|
+
}
|
|
11055
|
+
if (call_cids) {
|
|
11056
|
+
extra.call_cids = call_cids;
|
|
11057
|
+
}
|
|
11058
|
+
return JWTUserToken(this.secret, userID, extra, {});
|
|
11059
|
+
}
|
|
11034
11060
|
}
|
|
11035
11061
|
|
|
11036
11062
|
/**
|
|
@@ -11053,9 +11079,17 @@ class StreamVideoClient {
|
|
|
11053
11079
|
* @param tokenOrProvider a token or a function that returns a token.
|
|
11054
11080
|
*/
|
|
11055
11081
|
this.connectUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11082
|
+
var _a;
|
|
11083
|
+
const connectUser = () => {
|
|
11084
|
+
return this.streamClient.connectUser(
|
|
11085
|
+
// @ts-expect-error
|
|
11086
|
+
user, tokenOrProvider);
|
|
11087
|
+
};
|
|
11088
|
+
this.connectionPromise = this.disconnectionPromise
|
|
11089
|
+
? this.disconnectionPromise.then(() => connectUser())
|
|
11090
|
+
: connectUser();
|
|
11091
|
+
(_a = this.connectionPromise) === null || _a === void 0 ? void 0 : _a.finally(() => (this.connectionPromise = undefined));
|
|
11092
|
+
const connectUserResponse = yield this.connectionPromise;
|
|
11059
11093
|
this.writeableStateStore.setConnectedUser(user);
|
|
11060
11094
|
this.eventHandlersToUnregister.push(this.on('connection.changed', (e) => {
|
|
11061
11095
|
const event = e;
|
|
@@ -11129,8 +11163,14 @@ class StreamVideoClient {
|
|
|
11129
11163
|
* @param tokenOrProvider a token or a function that returns a token.
|
|
11130
11164
|
*/
|
|
11131
11165
|
this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
11166
|
+
const connectAnonymousUser = () =>
|
|
11132
11167
|
// @ts-expect-error
|
|
11133
|
-
|
|
11168
|
+
this.streamClient.connectAnonymousUser(user, tokenOrProvider);
|
|
11169
|
+
this.connectionPromise = this.disconnectionPromise
|
|
11170
|
+
? this.disconnectionPromise.then(() => connectAnonymousUser())
|
|
11171
|
+
: connectAnonymousUser();
|
|
11172
|
+
this.connectionPromise.finally(() => (this.connectionPromise = undefined));
|
|
11173
|
+
return this.connectionPromise;
|
|
11134
11174
|
});
|
|
11135
11175
|
/**
|
|
11136
11176
|
* Disconnects the currently connected user from the client.
|
|
@@ -11141,7 +11181,12 @@ class StreamVideoClient {
|
|
|
11141
11181
|
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
11142
11182
|
*/
|
|
11143
11183
|
this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
11144
|
-
|
|
11184
|
+
const disconnectUser = () => this.streamClient.disconnectUser(timeout);
|
|
11185
|
+
this.disconnectionPromise = this.connectionPromise
|
|
11186
|
+
? this.connectionPromise.then(() => disconnectUser())
|
|
11187
|
+
: disconnectUser();
|
|
11188
|
+
this.disconnectionPromise.finally(() => (this.disconnectionPromise = undefined));
|
|
11189
|
+
yield this.disconnectionPromise;
|
|
11145
11190
|
this.eventHandlersToUnregister.forEach((unregister) => unregister());
|
|
11146
11191
|
this.eventHandlersToUnregister = [];
|
|
11147
11192
|
this.writeableStateStore.setConnectedUser(undefined);
|
|
@@ -11268,9 +11313,7 @@ class StreamVideoClient {
|
|
|
11268
11313
|
this.removeDevice = (id, userID) => __awaiter(this, void 0, void 0, function* () {
|
|
11269
11314
|
return yield this.streamClient.delete('/devices', Object.assign({ id }, (userID ? { user_id: userID } : {})));
|
|
11270
11315
|
});
|
|
11271
|
-
this.streamClient = new StreamClient(apiKey, Object.assign({
|
|
11272
|
-
// FIXME: OL: fix SSR.
|
|
11273
|
-
browser: true, persistUserOnConnectionFailure: true }, opts));
|
|
11316
|
+
this.streamClient = new StreamClient(apiKey, Object.assign({ persistUserOnConnectionFailure: true }, opts));
|
|
11274
11317
|
this.writeableStateStore = new StreamVideoWriteableStateStore();
|
|
11275
11318
|
this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
|
|
11276
11319
|
}
|
|
@@ -11287,6 +11330,19 @@ class StreamVideoClient {
|
|
|
11287
11330
|
return yield this.addDevice(id, push_provider, push_provider_name, userID, true);
|
|
11288
11331
|
});
|
|
11289
11332
|
}
|
|
11333
|
+
/**
|
|
11334
|
+
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
11335
|
+
* The resulting token should be passed to the client side when the users registers or logs in.
|
|
11336
|
+
*
|
|
11337
|
+
* @param {string} userID The User ID
|
|
11338
|
+
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
11339
|
+
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
11340
|
+
*
|
|
11341
|
+
* @return {string} Returns a token
|
|
11342
|
+
*/
|
|
11343
|
+
createToken(userID, exp, iat, call_cids) {
|
|
11344
|
+
return this.streamClient.createToken(userID, exp, iat, call_cids);
|
|
11345
|
+
}
|
|
11290
11346
|
}
|
|
11291
11347
|
|
|
11292
11348
|
const getDevices = (constraints) => {
|