@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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
|
+
import { beforeAll, describe, expect, it } from 'vitest';
|
|
4
|
+
import { StreamVideoServerClient } from '../../StreamVideoServerClient';
|
|
5
|
+
|
|
6
|
+
const apiKey = process.env.STREAM_API_KEY!;
|
|
7
|
+
const secret = process.env.STREAM_SECRET!;
|
|
8
|
+
|
|
9
|
+
describe('creating tokens', () => {
|
|
10
|
+
let client: StreamVideoServerClient;
|
|
11
|
+
const userId = 'john';
|
|
12
|
+
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
client = new StreamVideoServerClient(apiKey, {
|
|
15
|
+
secret,
|
|
16
|
+
logLevel: 'error',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('with no expiration', () => {
|
|
21
|
+
const token = client.createToken(userId);
|
|
22
|
+
const decodedToken = jwt.verify(token, secret) as any;
|
|
23
|
+
|
|
24
|
+
expect(decodedToken.user_id).toBe(userId);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('with expiration and issued at provided', () => {
|
|
28
|
+
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
|
|
29
|
+
const iat = Math.round(new Date().getTime() / 1000);
|
|
30
|
+
const token = client.createToken(userId, exp, iat);
|
|
31
|
+
const decodedToken = jwt.verify(token, secret) as any;
|
|
32
|
+
|
|
33
|
+
expect(decodedToken.exp).toBe(exp);
|
|
34
|
+
expect(decodedToken.iat).toBe(iat);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('with call IDs provided', () => {
|
|
38
|
+
const call_cids = ['default:call1', 'livestream:call2'];
|
|
39
|
+
const token = client.createToken(userId, undefined, undefined, call_cids);
|
|
40
|
+
const decodedToken = jwt.verify(token, secret) as any;
|
|
41
|
+
|
|
42
|
+
expect(decodedToken.call_cids).toEqual(call_cids);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
+
import { StreamVideoServerClient } from '../../StreamVideoServerClient';
|
|
4
|
+
|
|
5
|
+
const apiKey = process.env.STREAM_API_KEY!;
|
|
6
|
+
const secret = process.env.STREAM_SECRET!;
|
|
7
|
+
|
|
8
|
+
describe('server side user connect', () => {
|
|
9
|
+
let client: StreamVideoServerClient;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
client = new StreamVideoServerClient(apiKey, {
|
|
13
|
+
browser: false,
|
|
14
|
+
secret,
|
|
15
|
+
allowServerSideConnect: true,
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('hold up API requests until connect is ready', async () => {
|
|
20
|
+
const userId = 'server-side-test';
|
|
21
|
+
const token = client.createToken(userId);
|
|
22
|
+
client.connectUser({ id: userId }, token);
|
|
23
|
+
|
|
24
|
+
const response = await client.queryCalls({});
|
|
25
|
+
|
|
26
|
+
expect(response).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -71,8 +71,6 @@ export class StreamClient {
|
|
|
71
71
|
rejectConnectionId?: Function;
|
|
72
72
|
connectionIdPromise?: Promise<string | undefined>;
|
|
73
73
|
private nextRequestAbortController: AbortController | null = null;
|
|
74
|
-
private waitForConnectPromise?: Promise<void>;
|
|
75
|
-
private resolveConnectPromise?: Function;
|
|
76
74
|
|
|
77
75
|
/**
|
|
78
76
|
* Initialize a client.
|
|
@@ -201,15 +199,6 @@ export class StreamClient {
|
|
|
201
199
|
|
|
202
200
|
_hasConnectionID = () => Boolean(this._getConnectionID());
|
|
203
201
|
|
|
204
|
-
/**
|
|
205
|
-
* This will start a promise to hold API calls until `connectUser` is called, useful when user is set in `StreamVideoClient constructor`
|
|
206
|
-
*/
|
|
207
|
-
startWaitingForConnection = () => {
|
|
208
|
-
this.waitForConnectPromise = new Promise((resolve) => {
|
|
209
|
-
this.resolveConnectPromise = resolve;
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
|
|
213
202
|
/**
|
|
214
203
|
* connectUser - Set the current user and open a WebSocket connection
|
|
215
204
|
*
|
|
@@ -271,12 +260,6 @@ export class StreamClient {
|
|
|
271
260
|
(result) => result[1], // We only return connection promise;
|
|
272
261
|
);
|
|
273
262
|
|
|
274
|
-
if (this.resolveConnectPromise) {
|
|
275
|
-
this.resolveConnectPromise();
|
|
276
|
-
this.waitForConnectPromise = undefined;
|
|
277
|
-
this.resolveConnectPromise = undefined;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
263
|
try {
|
|
281
264
|
return await this.setUserPromise;
|
|
282
265
|
} catch (err) {
|
|
@@ -436,11 +419,6 @@ export class StreamClient {
|
|
|
436
419
|
this.anonymous = true;
|
|
437
420
|
await this._setToken(user, tokenOrProvider, this.anonymous);
|
|
438
421
|
|
|
439
|
-
if (this.resolveConnectPromise) {
|
|
440
|
-
this.resolveConnectPromise();
|
|
441
|
-
this.waitForConnectPromise = undefined;
|
|
442
|
-
this.resolveConnectPromise = undefined;
|
|
443
|
-
}
|
|
444
422
|
this._setUser(user);
|
|
445
423
|
// some endpoints require a connection_id to be resolved.
|
|
446
424
|
// as anonymous users aren't allowed to open WS connections, we just
|
|
@@ -526,9 +504,6 @@ export class StreamClient {
|
|
|
526
504
|
response,
|
|
527
505
|
},
|
|
528
506
|
);
|
|
529
|
-
this.logger('trace', `client:${type} - Response payload`, {
|
|
530
|
-
response,
|
|
531
|
-
});
|
|
532
507
|
};
|
|
533
508
|
|
|
534
509
|
_logApiError = (type: string, url: string, error: unknown) => {
|
|
@@ -547,9 +522,6 @@ export class StreamClient {
|
|
|
547
522
|
} & { publicEndpoint?: boolean } = {},
|
|
548
523
|
): Promise<T> => {
|
|
549
524
|
if (!options.publicEndpoint) {
|
|
550
|
-
if (this.waitForConnectPromise) {
|
|
551
|
-
await this.waitForConnectPromise;
|
|
552
|
-
}
|
|
553
525
|
await Promise.all([
|
|
554
526
|
this.tokenManager.tokenReady(),
|
|
555
527
|
this.connectionIdPromise,
|
|
@@ -587,9 +559,9 @@ export class StreamClient {
|
|
|
587
559
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
588
560
|
} catch (e: any /**TODO: generalize error types */) {
|
|
589
561
|
e.client_request_id = requestConfig.headers?.['x-client-request-id'];
|
|
590
|
-
this._logApiError(type, url, e);
|
|
591
562
|
this.consecutiveFailures += 1;
|
|
592
563
|
if (e.response) {
|
|
564
|
+
this._logApiError(type, url, e.response);
|
|
593
565
|
/** connection_fallback depends on this token expiration logic */
|
|
594
566
|
if (
|
|
595
567
|
e.response.data.code === KnownCodes.TOKEN_EXPIRED &&
|
|
@@ -603,6 +575,7 @@ export class StreamClient {
|
|
|
603
575
|
}
|
|
604
576
|
return this.handleResponse(e.response);
|
|
605
577
|
} else {
|
|
578
|
+
this._logApiError(type, url, e);
|
|
606
579
|
// eslint-disable-next-line no-throw-literal
|
|
607
580
|
throw e as AxiosError<APIErrorResponse>;
|
|
608
581
|
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { StreamVideoServerClient } from '../StreamVideoServerClient';
|
|
2
|
-
import 'dotenv/config';
|
|
3
|
-
import jwt from 'jsonwebtoken';
|
|
4
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
-
import { generateUUIDv4 } from '../coordinator/connection/utils';
|
|
6
|
-
|
|
7
|
-
const apiKey = process.env.STREAM_API_KEY!;
|
|
8
|
-
const secret = process.env.STREAM_SECRET!;
|
|
9
|
-
|
|
10
|
-
describe('StreamVideoServerClient - docs snippets', () => {
|
|
11
|
-
let client: StreamVideoServerClient;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
client = new StreamVideoServerClient(apiKey, {
|
|
15
|
-
secret,
|
|
16
|
-
// turn off
|
|
17
|
-
logger: () => {},
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('creating tokens', () => {
|
|
22
|
-
const userId = 'john';
|
|
23
|
-
|
|
24
|
-
it('with no expiration', () => {
|
|
25
|
-
const token = client.createToken(userId);
|
|
26
|
-
const decodedToken = jwt.verify(token, secret) as any;
|
|
27
|
-
|
|
28
|
-
expect(decodedToken.user_id).toBe(userId);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('with expiration and issued at provided', () => {
|
|
32
|
-
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
|
|
33
|
-
const iat = Math.round(new Date().getTime() / 1000);
|
|
34
|
-
const token = client.createToken(userId, exp, iat);
|
|
35
|
-
const decodedToken = jwt.verify(token, secret) as any;
|
|
36
|
-
|
|
37
|
-
expect(decodedToken.exp).toBe(exp);
|
|
38
|
-
expect(decodedToken.iat).toBe(iat);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('with call IDs provided', () => {
|
|
42
|
-
const call_cids = ['default:call1', 'livestream:call2'];
|
|
43
|
-
const token = client.createToken(userId, undefined, undefined, call_cids);
|
|
44
|
-
const decodedToken = jwt.verify(token, secret) as any;
|
|
45
|
-
|
|
46
|
-
expect(decodedToken.call_cids).toEqual(call_cids);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('call type CRUD API', () => {
|
|
51
|
-
const callTypeName = `calltype${generateUUIDv4()}`;
|
|
52
|
-
|
|
53
|
-
it('create', async () => {
|
|
54
|
-
const createResponse = await client.createCallType({
|
|
55
|
-
name: callTypeName,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(createResponse.name).toBe(callTypeName);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('read', async () => {
|
|
62
|
-
const readResponse = await client.getCallTypes();
|
|
63
|
-
|
|
64
|
-
expect(readResponse.call_types[callTypeName]).toContain({
|
|
65
|
-
name: callTypeName,
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('update', async () => {
|
|
70
|
-
const updateResponse = await client.updateCallType(callTypeName, {
|
|
71
|
-
settings: {
|
|
72
|
-
audio: { mic_default_on: false, default_device: 'earpiece' },
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
expect(updateResponse.settings.audio.mic_default_on).toBeFalsy();
|
|
77
|
-
expect(updateResponse.settings.audio.default_device).toBe('earpiece');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('delete', async () => {
|
|
81
|
-
await client.deleteCallType(callTypeName);
|
|
82
|
-
|
|
83
|
-
await expect(() =>
|
|
84
|
-
client.getCallType(callTypeName),
|
|
85
|
-
).rejects.toThrowError();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('StreamVideoServerClient - server side user connect', () => {
|
|
91
|
-
let client: StreamVideoServerClient;
|
|
92
|
-
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
client = new StreamVideoServerClient(apiKey, {
|
|
95
|
-
browser: false,
|
|
96
|
-
secret,
|
|
97
|
-
allowServerSideConnect: true,
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('hold up API requests until connect is ready', async () => {
|
|
102
|
-
const userId = 'server-side-test';
|
|
103
|
-
const token = client.createToken(userId);
|
|
104
|
-
client.connectUser({ id: userId }, token);
|
|
105
|
-
|
|
106
|
-
const response = await client.queryCalls({});
|
|
107
|
-
|
|
108
|
-
expect(response).toBeDefined();
|
|
109
|
-
});
|
|
110
|
-
});
|
/package/dist/src/__tests__/{StreamVideoServerClient.test.d.ts → server-side/call-members.test.d.ts}
RENAMED
|
File without changes
|