@stream-io/video-client 0.0.9 → 0.0.11
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 +126 -111
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +126 -111
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +126 -111
- package/dist/index.es.js.map +1 -1
- package/dist/src/Call.d.ts +4 -4
- package/dist/src/StreamVideoClient.d.ts +8 -8
- package/dist/src/coordinator/connection/client.d.ts +13 -9
- package/dist/src/coordinator/connection/insights.d.ts +2 -2
- package/dist/src/coordinator/connection/token_manager.d.ts +4 -4
- package/dist/src/coordinator/connection/types.d.ts +17 -12
- package/dist/src/store/stateStore.d.ts +6 -6
- package/package.json +3 -3
- package/src/Call.ts +4 -4
- package/src/StreamVideoClient.ts +47 -32
- package/src/coordinator/connection/client.ts +23 -15
- package/src/coordinator/connection/token_manager.ts +5 -5
- package/src/coordinator/connection/types.ts +16 -10
- package/src/events/__tests__/call.test.ts +6 -0
- package/src/store/stateStore.ts +8 -6
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.11](https://github.com/GetStream/stream-video-js/compare/client0.0.10...client0.0.11) (2023-06-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add audio room demo app ([#572](https://github.com/GetStream/stream-video-js/issues/572)) ([77f7b65](https://github.com/GetStream/stream-video-js/commit/77f7b6596047d59e10c8e58abad38c4f48cc162f))
|
|
11
|
+
|
|
12
|
+
### [0.0.10](https://github.com/GetStream/stream-video-js/compare/client0.0.9...client0.0.10) (2023-06-12)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* User connect and types ([#627](https://github.com/GetStream/stream-video-js/issues/627)) ([721ef61](https://github.com/GetStream/stream-video-js/commit/721ef611374540ef570a516009c78d58ce4f5360))
|
|
18
|
+
|
|
5
19
|
### [0.0.9](https://github.com/GetStream/stream-video-js/compare/client0.0.8...client0.0.9) (2023-06-12)
|
|
6
20
|
|
|
7
21
|
|
package/dist/index.browser.es.js
CHANGED
|
@@ -10217,7 +10217,7 @@ class TokenManager {
|
|
|
10217
10217
|
return;
|
|
10218
10218
|
// Don't allow empty token for non-server side client.
|
|
10219
10219
|
if (!this.secret && !tokenOrProvider) {
|
|
10220
|
-
throw new Error('
|
|
10220
|
+
throw new Error('UserWithId token can not be empty');
|
|
10221
10221
|
}
|
|
10222
10222
|
if (tokenOrProvider &&
|
|
10223
10223
|
typeof tokenOrProvider !== 'string' &&
|
|
@@ -10530,7 +10530,7 @@ class StreamClient {
|
|
|
10530
10530
|
/**
|
|
10531
10531
|
* connectUser - Set the current user and open a WebSocket connection
|
|
10532
10532
|
*
|
|
10533
|
-
* @param
|
|
10533
|
+
* @param user Data about this user. IE {name: "john"}
|
|
10534
10534
|
* @param {TokenOrProvider} userTokenOrProvider Token or provider
|
|
10535
10535
|
*
|
|
10536
10536
|
* @return {ConnectAPIResponse} Returns a promise that resolves when the connection is setup
|
|
@@ -10607,7 +10607,7 @@ class StreamClient {
|
|
|
10607
10607
|
this.openConnection = () => __awaiter(this, void 0, void 0, function* () {
|
|
10608
10608
|
var _d, _e, _f;
|
|
10609
10609
|
if (!this.userID) {
|
|
10610
|
-
throw Error('
|
|
10610
|
+
throw Error('UserWithId is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
10611
10611
|
}
|
|
10612
10612
|
if (((_d = this.wsConnection) === null || _d === void 0 ? void 0 : _d.isConnecting) && this.wsPromise) {
|
|
10613
10613
|
this.logger('info', 'client:openConnection() - connection already in progress', {
|
|
@@ -10667,7 +10667,9 @@ class StreamClient {
|
|
|
10667
10667
|
});
|
|
10668
10668
|
this.doAxiosRequest = (type, url, data, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
10669
10669
|
var _g;
|
|
10670
|
-
|
|
10670
|
+
if (!options.publicEndpoint || this.user) {
|
|
10671
|
+
yield this.tokenManager.tokenReady();
|
|
10672
|
+
}
|
|
10671
10673
|
const requestConfig = this._enrichAxiosOptions(options);
|
|
10672
10674
|
try {
|
|
10673
10675
|
let response;
|
|
@@ -11020,7 +11022,7 @@ class StreamClient {
|
|
|
11020
11022
|
}
|
|
11021
11023
|
getUserAgent() {
|
|
11022
11024
|
return (this.userAgent ||
|
|
11023
|
-
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.
|
|
11025
|
+
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.10"}`);
|
|
11024
11026
|
}
|
|
11025
11027
|
setUserAgent(userAgent) {
|
|
11026
11028
|
this.userAgent = userAgent;
|
|
@@ -11031,7 +11033,7 @@ class StreamClient {
|
|
|
11031
11033
|
config: {},
|
|
11032
11034
|
}) {
|
|
11033
11035
|
var _a;
|
|
11034
|
-
const token = this._getToken();
|
|
11036
|
+
const token = options.publicEndpoint && !this.user ? undefined : this._getToken();
|
|
11035
11037
|
const authorization = token ? { Authorization: token } : undefined;
|
|
11036
11038
|
let signal = null;
|
|
11037
11039
|
if (this.nextRequestAbortController !== null) {
|
|
@@ -11041,7 +11043,9 @@ class StreamClient {
|
|
|
11041
11043
|
if (!((_a = options.headers) === null || _a === void 0 ? void 0 : _a['x-client-request-id'])) {
|
|
11042
11044
|
options.headers = Object.assign(Object.assign({}, options.headers), { 'x-client-request-id': randomId() });
|
|
11043
11045
|
}
|
|
11044
|
-
return Object.assign(Object.assign(Object.assign({ params: Object.assign({ user_id: this.userID, connection_id: this._getConnectionID(), api_key: this.key }, options.params), headers: Object.assign(Object.assign(Object.assign({}, authorization), { 'stream-auth-type':
|
|
11046
|
+
return Object.assign(Object.assign(Object.assign({ params: Object.assign({ user_id: this.userID, connection_id: this._getConnectionID(), api_key: this.key }, options.params), headers: Object.assign(Object.assign(Object.assign({}, authorization), { 'stream-auth-type': options.publicEndpoint && !this.user
|
|
11047
|
+
? 'anonymous'
|
|
11048
|
+
: this.getAuthType(), 'X-Stream-Client': this.getUserAgent() }), options.headers) }, (signal ? { signal } : {})), options.config), this.options.axiosRequestConfig);
|
|
11045
11049
|
}
|
|
11046
11050
|
_getToken() {
|
|
11047
11051
|
if (!this.tokenManager)
|
|
@@ -11058,7 +11062,7 @@ class StreamClient {
|
|
|
11058
11062
|
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
11059
11063
|
* The resulting token should be passed to the client side when the users registers or logs in.
|
|
11060
11064
|
*
|
|
11061
|
-
* @param {string} userID The
|
|
11065
|
+
* @param {string} userID The UserWithId ID
|
|
11062
11066
|
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
11063
11067
|
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
11064
11068
|
*
|
|
@@ -11093,108 +11097,6 @@ class StreamVideoClient {
|
|
|
11093
11097
|
*/
|
|
11094
11098
|
constructor(apiKey, opts) {
|
|
11095
11099
|
this.eventHandlersToUnregister = [];
|
|
11096
|
-
/**
|
|
11097
|
-
* Connects the given user to the client.
|
|
11098
|
-
* Only one user can connect at a time, if you want to change users, call `disconnectUser` before connecting a new user.
|
|
11099
|
-
* If the connection is successful, the connected user [state variable](#readonlystatestore) will be updated accordingly.
|
|
11100
|
-
*
|
|
11101
|
-
* @param user the user to connect.
|
|
11102
|
-
* @param tokenOrProvider a token or a function that returns a token.
|
|
11103
|
-
*/
|
|
11104
|
-
this.connectUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
11105
|
-
var _a;
|
|
11106
|
-
const connectUser = () => {
|
|
11107
|
-
return this.streamClient.connectUser(
|
|
11108
|
-
// @ts-expect-error
|
|
11109
|
-
user, tokenOrProvider);
|
|
11110
|
-
};
|
|
11111
|
-
this.connectionPromise = this.disconnectionPromise
|
|
11112
|
-
? this.disconnectionPromise.then(() => connectUser())
|
|
11113
|
-
: connectUser();
|
|
11114
|
-
(_a = this.connectionPromise) === null || _a === void 0 ? void 0 : _a.finally(() => (this.connectionPromise = undefined));
|
|
11115
|
-
const connectUserResponse = yield this.connectionPromise;
|
|
11116
|
-
this.writeableStateStore.setConnectedUser(user);
|
|
11117
|
-
this.eventHandlersToUnregister.push(this.on('connection.changed', (e) => {
|
|
11118
|
-
const event = e;
|
|
11119
|
-
if (event.online) {
|
|
11120
|
-
const callsToReWatch = this.writeableStateStore.calls
|
|
11121
|
-
.filter((call) => call.watching)
|
|
11122
|
-
.map((call) => call.cid);
|
|
11123
|
-
if (callsToReWatch.length > 0) {
|
|
11124
|
-
this.queryCalls({
|
|
11125
|
-
watch: true,
|
|
11126
|
-
filter_conditions: {
|
|
11127
|
-
cid: { $in: callsToReWatch },
|
|
11128
|
-
},
|
|
11129
|
-
sort: [{ field: 'cid', direction: 1 }],
|
|
11130
|
-
}).catch((err) => {
|
|
11131
|
-
console.warn('Failed to re-watch calls', err);
|
|
11132
|
-
});
|
|
11133
|
-
}
|
|
11134
|
-
}
|
|
11135
|
-
}));
|
|
11136
|
-
this.eventHandlersToUnregister.push(this.on('call.created', (event) => {
|
|
11137
|
-
if (event.type !== 'call.created')
|
|
11138
|
-
return;
|
|
11139
|
-
const { call, members } = event;
|
|
11140
|
-
if (user.id === call.created_by.id) {
|
|
11141
|
-
console.warn('Received `call.created` sent by the current user');
|
|
11142
|
-
return;
|
|
11143
|
-
}
|
|
11144
|
-
this.writeableStateStore.registerCall(new Call({
|
|
11145
|
-
streamClient: this.streamClient,
|
|
11146
|
-
type: call.type,
|
|
11147
|
-
id: call.id,
|
|
11148
|
-
metadata: call,
|
|
11149
|
-
members,
|
|
11150
|
-
clientStore: this.writeableStateStore,
|
|
11151
|
-
}));
|
|
11152
|
-
}));
|
|
11153
|
-
this.eventHandlersToUnregister.push(this.on('call.ring', (event) => __awaiter(this, void 0, void 0, function* () {
|
|
11154
|
-
if (event.type !== 'call.ring')
|
|
11155
|
-
return;
|
|
11156
|
-
const { call, members } = event;
|
|
11157
|
-
if (user.id === call.created_by.id) {
|
|
11158
|
-
console.warn('Received `call.ring` sent by the current user');
|
|
11159
|
-
return;
|
|
11160
|
-
}
|
|
11161
|
-
// The call might already be tracked by the client,
|
|
11162
|
-
// if `call.created` was received before `call.ring`.
|
|
11163
|
-
// In that case, we just reuse the already tracked call.
|
|
11164
|
-
let theCall = this.writeableStateStore.findCall(call.type, call.id);
|
|
11165
|
-
if (!theCall) {
|
|
11166
|
-
// otherwise, we create a new call
|
|
11167
|
-
theCall = new Call({
|
|
11168
|
-
streamClient: this.streamClient,
|
|
11169
|
-
type: call.type,
|
|
11170
|
-
id: call.id,
|
|
11171
|
-
members,
|
|
11172
|
-
clientStore: this.writeableStateStore,
|
|
11173
|
-
ringing: true,
|
|
11174
|
-
});
|
|
11175
|
-
}
|
|
11176
|
-
// we fetch the latest metadata for the call from the server
|
|
11177
|
-
yield theCall.get({ ring: true });
|
|
11178
|
-
this.writeableStateStore.registerCall(theCall);
|
|
11179
|
-
})));
|
|
11180
|
-
return connectUserResponse;
|
|
11181
|
-
});
|
|
11182
|
-
/**
|
|
11183
|
-
* Connects the given anonymous user to the client.
|
|
11184
|
-
*
|
|
11185
|
-
* @param user the user to connect.
|
|
11186
|
-
* @param tokenOrProvider a token or a function that returns a token.
|
|
11187
|
-
*/
|
|
11188
|
-
this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
11189
|
-
const connectAnonymousUser = () =>
|
|
11190
|
-
// @ts-expect-error
|
|
11191
|
-
this.streamClient.connectAnonymousUser(user, tokenOrProvider);
|
|
11192
|
-
this.connectionPromise = this.disconnectionPromise
|
|
11193
|
-
? this.disconnectionPromise.then(() => connectAnonymousUser())
|
|
11194
|
-
: connectAnonymousUser();
|
|
11195
|
-
this.connectionPromise.finally(() => (this.connectionPromise = undefined));
|
|
11196
|
-
return this.connectionPromise;
|
|
11197
|
-
});
|
|
11198
11100
|
/**
|
|
11199
11101
|
* Disconnects the currently connected user from the client.
|
|
11200
11102
|
*
|
|
@@ -11255,7 +11157,7 @@ class StreamVideoClient {
|
|
|
11255
11157
|
* @param data the data for the guest user.
|
|
11256
11158
|
*/
|
|
11257
11159
|
this.createGuestUser = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
11258
|
-
return this.streamClient.
|
|
11160
|
+
return this.streamClient.doAxiosRequest('post', '/guest', data, { publicEndpoint: true });
|
|
11259
11161
|
});
|
|
11260
11162
|
/**
|
|
11261
11163
|
* Will query the API for calls matching the given filters.
|
|
@@ -11336,10 +11238,123 @@ class StreamVideoClient {
|
|
|
11336
11238
|
this.removeDevice = (id, userID) => __awaiter(this, void 0, void 0, function* () {
|
|
11337
11239
|
return yield this.streamClient.delete('/devices', Object.assign({ id }, (userID ? { user_id: userID } : {})));
|
|
11338
11240
|
});
|
|
11241
|
+
/**
|
|
11242
|
+
* Connects the given anonymous user to the client.
|
|
11243
|
+
*
|
|
11244
|
+
* @param user the user to connect.
|
|
11245
|
+
* @param tokenOrProvider a token or a function that returns a token.
|
|
11246
|
+
*/
|
|
11247
|
+
this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
11248
|
+
const connectAnonymousUser = () => this.streamClient.connectAnonymousUser(user, tokenOrProvider);
|
|
11249
|
+
this.connectionPromise = this.disconnectionPromise
|
|
11250
|
+
? this.disconnectionPromise.then(() => connectAnonymousUser())
|
|
11251
|
+
: connectAnonymousUser();
|
|
11252
|
+
this.connectionPromise.finally(() => (this.connectionPromise = undefined));
|
|
11253
|
+
return this.connectionPromise;
|
|
11254
|
+
});
|
|
11339
11255
|
this.streamClient = new StreamClient(apiKey, Object.assign({ persistUserOnConnectionFailure: true }, opts));
|
|
11340
11256
|
this.writeableStateStore = new StreamVideoWriteableStateStore();
|
|
11341
11257
|
this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
|
|
11342
11258
|
}
|
|
11259
|
+
/**
|
|
11260
|
+
* Connects the given user to the client.
|
|
11261
|
+
* Only one user can connect at a time, if you want to change users, call `disconnectUser` before connecting a new user.
|
|
11262
|
+
* If the connection is successful, the connected user [state variable](#readonlystatestore) will be updated accordingly.
|
|
11263
|
+
*
|
|
11264
|
+
* @param user the user to connect.
|
|
11265
|
+
* @param tokenOrProvider a token or a function that returns a token.
|
|
11266
|
+
*/
|
|
11267
|
+
connectUser(user, token) {
|
|
11268
|
+
var _a;
|
|
11269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11270
|
+
if (user.type === 'anonymous') {
|
|
11271
|
+
user.id = '!anon';
|
|
11272
|
+
return this.connectAnonymousUser(user, token);
|
|
11273
|
+
}
|
|
11274
|
+
if (user.type === 'guest') {
|
|
11275
|
+
const response = yield this.createGuestUser({
|
|
11276
|
+
user: Object.assign(Object.assign({}, user), { role: 'guest' }),
|
|
11277
|
+
});
|
|
11278
|
+
return this.connectUser(response.user, response.access_token);
|
|
11279
|
+
}
|
|
11280
|
+
const connectUser = () => {
|
|
11281
|
+
return this.streamClient.connectUser(user, token);
|
|
11282
|
+
};
|
|
11283
|
+
this.connectionPromise = this.disconnectionPromise
|
|
11284
|
+
? this.disconnectionPromise.then(() => connectUser())
|
|
11285
|
+
: connectUser();
|
|
11286
|
+
(_a = this.connectionPromise) === null || _a === void 0 ? void 0 : _a.finally(() => (this.connectionPromise = undefined));
|
|
11287
|
+
const connectUserResponse = yield this.connectionPromise;
|
|
11288
|
+
// connectUserResponse will be void if connectUser called twice for the same user
|
|
11289
|
+
if (connectUserResponse === null || connectUserResponse === void 0 ? void 0 : connectUserResponse.me) {
|
|
11290
|
+
this.writeableStateStore.setConnectedUser(connectUserResponse.me);
|
|
11291
|
+
}
|
|
11292
|
+
this.eventHandlersToUnregister.push(this.on('connection.changed', (e) => {
|
|
11293
|
+
const event = e;
|
|
11294
|
+
if (event.online) {
|
|
11295
|
+
const callsToReWatch = this.writeableStateStore.calls
|
|
11296
|
+
.filter((call) => call.watching)
|
|
11297
|
+
.map((call) => call.cid);
|
|
11298
|
+
if (callsToReWatch.length > 0) {
|
|
11299
|
+
this.queryCalls({
|
|
11300
|
+
watch: true,
|
|
11301
|
+
filter_conditions: {
|
|
11302
|
+
cid: { $in: callsToReWatch },
|
|
11303
|
+
},
|
|
11304
|
+
sort: [{ field: 'cid', direction: 1 }],
|
|
11305
|
+
}).catch((err) => {
|
|
11306
|
+
console.warn('Failed to re-watch calls', err);
|
|
11307
|
+
});
|
|
11308
|
+
}
|
|
11309
|
+
}
|
|
11310
|
+
}));
|
|
11311
|
+
this.eventHandlersToUnregister.push(this.on('call.created', (event) => {
|
|
11312
|
+
if (event.type !== 'call.created')
|
|
11313
|
+
return;
|
|
11314
|
+
const { call, members } = event;
|
|
11315
|
+
if (user.id === call.created_by.id) {
|
|
11316
|
+
console.warn('Received `call.created` sent by the current user');
|
|
11317
|
+
return;
|
|
11318
|
+
}
|
|
11319
|
+
this.writeableStateStore.registerCall(new Call({
|
|
11320
|
+
streamClient: this.streamClient,
|
|
11321
|
+
type: call.type,
|
|
11322
|
+
id: call.id,
|
|
11323
|
+
metadata: call,
|
|
11324
|
+
members,
|
|
11325
|
+
clientStore: this.writeableStateStore,
|
|
11326
|
+
}));
|
|
11327
|
+
}));
|
|
11328
|
+
this.eventHandlersToUnregister.push(this.on('call.ring', (event) => __awaiter(this, void 0, void 0, function* () {
|
|
11329
|
+
if (event.type !== 'call.ring')
|
|
11330
|
+
return;
|
|
11331
|
+
const { call, members } = event;
|
|
11332
|
+
if (user.id === call.created_by.id) {
|
|
11333
|
+
console.warn('Received `call.ring` sent by the current user');
|
|
11334
|
+
return;
|
|
11335
|
+
}
|
|
11336
|
+
// The call might already be tracked by the client,
|
|
11337
|
+
// if `call.created` was received before `call.ring`.
|
|
11338
|
+
// In that case, we just reuse the already tracked call.
|
|
11339
|
+
let theCall = this.writeableStateStore.findCall(call.type, call.id);
|
|
11340
|
+
if (!theCall) {
|
|
11341
|
+
// otherwise, we create a new call
|
|
11342
|
+
theCall = new Call({
|
|
11343
|
+
streamClient: this.streamClient,
|
|
11344
|
+
type: call.type,
|
|
11345
|
+
id: call.id,
|
|
11346
|
+
members,
|
|
11347
|
+
clientStore: this.writeableStateStore,
|
|
11348
|
+
ringing: true,
|
|
11349
|
+
});
|
|
11350
|
+
}
|
|
11351
|
+
// we fetch the latest metadata for the call from the server
|
|
11352
|
+
yield theCall.get({ ring: true });
|
|
11353
|
+
this.writeableStateStore.registerCall(theCall);
|
|
11354
|
+
})));
|
|
11355
|
+
return connectUserResponse;
|
|
11356
|
+
});
|
|
11357
|
+
}
|
|
11343
11358
|
/**
|
|
11344
11359
|
* addDevice - Adds a push device for a user.
|
|
11345
11360
|
*
|