@stream-io/video-client 0.1.4 → 0.1.6
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/README.md +54 -8
- package/dist/index.browser.es.js +40 -61
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +39 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +40 -61
- package/dist/index.es.js.map +1 -1
- package/dist/src/Call.d.ts +2 -2
- package/dist/src/StreamVideoClient.d.ts +4 -5
- package/dist/src/__tests__/server-side/call-types.test.d.ts +1 -0
- package/dist/src/__tests__/server-side/call.test.d.ts +1 -0
- package/dist/src/__tests__/server-side/create-token.test.d.ts +1 -0
- package/dist/src/__tests__/server-side/server-side-user.test.d.ts +1 -0
- package/dist/src/coordinator/connection/client.d.ts +0 -6
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Call.ts +18 -11
- package/src/StreamVideoClient.ts +33 -31
- package/src/__tests__/StreamVideoClient.test.ts +9 -9
- package/src/__tests__/server-side/call-members.test.ts +93 -0
- package/src/__tests__/server-side/call-types.test.ts +78 -0
- package/src/__tests__/server-side/call.test.ts +147 -0
- package/src/__tests__/server-side/create-token.test.ts +44 -0
- package/src/__tests__/server-side/server-side-user.test.ts +28 -0
- package/src/coordinator/connection/client.ts +2 -29
- package/src/__tests__/StreamVideoServerClient.test.ts +0 -110
- /package/dist/src/__tests__/{StreamVideoServerClient.test.d.ts → server-side/call-members.test.d.ts} +0 -0
package/dist/index.es.js
CHANGED
|
@@ -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
|
|
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';
|
|
@@ -9468,11 +9468,13 @@ class Call {
|
|
|
9468
9468
|
*/
|
|
9469
9469
|
this.leave = ({ reject = false } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
9470
9470
|
var _a, _b, _c, _d;
|
|
9471
|
-
// TODO: handle case when leave is called during JOINING
|
|
9472
9471
|
const callingState = this.state.callingState;
|
|
9473
9472
|
if (callingState === CallingState.LEFT) {
|
|
9474
9473
|
throw new Error('Cannot leave call that has already been left.');
|
|
9475
9474
|
}
|
|
9475
|
+
if (callingState === CallingState.JOINING) {
|
|
9476
|
+
yield this.assertCallJoined();
|
|
9477
|
+
}
|
|
9476
9478
|
if (this.ringing) {
|
|
9477
9479
|
// I'm the one who started the call, so I should cancel it.
|
|
9478
9480
|
const hasOtherParticipants = this.state.remoteParticipants.length > 0;
|
|
@@ -9878,13 +9880,6 @@ class Call {
|
|
|
9878
9880
|
}, timeout);
|
|
9879
9881
|
});
|
|
9880
9882
|
};
|
|
9881
|
-
this.assertCallJoined = () => {
|
|
9882
|
-
return new Promise((resolve) => {
|
|
9883
|
-
this.state.callingState$
|
|
9884
|
-
.pipe(takeWhile((state) => state !== CallingState.JOINED, true))
|
|
9885
|
-
.subscribe(() => resolve());
|
|
9886
|
-
});
|
|
9887
|
-
};
|
|
9888
9883
|
/**
|
|
9889
9884
|
* Starts publishing the given video stream to the call.
|
|
9890
9885
|
* The stream will be stopped if the user changes an input device, or if the user leaves the call.
|
|
@@ -10115,6 +10110,13 @@ class Call {
|
|
|
10115
10110
|
var _h;
|
|
10116
10111
|
return (_h = this.publisher) === null || _h === void 0 ? void 0 : _h.updateVideoPublishQuality(enabledRids);
|
|
10117
10112
|
});
|
|
10113
|
+
this.assertCallJoined = () => {
|
|
10114
|
+
return new Promise((resolve) => {
|
|
10115
|
+
this.state.callingState$
|
|
10116
|
+
.pipe(takeWhile((state) => state !== CallingState.JOINED, true), filter((s) => s === CallingState.JOINED))
|
|
10117
|
+
.subscribe(() => resolve());
|
|
10118
|
+
});
|
|
10119
|
+
};
|
|
10118
10120
|
/**
|
|
10119
10121
|
* Sends a reaction to the other call participants.
|
|
10120
10122
|
*
|
|
@@ -10326,7 +10328,7 @@ class Call {
|
|
|
10326
10328
|
* @returns
|
|
10327
10329
|
*/
|
|
10328
10330
|
this.queryMembers = (request) => {
|
|
10329
|
-
return this.streamClient.post('/call/members', Object.assign(Object.assign({}, request), { id: this.id, type: this.type }));
|
|
10331
|
+
return this.streamClient.post('/call/members', Object.assign(Object.assign({}, (request || {})), { id: this.id, type: this.type }));
|
|
10330
10332
|
};
|
|
10331
10333
|
/**
|
|
10332
10334
|
* Will update the call members.
|
|
@@ -11638,7 +11640,7 @@ class WSConnectionFallback {
|
|
|
11638
11640
|
}
|
|
11639
11641
|
}
|
|
11640
11642
|
|
|
11641
|
-
const version = '0.1.
|
|
11643
|
+
const version = '0.1.6';
|
|
11642
11644
|
|
|
11643
11645
|
const logger = getLogger(['location']);
|
|
11644
11646
|
const HINT_URL = `https://hint.stream-io-video.com/`;
|
|
@@ -11701,14 +11703,6 @@ class StreamClient {
|
|
|
11701
11703
|
});
|
|
11702
11704
|
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); };
|
|
11703
11705
|
this._hasConnectionID = () => Boolean(this._getConnectionID());
|
|
11704
|
-
/**
|
|
11705
|
-
* This will start a promise to hold API calls until `connectUser` is called, useful when user is set in `StreamVideoClient constructor`
|
|
11706
|
-
*/
|
|
11707
|
-
this.startWaitingForConnection = () => {
|
|
11708
|
-
this.waitForConnectPromise = new Promise((resolve) => {
|
|
11709
|
-
this.resolveConnectPromise = resolve;
|
|
11710
|
-
});
|
|
11711
|
-
};
|
|
11712
11706
|
/**
|
|
11713
11707
|
* connectUser - Set the current user and open a WebSocket connection
|
|
11714
11708
|
*
|
|
@@ -11743,11 +11737,6 @@ class StreamClient {
|
|
|
11743
11737
|
this._setUser(user);
|
|
11744
11738
|
const wsPromise = this.openConnection();
|
|
11745
11739
|
this.setUserPromise = Promise.all([setTokenPromise, wsPromise]).then((result) => result[1]);
|
|
11746
|
-
if (this.resolveConnectPromise) {
|
|
11747
|
-
this.resolveConnectPromise();
|
|
11748
|
-
this.waitForConnectPromise = undefined;
|
|
11749
|
-
this.resolveConnectPromise = undefined;
|
|
11750
|
-
}
|
|
11751
11740
|
try {
|
|
11752
11741
|
return yield this.setUserPromise;
|
|
11753
11742
|
}
|
|
@@ -11862,11 +11851,6 @@ class StreamClient {
|
|
|
11862
11851
|
});
|
|
11863
11852
|
this.anonymous = true;
|
|
11864
11853
|
yield this._setToken(user, tokenOrProvider, this.anonymous);
|
|
11865
|
-
if (this.resolveConnectPromise) {
|
|
11866
|
-
this.resolveConnectPromise();
|
|
11867
|
-
this.waitForConnectPromise = undefined;
|
|
11868
|
-
this.resolveConnectPromise = undefined;
|
|
11869
|
-
}
|
|
11870
11854
|
this._setUser(user);
|
|
11871
11855
|
// some endpoints require a connection_id to be resolved.
|
|
11872
11856
|
// as anonymous users aren't allowed to open WS connections, we just
|
|
@@ -11923,9 +11907,6 @@ class StreamClient {
|
|
|
11923
11907
|
this.logger('trace', `client:${type} - Response - url: ${url} > status ${response.status}`, {
|
|
11924
11908
|
response,
|
|
11925
11909
|
});
|
|
11926
|
-
this.logger('trace', `client:${type} - Response payload`, {
|
|
11927
|
-
response,
|
|
11928
|
-
});
|
|
11929
11910
|
};
|
|
11930
11911
|
this._logApiError = (type, url, error) => {
|
|
11931
11912
|
this.logger('error', `client:${type} - Error - url: ${url}`, {
|
|
@@ -11936,9 +11917,6 @@ class StreamClient {
|
|
|
11936
11917
|
this.doAxiosRequest = (type, url, data, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
11937
11918
|
var _h;
|
|
11938
11919
|
if (!options.publicEndpoint) {
|
|
11939
|
-
if (this.waitForConnectPromise) {
|
|
11940
|
-
yield this.waitForConnectPromise;
|
|
11941
|
-
}
|
|
11942
11920
|
yield Promise.all([
|
|
11943
11921
|
this.tokenManager.tokenReady(),
|
|
11944
11922
|
this.connectionIdPromise,
|
|
@@ -11977,9 +11955,9 @@ class StreamClient {
|
|
|
11977
11955
|
}
|
|
11978
11956
|
catch (e /**TODO: generalize error types */) {
|
|
11979
11957
|
e.client_request_id = (_h = requestConfig.headers) === null || _h === void 0 ? void 0 : _h['x-client-request-id'];
|
|
11980
|
-
this._logApiError(type, url, e);
|
|
11981
11958
|
this.consecutiveFailures += 1;
|
|
11982
11959
|
if (e.response) {
|
|
11960
|
+
this._logApiError(type, url, e.response);
|
|
11983
11961
|
/** connection_fallback depends on this token expiration logic */
|
|
11984
11962
|
if (e.response.data.code === KnownCodes.TOKEN_EXPIRED &&
|
|
11985
11963
|
!this.tokenManager.isStatic()) {
|
|
@@ -11992,6 +11970,7 @@ class StreamClient {
|
|
|
11992
11970
|
return this.handleResponse(e.response);
|
|
11993
11971
|
}
|
|
11994
11972
|
else {
|
|
11973
|
+
this._logApiError(type, url, e);
|
|
11995
11974
|
// eslint-disable-next-line no-throw-literal
|
|
11996
11975
|
throw e;
|
|
11997
11976
|
}
|
|
@@ -12276,6 +12255,7 @@ class StreamClient {
|
|
|
12276
12255
|
class StreamVideoClient {
|
|
12277
12256
|
constructor(apiKeyOrArgs, opts) {
|
|
12278
12257
|
var _a, _b;
|
|
12258
|
+
this.logLevel = 'warn';
|
|
12279
12259
|
this.eventHandlersToUnregister = [];
|
|
12280
12260
|
/**
|
|
12281
12261
|
* Disconnects the currently connected user from the client.
|
|
@@ -12286,7 +12266,7 @@ class StreamVideoClient {
|
|
|
12286
12266
|
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
12287
12267
|
*/
|
|
12288
12268
|
this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
12289
|
-
if (!this.streamClient.user) {
|
|
12269
|
+
if (!this.streamClient.user && !this.connectionPromise) {
|
|
12290
12270
|
return;
|
|
12291
12271
|
}
|
|
12292
12272
|
const disconnectUser = () => this.streamClient.disconnectUser(timeout);
|
|
@@ -12347,7 +12327,7 @@ class StreamVideoClient {
|
|
|
12347
12327
|
*
|
|
12348
12328
|
* @param data the query data.
|
|
12349
12329
|
*/
|
|
12350
|
-
this.queryCalls = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
12330
|
+
this.queryCalls = (data = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
12351
12331
|
const response = yield this.streamClient.post('/calls', data);
|
|
12352
12332
|
const calls = response.calls.map((c) => {
|
|
12353
12333
|
const call = new Call({
|
|
@@ -12463,14 +12443,16 @@ class StreamVideoClient {
|
|
|
12463
12443
|
this.streamClient.setUserAgent(this.streamClient.getUserAgent() +
|
|
12464
12444
|
`-video-${SdkType[sdkInfo.type].toLowerCase()}-sdk-${sdkInfo.major}.${sdkInfo.minor}.${sdkInfo.patch}`);
|
|
12465
12445
|
}
|
|
12466
|
-
this.user = apiKeyOrArgs.user;
|
|
12467
|
-
this.token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
|
|
12468
|
-
if (this.user) {
|
|
12469
|
-
this.streamClient.startWaitingForConnection();
|
|
12470
|
-
}
|
|
12471
12446
|
}
|
|
12472
12447
|
this.writeableStateStore = new StreamVideoWriteableStateStore();
|
|
12473
12448
|
this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
|
|
12449
|
+
if (typeof apiKeyOrArgs !== 'string') {
|
|
12450
|
+
const user = apiKeyOrArgs.user;
|
|
12451
|
+
const token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
|
|
12452
|
+
if (user) {
|
|
12453
|
+
this.connectUser(user, token);
|
|
12454
|
+
}
|
|
12455
|
+
}
|
|
12474
12456
|
}
|
|
12475
12457
|
/**
|
|
12476
12458
|
* Connects the given user to the client.
|
|
@@ -12483,24 +12465,21 @@ class StreamVideoClient {
|
|
|
12483
12465
|
connectUser(user, token) {
|
|
12484
12466
|
var _a;
|
|
12485
12467
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
throw new Error('Connect user is called without user');
|
|
12490
|
-
}
|
|
12491
|
-
if (userToConnect.type === 'anonymous') {
|
|
12492
|
-
userToConnect.id = '!anon';
|
|
12493
|
-
return this.connectAnonymousUser(userToConnect, tokenToUse);
|
|
12494
|
-
}
|
|
12495
|
-
if (userToConnect.type === 'guest') {
|
|
12496
|
-
const response = yield this.createGuestUser({
|
|
12497
|
-
user: Object.assign(Object.assign({}, userToConnect), { role: 'guest' }),
|
|
12498
|
-
});
|
|
12499
|
-
return this.connectUser(response.user, response.access_token);
|
|
12468
|
+
if (user.type === 'anonymous') {
|
|
12469
|
+
user.id = '!anon';
|
|
12470
|
+
return this.connectAnonymousUser(user, token);
|
|
12500
12471
|
}
|
|
12501
|
-
|
|
12502
|
-
return this.streamClient.connectUser(
|
|
12472
|
+
let connectUser = () => {
|
|
12473
|
+
return this.streamClient.connectUser(user, token);
|
|
12503
12474
|
};
|
|
12475
|
+
if (user.type === 'guest') {
|
|
12476
|
+
connectUser = () => __awaiter(this, void 0, void 0, function* () {
|
|
12477
|
+
const response = yield this.createGuestUser({
|
|
12478
|
+
user: Object.assign(Object.assign({}, user), { role: 'guest' }),
|
|
12479
|
+
});
|
|
12480
|
+
return this.streamClient.connectUser(response.user, response.access_token);
|
|
12481
|
+
});
|
|
12482
|
+
}
|
|
12504
12483
|
this.connectionPromise = this.disconnectionPromise
|
|
12505
12484
|
? this.disconnectionPromise.then(() => connectUser())
|
|
12506
12485
|
: connectUser();
|
|
@@ -12534,7 +12513,7 @@ class StreamVideoClient {
|
|
|
12534
12513
|
if (event.type !== 'call.created')
|
|
12535
12514
|
return;
|
|
12536
12515
|
const { call, members } = event;
|
|
12537
|
-
if (
|
|
12516
|
+
if (user.id === call.created_by.id) {
|
|
12538
12517
|
this.logger('warn', 'Received `call.created` sent by the current user');
|
|
12539
12518
|
return;
|
|
12540
12519
|
}
|
|
@@ -12552,7 +12531,7 @@ class StreamVideoClient {
|
|
|
12552
12531
|
if (event.type !== 'call.ring')
|
|
12553
12532
|
return;
|
|
12554
12533
|
const { call, members } = event;
|
|
12555
|
-
if (
|
|
12534
|
+
if (user.id === call.created_by.id) {
|
|
12556
12535
|
this.logger('debug', 'Received `call.ring` sent by the current user so ignoring the event');
|
|
12557
12536
|
return;
|
|
12558
12537
|
}
|