@stream-io/video-client 0.0.11 → 0.0.13
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 +189 -197
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +188 -196
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +189 -197
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamVideoClient.d.ts +12 -5
- package/dist/src/coordinator/connection/client.d.ts +6 -0
- package/dist/src/store/stateStore.d.ts +0 -40
- package/package.json +1 -1
- package/src/StreamVideoClient.ts +72 -33
- package/src/coordinator/connection/client.ts +26 -0
- package/src/store/stateStore.ts +0 -88
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.13](https://github.com/GetStream/stream-video-js/compare/client0.0.12...client0.0.13) (2023-06-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* do not send ring to backend if call was not created by the user ([#645](https://github.com/GetStream/stream-video-js/issues/645)) ([1fa8ffb](https://github.com/GetStream/stream-video-js/commit/1fa8ffbb7373e9eff497bfe1ce48a970aedc0d9d))
|
|
11
|
+
|
|
12
|
+
### [0.0.12](https://github.com/GetStream/stream-video-js/compare/client0.0.11...client0.0.12) (2023-06-13)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Make it possible to provide user and token in StreamVideoClient… ([#631](https://github.com/GetStream/stream-video-js/issues/631)) ([93f9b03](https://github.com/GetStream/stream-video-js/commit/93f9b03313ac74179f1d93b513ea4de306312291))
|
|
18
|
+
|
|
5
19
|
### [0.0.11](https://github.com/GetStream/stream-video-js/compare/client0.0.10...client0.0.11) (2023-06-13)
|
|
6
20
|
|
|
7
21
|
|
package/dist/index.browser.es.js
CHANGED
|
@@ -5,7 +5,7 @@ export { AxiosError } from 'axios';
|
|
|
5
5
|
import { TwirpFetchTransport } from '@protobuf-ts/twirp-transport';
|
|
6
6
|
import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
7
7
|
import { ReplaySubject, BehaviorSubject, Subject, takeWhile, pairwise, tap, debounce, of, timer, map as map$2, Observable, debounceTime, concatMap, from, shareReplay, merge, combineLatest, filter } from 'rxjs';
|
|
8
|
-
import { take, map as map$1, distinctUntilChanged
|
|
8
|
+
import { take, map as map$1, distinctUntilChanged } from 'rxjs/operators';
|
|
9
9
|
import { UAParser } from 'ua-parser-js';
|
|
10
10
|
import WebSocket$1 from 'isomorphic-ws';
|
|
11
11
|
import { fromByteArray } from 'base64-js';
|
|
@@ -6362,6 +6362,130 @@ var rxUtils = /*#__PURE__*/Object.freeze({
|
|
|
6362
6362
|
setCurrentValue: setCurrentValue
|
|
6363
6363
|
});
|
|
6364
6364
|
|
|
6365
|
+
class StreamVideoWriteableStateStore {
|
|
6366
|
+
constructor() {
|
|
6367
|
+
/**
|
|
6368
|
+
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
6369
|
+
*/
|
|
6370
|
+
this.connectedUserSubject = new BehaviorSubject(undefined);
|
|
6371
|
+
/**
|
|
6372
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
6373
|
+
*/
|
|
6374
|
+
this.callsSubject = new BehaviorSubject([]);
|
|
6375
|
+
/**
|
|
6376
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
6377
|
+
* not emitted a value yet.
|
|
6378
|
+
*
|
|
6379
|
+
* @param observable$ the observable to get the value from.
|
|
6380
|
+
*/
|
|
6381
|
+
this.getCurrentValue = getCurrentValue;
|
|
6382
|
+
/**
|
|
6383
|
+
* Updates the value of the provided Subject.
|
|
6384
|
+
* An `update` can either be a new value or a function which takes
|
|
6385
|
+
* the current value and returns a new value.
|
|
6386
|
+
*
|
|
6387
|
+
* @param subject the subject to update.
|
|
6388
|
+
* @param update the update to apply to the subject.
|
|
6389
|
+
* @return the updated value.
|
|
6390
|
+
*/
|
|
6391
|
+
this.setCurrentValue = setCurrentValue;
|
|
6392
|
+
/**
|
|
6393
|
+
* Sets the currently connected user.
|
|
6394
|
+
*
|
|
6395
|
+
* @internal
|
|
6396
|
+
* @param user the user to set as connected.
|
|
6397
|
+
*/
|
|
6398
|
+
this.setConnectedUser = (user) => {
|
|
6399
|
+
return this.setCurrentValue(this.connectedUserSubject, user);
|
|
6400
|
+
};
|
|
6401
|
+
/**
|
|
6402
|
+
* Sets the list of {@link Call} objects created/tracked by this client.
|
|
6403
|
+
* @param calls
|
|
6404
|
+
*/
|
|
6405
|
+
this.setCalls = (calls) => {
|
|
6406
|
+
return this.setCurrentValue(this.callsSubject, calls);
|
|
6407
|
+
};
|
|
6408
|
+
/**
|
|
6409
|
+
* Adds a {@link Call} object to the list of {@link Call} objects created/tracked by this client.
|
|
6410
|
+
*
|
|
6411
|
+
* @param call the call to add.
|
|
6412
|
+
*/
|
|
6413
|
+
this.registerCall = (call) => {
|
|
6414
|
+
if (!this.calls.find((c) => c.cid === call.cid)) {
|
|
6415
|
+
this.setCalls((calls) => [...calls, call]);
|
|
6416
|
+
}
|
|
6417
|
+
};
|
|
6418
|
+
/**
|
|
6419
|
+
* Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
|
|
6420
|
+
*
|
|
6421
|
+
* @param call the call to remove
|
|
6422
|
+
*/
|
|
6423
|
+
this.unregisterCall = (call) => {
|
|
6424
|
+
return this.setCalls((calls) => calls.filter((c) => c !== call));
|
|
6425
|
+
};
|
|
6426
|
+
/**
|
|
6427
|
+
* Finds a {@link Call} object in the list of {@link Call} objects created/tracked by this client.
|
|
6428
|
+
*
|
|
6429
|
+
* @param type the type of call to find.
|
|
6430
|
+
* @param id the id of the call to find.
|
|
6431
|
+
*/
|
|
6432
|
+
this.findCall = (type, id) => {
|
|
6433
|
+
return this.calls.find((c) => c.type === type && c.id === id);
|
|
6434
|
+
};
|
|
6435
|
+
this.connectedUserSubject.subscribe((user) => __awaiter(this, void 0, void 0, function* () {
|
|
6436
|
+
// leave all calls when the user disconnects.
|
|
6437
|
+
if (!user) {
|
|
6438
|
+
for (const call of this.calls) {
|
|
6439
|
+
yield call.leave();
|
|
6440
|
+
}
|
|
6441
|
+
}
|
|
6442
|
+
}));
|
|
6443
|
+
}
|
|
6444
|
+
/**
|
|
6445
|
+
* The currently connected user.
|
|
6446
|
+
*/
|
|
6447
|
+
get connectedUser() {
|
|
6448
|
+
return this.getCurrentValue(this.connectedUserSubject);
|
|
6449
|
+
}
|
|
6450
|
+
/**
|
|
6451
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
6452
|
+
*/
|
|
6453
|
+
get calls() {
|
|
6454
|
+
return this.getCurrentValue(this.callsSubject);
|
|
6455
|
+
}
|
|
6456
|
+
}
|
|
6457
|
+
/**
|
|
6458
|
+
* A reactive store that exposes state variables in a reactive manner.
|
|
6459
|
+
* You can subscribe to changes of the different state variables.
|
|
6460
|
+
* This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
6461
|
+
*/
|
|
6462
|
+
class StreamVideoReadOnlyStateStore {
|
|
6463
|
+
constructor(store) {
|
|
6464
|
+
/**
|
|
6465
|
+
* This method allows you the get the current value of a state variable.
|
|
6466
|
+
*
|
|
6467
|
+
* @param observable the observable to get the current value of.
|
|
6468
|
+
* @returns the current value of the observable.
|
|
6469
|
+
*/
|
|
6470
|
+
this.getCurrentValue = getCurrentValue;
|
|
6471
|
+
// convert and expose subjects as observables
|
|
6472
|
+
this.connectedUser$ = store.connectedUserSubject.asObservable();
|
|
6473
|
+
this.calls$ = store.callsSubject.asObservable();
|
|
6474
|
+
}
|
|
6475
|
+
/**
|
|
6476
|
+
* The current user connected over WS to the backend.
|
|
6477
|
+
*/
|
|
6478
|
+
get connectedUser() {
|
|
6479
|
+
return getCurrentValue(this.connectedUser$);
|
|
6480
|
+
}
|
|
6481
|
+
/**
|
|
6482
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
6483
|
+
*/
|
|
6484
|
+
get calls() {
|
|
6485
|
+
return getCurrentValue(this.calls$);
|
|
6486
|
+
}
|
|
6487
|
+
}
|
|
6488
|
+
|
|
6365
6489
|
/**
|
|
6366
6490
|
* Creates a new combined {@link Comparator<T>} which sorts items by the given comparators.
|
|
6367
6491
|
* The comparators are applied in the order they are given (left -> right).
|
|
@@ -7021,171 +7145,6 @@ class CallState {
|
|
|
7021
7145
|
}
|
|
7022
7146
|
}
|
|
7023
7147
|
|
|
7024
|
-
class StreamVideoWriteableStateStore {
|
|
7025
|
-
constructor() {
|
|
7026
|
-
/**
|
|
7027
|
-
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
7028
|
-
*/
|
|
7029
|
-
this.connectedUserSubject = new BehaviorSubject(undefined);
|
|
7030
|
-
/**
|
|
7031
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7032
|
-
*/
|
|
7033
|
-
this.callsSubject = new BehaviorSubject([]);
|
|
7034
|
-
/**
|
|
7035
|
-
* Gets the current value of an observable, or undefined if the observable has
|
|
7036
|
-
* not emitted a value yet.
|
|
7037
|
-
*
|
|
7038
|
-
* @param observable$ the observable to get the value from.
|
|
7039
|
-
*/
|
|
7040
|
-
this.getCurrentValue = getCurrentValue;
|
|
7041
|
-
/**
|
|
7042
|
-
* Updates the value of the provided Subject.
|
|
7043
|
-
* An `update` can either be a new value or a function which takes
|
|
7044
|
-
* the current value and returns a new value.
|
|
7045
|
-
*
|
|
7046
|
-
* @param subject the subject to update.
|
|
7047
|
-
* @param update the update to apply to the subject.
|
|
7048
|
-
* @return the updated value.
|
|
7049
|
-
*/
|
|
7050
|
-
this.setCurrentValue = setCurrentValue;
|
|
7051
|
-
/**
|
|
7052
|
-
* Sets the currently connected user.
|
|
7053
|
-
*
|
|
7054
|
-
* @internal
|
|
7055
|
-
* @param user the user to set as connected.
|
|
7056
|
-
*/
|
|
7057
|
-
this.setConnectedUser = (user) => {
|
|
7058
|
-
return this.setCurrentValue(this.connectedUserSubject, user);
|
|
7059
|
-
};
|
|
7060
|
-
/**
|
|
7061
|
-
* Sets the list of {@link Call} objects created/tracked by this client.
|
|
7062
|
-
* @param calls
|
|
7063
|
-
*/
|
|
7064
|
-
this.setCalls = (calls) => {
|
|
7065
|
-
return this.setCurrentValue(this.callsSubject, calls);
|
|
7066
|
-
};
|
|
7067
|
-
/**
|
|
7068
|
-
* Adds a {@link Call} object to the list of {@link Call} objects created/tracked by this client.
|
|
7069
|
-
*
|
|
7070
|
-
* @param call the call to add.
|
|
7071
|
-
*/
|
|
7072
|
-
this.registerCall = (call) => {
|
|
7073
|
-
if (!this.calls.find((c) => c.cid === call.cid)) {
|
|
7074
|
-
this.setCalls((calls) => [...calls, call]);
|
|
7075
|
-
}
|
|
7076
|
-
};
|
|
7077
|
-
/**
|
|
7078
|
-
* Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
|
|
7079
|
-
*
|
|
7080
|
-
* @param call the call to remove
|
|
7081
|
-
*/
|
|
7082
|
-
this.unregisterCall = (call) => {
|
|
7083
|
-
return this.setCalls((calls) => calls.filter((c) => c !== call));
|
|
7084
|
-
};
|
|
7085
|
-
/**
|
|
7086
|
-
* Finds a {@link Call} object in the list of {@link Call} objects created/tracked by this client.
|
|
7087
|
-
*
|
|
7088
|
-
* @param type the type of call to find.
|
|
7089
|
-
* @param id the id of the call to find.
|
|
7090
|
-
*/
|
|
7091
|
-
this.findCall = (type, id) => {
|
|
7092
|
-
return this.calls.find((c) => c.type === type && c.id === id);
|
|
7093
|
-
};
|
|
7094
|
-
this.connectedUserSubject.subscribe((user) => __awaiter(this, void 0, void 0, function* () {
|
|
7095
|
-
// leave all calls when the user disconnects.
|
|
7096
|
-
if (!user) {
|
|
7097
|
-
for (const call of this.calls) {
|
|
7098
|
-
yield call.leave();
|
|
7099
|
-
}
|
|
7100
|
-
}
|
|
7101
|
-
}));
|
|
7102
|
-
this.incomingCalls$ = this.callsSubject.pipe(combineLatestWith(this.connectedUserSubject), map$1(([calls, connectedUser]) => calls.filter((call) => {
|
|
7103
|
-
const { metadata, callingState } = call.state;
|
|
7104
|
-
return ((metadata === null || metadata === void 0 ? void 0 : metadata.created_by.id) !== (connectedUser === null || connectedUser === void 0 ? void 0 : connectedUser.id) &&
|
|
7105
|
-
callingState === CallingState.RINGING);
|
|
7106
|
-
})));
|
|
7107
|
-
this.outgoingCalls$ = this.callsSubject.pipe(combineLatestWith(this.connectedUserSubject), map$1(([calls, connectedUser]) => calls.filter((call) => {
|
|
7108
|
-
const { metadata, callingState } = call.state;
|
|
7109
|
-
return ((metadata === null || metadata === void 0 ? void 0 : metadata.created_by.id) === (connectedUser === null || connectedUser === void 0 ? void 0 : connectedUser.id) &&
|
|
7110
|
-
callingState === CallingState.RINGING);
|
|
7111
|
-
})));
|
|
7112
|
-
}
|
|
7113
|
-
/**
|
|
7114
|
-
* The currently connected user.
|
|
7115
|
-
*/
|
|
7116
|
-
get connectedUser() {
|
|
7117
|
-
return this.getCurrentValue(this.connectedUserSubject);
|
|
7118
|
-
}
|
|
7119
|
-
/**
|
|
7120
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7121
|
-
*/
|
|
7122
|
-
get calls() {
|
|
7123
|
-
return this.getCurrentValue(this.callsSubject);
|
|
7124
|
-
}
|
|
7125
|
-
/**
|
|
7126
|
-
* A list of objects describing incoming calls.
|
|
7127
|
-
* @deprecated derive from calls$ instead.
|
|
7128
|
-
*/
|
|
7129
|
-
get incomingCalls() {
|
|
7130
|
-
return this.getCurrentValue(this.incomingCalls$);
|
|
7131
|
-
}
|
|
7132
|
-
/**
|
|
7133
|
-
* A list of objects describing calls initiated by the current user.
|
|
7134
|
-
* @deprecated derive from calls$ instead.
|
|
7135
|
-
*/
|
|
7136
|
-
get outgoingCalls() {
|
|
7137
|
-
return this.getCurrentValue(this.outgoingCalls$);
|
|
7138
|
-
}
|
|
7139
|
-
}
|
|
7140
|
-
/**
|
|
7141
|
-
* A reactive store that exposes state variables in a reactive manner.
|
|
7142
|
-
* You can subscribe to changes of the different state variables.
|
|
7143
|
-
* This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
7144
|
-
*/
|
|
7145
|
-
class StreamVideoReadOnlyStateStore {
|
|
7146
|
-
constructor(store) {
|
|
7147
|
-
/**
|
|
7148
|
-
* This method allows you the get the current value of a state variable.
|
|
7149
|
-
*
|
|
7150
|
-
* @param observable the observable to get the current value of.
|
|
7151
|
-
* @returns the current value of the observable.
|
|
7152
|
-
*/
|
|
7153
|
-
this.getCurrentValue = getCurrentValue;
|
|
7154
|
-
// convert and expose subjects as observables
|
|
7155
|
-
this.connectedUser$ = store.connectedUserSubject.asObservable();
|
|
7156
|
-
this.calls$ = store.callsSubject.asObservable();
|
|
7157
|
-
// re-expose observables
|
|
7158
|
-
this.incomingCalls$ = store.incomingCalls$;
|
|
7159
|
-
this.outgoingCalls$ = store.outgoingCalls$;
|
|
7160
|
-
}
|
|
7161
|
-
/**
|
|
7162
|
-
* The current user connected over WS to the backend.
|
|
7163
|
-
*/
|
|
7164
|
-
get connectedUser() {
|
|
7165
|
-
return getCurrentValue(this.connectedUser$);
|
|
7166
|
-
}
|
|
7167
|
-
/**
|
|
7168
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7169
|
-
*/
|
|
7170
|
-
get calls() {
|
|
7171
|
-
return getCurrentValue(this.calls$);
|
|
7172
|
-
}
|
|
7173
|
-
/**
|
|
7174
|
-
* A list of objects describing incoming calls.
|
|
7175
|
-
* @deprecated derive from calls$ instead.
|
|
7176
|
-
*/
|
|
7177
|
-
get incomingCalls() {
|
|
7178
|
-
return getCurrentValue(this.incomingCalls$);
|
|
7179
|
-
}
|
|
7180
|
-
/**
|
|
7181
|
-
* A list of objects describing calls initiated by the current user.
|
|
7182
|
-
* @deprecated derive from calls$ instead.
|
|
7183
|
-
*/
|
|
7184
|
-
get outgoingCalls() {
|
|
7185
|
-
return getCurrentValue(this.outgoingCalls$);
|
|
7186
|
-
}
|
|
7187
|
-
}
|
|
7188
|
-
|
|
7189
7148
|
/**
|
|
7190
7149
|
* Event handler that watched the delivery of `call.accepted`.
|
|
7191
7150
|
* Once the event is received, the call is joined.
|
|
@@ -10527,6 +10486,14 @@ class StreamClient {
|
|
|
10527
10486
|
this.nextRequestAbortController = null;
|
|
10528
10487
|
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); };
|
|
10529
10488
|
this._hasConnectionID = () => Boolean(this._getConnectionID());
|
|
10489
|
+
/**
|
|
10490
|
+
* This will start a promise to hold API calls until `connectUser` is called, useful when user is set in `StreamVideoClient constructor`
|
|
10491
|
+
*/
|
|
10492
|
+
this.startWaitingForConnection = () => {
|
|
10493
|
+
this.waitForConnectPromise = new Promise((resolve) => {
|
|
10494
|
+
this.resolveConnectPromise = resolve;
|
|
10495
|
+
});
|
|
10496
|
+
};
|
|
10530
10497
|
/**
|
|
10531
10498
|
* connectUser - Set the current user and open a WebSocket connection
|
|
10532
10499
|
*
|
|
@@ -10561,6 +10528,11 @@ class StreamClient {
|
|
|
10561
10528
|
this._setUser(user);
|
|
10562
10529
|
const wsPromise = this.openConnection();
|
|
10563
10530
|
this.setUserPromise = Promise.all([setTokenPromise, wsPromise]).then((result) => result[1]);
|
|
10531
|
+
if (this.resolveConnectPromise) {
|
|
10532
|
+
this.resolveConnectPromise();
|
|
10533
|
+
this.waitForConnectPromise = undefined;
|
|
10534
|
+
this.resolveConnectPromise = undefined;
|
|
10535
|
+
}
|
|
10564
10536
|
try {
|
|
10565
10537
|
return yield this.setUserPromise;
|
|
10566
10538
|
}
|
|
@@ -10659,6 +10631,11 @@ class StreamClient {
|
|
|
10659
10631
|
this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
|
|
10660
10632
|
this.anonymous = true;
|
|
10661
10633
|
yield this._setToken(user, tokenOrProvider, this.anonymous);
|
|
10634
|
+
if (this.resolveConnectPromise) {
|
|
10635
|
+
this.resolveConnectPromise();
|
|
10636
|
+
this.waitForConnectPromise = undefined;
|
|
10637
|
+
this.resolveConnectPromise = undefined;
|
|
10638
|
+
}
|
|
10662
10639
|
this._setUser(user);
|
|
10663
10640
|
// some endpoints require a connection_id to be resolved.
|
|
10664
10641
|
// as anonymous users aren't allowed to open WS connections, we just
|
|
@@ -10668,6 +10645,9 @@ class StreamClient {
|
|
|
10668
10645
|
this.doAxiosRequest = (type, url, data, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
10669
10646
|
var _g;
|
|
10670
10647
|
if (!options.publicEndpoint || this.user) {
|
|
10648
|
+
if (this.waitForConnectPromise) {
|
|
10649
|
+
yield this.waitForConnectPromise;
|
|
10650
|
+
}
|
|
10671
10651
|
yield this.tokenManager.tokenReady();
|
|
10672
10652
|
}
|
|
10673
10653
|
const requestConfig = this._enrichAxiosOptions(options);
|
|
@@ -11022,7 +11002,7 @@ class StreamClient {
|
|
|
11022
11002
|
}
|
|
11023
11003
|
getUserAgent() {
|
|
11024
11004
|
return (this.userAgent ||
|
|
11025
|
-
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.
|
|
11005
|
+
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.12"}`);
|
|
11026
11006
|
}
|
|
11027
11007
|
setUserAgent(userAgent) {
|
|
11028
11008
|
this.userAgent = userAgent;
|
|
@@ -11090,12 +11070,7 @@ class StreamClient {
|
|
|
11090
11070
|
* A `StreamVideoClient` instance lets you communicate with our API, and authenticate users.
|
|
11091
11071
|
*/
|
|
11092
11072
|
class StreamVideoClient {
|
|
11093
|
-
|
|
11094
|
-
* You should create only one instance of `StreamVideoClient`.
|
|
11095
|
-
* @param apiKey your Stream API key
|
|
11096
|
-
* @param opts the options for the client.
|
|
11097
|
-
*/
|
|
11098
|
-
constructor(apiKey, opts) {
|
|
11073
|
+
constructor(apiKeyOrArgs, opts) {
|
|
11099
11074
|
this.eventHandlersToUnregister = [];
|
|
11100
11075
|
/**
|
|
11101
11076
|
* Disconnects the currently connected user from the client.
|
|
@@ -11106,6 +11081,9 @@ class StreamVideoClient {
|
|
|
11106
11081
|
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
11107
11082
|
*/
|
|
11108
11083
|
this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
11084
|
+
if (!this.streamClient.user) {
|
|
11085
|
+
return;
|
|
11086
|
+
}
|
|
11109
11087
|
const disconnectUser = () => this.streamClient.disconnectUser(timeout);
|
|
11110
11088
|
this.disconnectionPromise = this.connectionPromise
|
|
11111
11089
|
? this.connectionPromise.then(() => disconnectUser())
|
|
@@ -11252,7 +11230,17 @@ class StreamVideoClient {
|
|
|
11252
11230
|
this.connectionPromise.finally(() => (this.connectionPromise = undefined));
|
|
11253
11231
|
return this.connectionPromise;
|
|
11254
11232
|
});
|
|
11255
|
-
|
|
11233
|
+
if (typeof apiKeyOrArgs === 'string') {
|
|
11234
|
+
this.streamClient = new StreamClient(apiKeyOrArgs, Object.assign({ persistUserOnConnectionFailure: true }, opts));
|
|
11235
|
+
}
|
|
11236
|
+
else {
|
|
11237
|
+
this.streamClient = new StreamClient(apiKeyOrArgs.apiKey, Object.assign({ persistUserOnConnectionFailure: true }, apiKeyOrArgs.options));
|
|
11238
|
+
this.user = apiKeyOrArgs.user;
|
|
11239
|
+
this.token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
|
|
11240
|
+
if (this.user) {
|
|
11241
|
+
this.streamClient.startWaitingForConnection();
|
|
11242
|
+
}
|
|
11243
|
+
}
|
|
11256
11244
|
this.writeableStateStore = new StreamVideoWriteableStateStore();
|
|
11257
11245
|
this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
|
|
11258
11246
|
}
|
|
@@ -11262,23 +11250,28 @@ class StreamVideoClient {
|
|
|
11262
11250
|
* If the connection is successful, the connected user [state variable](#readonlystatestore) will be updated accordingly.
|
|
11263
11251
|
*
|
|
11264
11252
|
* @param user the user to connect.
|
|
11265
|
-
* @param
|
|
11253
|
+
* @param token a token or a function that returns a token.
|
|
11266
11254
|
*/
|
|
11267
11255
|
connectUser(user, token) {
|
|
11268
11256
|
var _a;
|
|
11269
11257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11258
|
+
const userToConnect = user || this.user;
|
|
11259
|
+
const tokenToUse = token || this.token;
|
|
11260
|
+
if (!userToConnect) {
|
|
11261
|
+
throw new Error('Connect user is called without user');
|
|
11262
|
+
}
|
|
11263
|
+
if (userToConnect.type === 'anonymous') {
|
|
11264
|
+
userToConnect.id = '!anon';
|
|
11265
|
+
return this.connectAnonymousUser(userToConnect, tokenToUse);
|
|
11273
11266
|
}
|
|
11274
|
-
if (
|
|
11267
|
+
if (userToConnect.type === 'guest') {
|
|
11275
11268
|
const response = yield this.createGuestUser({
|
|
11276
|
-
user: Object.assign(Object.assign({},
|
|
11269
|
+
user: Object.assign(Object.assign({}, userToConnect), { role: 'guest' }),
|
|
11277
11270
|
});
|
|
11278
11271
|
return this.connectUser(response.user, response.access_token);
|
|
11279
11272
|
}
|
|
11280
11273
|
const connectUser = () => {
|
|
11281
|
-
return this.streamClient.connectUser(
|
|
11274
|
+
return this.streamClient.connectUser(userToConnect, tokenToUse);
|
|
11282
11275
|
};
|
|
11283
11276
|
this.connectionPromise = this.disconnectionPromise
|
|
11284
11277
|
? this.disconnectionPromise.then(() => connectUser())
|
|
@@ -11312,7 +11305,7 @@ class StreamVideoClient {
|
|
|
11312
11305
|
if (event.type !== 'call.created')
|
|
11313
11306
|
return;
|
|
11314
11307
|
const { call, members } = event;
|
|
11315
|
-
if (
|
|
11308
|
+
if (userToConnect.id === call.created_by.id) {
|
|
11316
11309
|
console.warn('Received `call.created` sent by the current user');
|
|
11317
11310
|
return;
|
|
11318
11311
|
}
|
|
@@ -11329,27 +11322,26 @@ class StreamVideoClient {
|
|
|
11329
11322
|
if (event.type !== 'call.ring')
|
|
11330
11323
|
return;
|
|
11331
11324
|
const { call, members } = event;
|
|
11332
|
-
if (
|
|
11325
|
+
if (userToConnect.id === call.created_by.id) {
|
|
11333
11326
|
console.warn('Received `call.ring` sent by the current user');
|
|
11334
11327
|
return;
|
|
11335
11328
|
}
|
|
11336
11329
|
// The call might already be tracked by the client,
|
|
11337
11330
|
// if `call.created` was received before `call.ring`.
|
|
11338
|
-
// In that case, we
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
}
|
|
11331
|
+
// In that case, we cleanup the already tracked call.
|
|
11332
|
+
const prevCall = this.writeableStateStore.findCall(call.type, call.id);
|
|
11333
|
+
yield (prevCall === null || prevCall === void 0 ? void 0 : prevCall.leave());
|
|
11334
|
+
// we create a new call
|
|
11335
|
+
const theCall = new Call({
|
|
11336
|
+
streamClient: this.streamClient,
|
|
11337
|
+
type: call.type,
|
|
11338
|
+
id: call.id,
|
|
11339
|
+
members,
|
|
11340
|
+
clientStore: this.writeableStateStore,
|
|
11341
|
+
ringing: true,
|
|
11342
|
+
});
|
|
11351
11343
|
// we fetch the latest metadata for the call from the server
|
|
11352
|
-
yield theCall.get(
|
|
11344
|
+
yield theCall.get();
|
|
11353
11345
|
this.writeableStateStore.registerCall(theCall);
|
|
11354
11346
|
})));
|
|
11355
11347
|
return connectUserResponse;
|