@stream-io/video-client 0.1.0 → 0.1.2
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 +33 -34
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +33 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +33 -34
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamVideoClient.d.ts +8 -25
- package/dist/src/StreamVideoServerClient.d.ts +23 -0
- package/dist/src/__tests__/StreamVideoServerClient.test.d.ts +1 -0
- package/dist/src/coordinator/connection/client.d.ts +1 -1
- package/dist/src/gen/coordinator/index.d.ts +12 -24
- package/dist/version.d.ts +1 -1
- package/index.ts +1 -0
- package/package.json +2 -1
- package/src/StreamVideoClient.ts +5 -55
- package/src/StreamVideoServerClient.ts +59 -0
- package/src/__tests__/StreamVideoServerClient.test.ts +88 -0
- package/src/coordinator/connection/client.ts +7 -7
- package/src/events/__tests__/sessions.test.ts +14 -12
- package/src/events/sessions.ts +4 -12
- package/src/gen/coordinator/index.ts +12 -24
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Call } from './Call';
|
|
2
2
|
import { StreamClient } from './coordinator/connection/client';
|
|
3
|
-
import { StreamVideoReadOnlyStateStore } from './store';
|
|
4
|
-
import type { ConnectedEvent,
|
|
5
|
-
import type { EventHandler, EventTypes, Logger, StreamClientOptions, TokenOrProvider, TokenProvider, User } from './coordinator/connection/types';
|
|
3
|
+
import { StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore } from './store';
|
|
4
|
+
import type { ConnectedEvent, CreateDeviceRequest, CreateGuestRequest, CreateGuestResponse, GetEdgesResponse, ListDevicesResponse, QueryCallsRequest } from './gen/coordinator';
|
|
5
|
+
import type { EventHandler, EventTypes, Logger, StreamClientOptions, TokenOrProvider, TokenProvider, User, UserWithId } from './coordinator/connection/types';
|
|
6
6
|
/**
|
|
7
7
|
* A `StreamVideoClient` instance lets you communicate with our API, and authenticate users.
|
|
8
8
|
*/
|
|
@@ -14,11 +14,11 @@ export declare class StreamVideoClient {
|
|
|
14
14
|
readonly user?: User;
|
|
15
15
|
readonly token?: TokenOrProvider;
|
|
16
16
|
readonly logger: Logger;
|
|
17
|
-
|
|
17
|
+
protected readonly writeableStateStore: StreamVideoWriteableStateStore;
|
|
18
18
|
streamClient: StreamClient;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
protected eventHandlersToUnregister: Array<() => void>;
|
|
20
|
+
protected connectionPromise: Promise<void | ConnectedEvent> | undefined;
|
|
21
|
+
protected disconnectionPromise: Promise<void> | undefined;
|
|
22
22
|
/**
|
|
23
23
|
* You should create only one instance of `StreamVideoClient`.
|
|
24
24
|
*/
|
|
@@ -91,11 +91,6 @@ export declare class StreamVideoClient {
|
|
|
91
91
|
}>;
|
|
92
92
|
queryUsers: () => Promise<void>;
|
|
93
93
|
edges: () => Promise<GetEdgesResponse>;
|
|
94
|
-
createCallType: (data: CreateCallTypeRequest) => Promise<CreateCallTypeResponse>;
|
|
95
|
-
getCallType: (name: string) => Promise<GetCallTypeResponse>;
|
|
96
|
-
updateCallType: (name: string, data: UpdateCallTypeRequest) => Promise<UpdateCallTypeResponse>;
|
|
97
|
-
deleteCallType: (name: string) => Promise<unknown>;
|
|
98
|
-
listCallTypes: () => Promise<ListCallTypeResponse>;
|
|
99
94
|
/**
|
|
100
95
|
* addDevice - Adds a push device for a user.
|
|
101
96
|
*
|
|
@@ -128,18 +123,6 @@ export declare class StreamVideoClient {
|
|
|
128
123
|
*
|
|
129
124
|
*/
|
|
130
125
|
removeDevice: (id: string, userID?: string) => Promise<unknown>;
|
|
131
|
-
/**
|
|
132
|
-
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
133
|
-
* The resulting token should be passed to the client side when the users register or logs in.
|
|
134
|
-
*
|
|
135
|
-
* @param {string} userID The User ID
|
|
136
|
-
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
137
|
-
* @param {number} [iat] The timestamp when a token has been issued
|
|
138
|
-
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
139
|
-
*
|
|
140
|
-
* @return {string} Returns a token
|
|
141
|
-
*/
|
|
142
|
-
createToken(userID: string, exp?: number, iat?: number, call_cids?: string[]): string;
|
|
143
126
|
/**
|
|
144
127
|
* A callback that can be used to create ringing calls from push notifications. If the call already exists, it will do nothing.
|
|
145
128
|
* @param call_cid
|
|
@@ -152,5 +135,5 @@ export declare class StreamVideoClient {
|
|
|
152
135
|
* @param user the user to connect.
|
|
153
136
|
* @param tokenOrProvider a token or a function that returns a token.
|
|
154
137
|
*/
|
|
155
|
-
|
|
138
|
+
protected connectAnonymousUser: (user: UserWithId, tokenOrProvider: TokenOrProvider) => Promise<void | ConnectedEvent>;
|
|
156
139
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StreamVideoClient } from './StreamVideoClient';
|
|
2
|
+
import { StreamClientOptions } from './coordinator/connection/types';
|
|
3
|
+
import { CreateCallTypeRequest, CreateCallTypeResponse, GetCallTypeResponse, ListCallTypeResponse, UpdateCallTypeRequest, UpdateCallTypeResponse } from './gen/coordinator';
|
|
4
|
+
export declare class StreamVideoServerClient extends StreamVideoClient {
|
|
5
|
+
constructor(apiKey: string, options: StreamClientOptions);
|
|
6
|
+
/**
|
|
7
|
+
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
8
|
+
* The resulting token should be passed to the client side when the users register or logs in.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} userID The User ID
|
|
11
|
+
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
12
|
+
* @param {number} [iat] The timestamp when a token has been issued
|
|
13
|
+
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
14
|
+
*
|
|
15
|
+
* @return {string} Returns a token
|
|
16
|
+
*/
|
|
17
|
+
createToken(userID: string, exp?: number, iat?: number, call_cids?: string[]): string;
|
|
18
|
+
getCallTypes: () => Promise<ListCallTypeResponse>;
|
|
19
|
+
getCallType: (name: string) => Promise<GetCallTypeResponse>;
|
|
20
|
+
createCallType: (data: CreateCallTypeRequest) => Promise<CreateCallTypeResponse>;
|
|
21
|
+
deleteCallType: (name: string) => Promise<void>;
|
|
22
|
+
updateCallType: (name: string, data: UpdateCallTypeRequest) => Promise<UpdateCallTypeResponse>;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
@@ -37,7 +37,7 @@ export declare class StreamClient {
|
|
|
37
37
|
defaultWSTimeout: number;
|
|
38
38
|
resolveConnectionId: Function;
|
|
39
39
|
rejectConnectionId: Function;
|
|
40
|
-
connectionIdPromise
|
|
40
|
+
connectionIdPromise?: Promise<string | undefined>;
|
|
41
41
|
private nextRequestAbortController;
|
|
42
42
|
private waitForConnectPromise?;
|
|
43
43
|
private resolveConnectPromise?;
|
|
@@ -1180,6 +1180,12 @@ export interface CallSessionParticipantJoinedEvent {
|
|
|
1180
1180
|
* @memberof CallSessionParticipantJoinedEvent
|
|
1181
1181
|
*/
|
|
1182
1182
|
created_at: string;
|
|
1183
|
+
/**
|
|
1184
|
+
*
|
|
1185
|
+
* @type {CallParticipantResponse}
|
|
1186
|
+
* @memberof CallSessionParticipantJoinedEvent
|
|
1187
|
+
*/
|
|
1188
|
+
participant: CallParticipantResponse;
|
|
1183
1189
|
/**
|
|
1184
1190
|
* Call session ID
|
|
1185
1191
|
* @type {string}
|
|
@@ -1192,18 +1198,6 @@ export interface CallSessionParticipantJoinedEvent {
|
|
|
1192
1198
|
* @memberof CallSessionParticipantJoinedEvent
|
|
1193
1199
|
*/
|
|
1194
1200
|
type: string;
|
|
1195
|
-
/**
|
|
1196
|
-
*
|
|
1197
|
-
* @type {UserResponse}
|
|
1198
|
-
* @memberof CallSessionParticipantJoinedEvent
|
|
1199
|
-
*/
|
|
1200
|
-
user: UserResponse;
|
|
1201
|
-
/**
|
|
1202
|
-
* The user session ID of the user that joined the call session
|
|
1203
|
-
* @type {string}
|
|
1204
|
-
* @memberof CallSessionParticipantJoinedEvent
|
|
1205
|
-
*/
|
|
1206
|
-
user_session_id: string;
|
|
1207
1201
|
}
|
|
1208
1202
|
/**
|
|
1209
1203
|
* This event is sent when a participant leaves a call session
|
|
@@ -1223,6 +1217,12 @@ export interface CallSessionParticipantLeftEvent {
|
|
|
1223
1217
|
* @memberof CallSessionParticipantLeftEvent
|
|
1224
1218
|
*/
|
|
1225
1219
|
created_at: string;
|
|
1220
|
+
/**
|
|
1221
|
+
*
|
|
1222
|
+
* @type {CallParticipantResponse}
|
|
1223
|
+
* @memberof CallSessionParticipantLeftEvent
|
|
1224
|
+
*/
|
|
1225
|
+
participant: CallParticipantResponse;
|
|
1226
1226
|
/**
|
|
1227
1227
|
* Call session ID
|
|
1228
1228
|
* @type {string}
|
|
@@ -1235,18 +1235,6 @@ export interface CallSessionParticipantLeftEvent {
|
|
|
1235
1235
|
* @memberof CallSessionParticipantLeftEvent
|
|
1236
1236
|
*/
|
|
1237
1237
|
type: string;
|
|
1238
|
-
/**
|
|
1239
|
-
*
|
|
1240
|
-
* @type {UserResponse}
|
|
1241
|
-
* @memberof CallSessionParticipantLeftEvent
|
|
1242
|
-
*/
|
|
1243
|
-
user: UserResponse;
|
|
1244
|
-
/**
|
|
1245
|
-
* The user session ID of the user that left the call session
|
|
1246
|
-
* @type {string}
|
|
1247
|
-
* @memberof CallSessionParticipantLeftEvent
|
|
1248
|
-
*/
|
|
1249
|
-
user_session_id: string;
|
|
1250
1238
|
}
|
|
1251
1239
|
/**
|
|
1252
1240
|
*
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.1.
|
|
1
|
+
export declare const version = "0.1.2";
|
package/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './src/stats/types';
|
|
|
13
13
|
export * from './src/Call';
|
|
14
14
|
export * from './src/CallType';
|
|
15
15
|
export * from './src/StreamVideoClient';
|
|
16
|
+
export * from './src/StreamVideoServerClient';
|
|
16
17
|
export * from './src/StreamSfuClient';
|
|
17
18
|
export * from './src/devices';
|
|
18
19
|
export * from './src/store';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"packageManager": "yarn@3.2.4",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@types/ua-parser-js": "^0.7.36",
|
|
54
54
|
"@types/ws": "^8.5.4",
|
|
55
55
|
"@vitest/coverage-c8": "^0.31.0",
|
|
56
|
+
"dotenv": "^16.3.1",
|
|
56
57
|
"prettier": "^2.8.4",
|
|
57
58
|
"rimraf": "^3.0.2",
|
|
58
59
|
"rollup": "^3.25.1",
|
package/src/StreamVideoClient.ts
CHANGED
|
@@ -6,19 +6,13 @@ import {
|
|
|
6
6
|
} from './store';
|
|
7
7
|
import type {
|
|
8
8
|
ConnectedEvent,
|
|
9
|
-
CreateCallTypeRequest,
|
|
10
|
-
CreateCallTypeResponse,
|
|
11
9
|
CreateDeviceRequest,
|
|
12
10
|
CreateGuestRequest,
|
|
13
11
|
CreateGuestResponse,
|
|
14
|
-
GetCallTypeResponse,
|
|
15
12
|
GetEdgesResponse,
|
|
16
|
-
ListCallTypeResponse,
|
|
17
13
|
ListDevicesResponse,
|
|
18
14
|
QueryCallsRequest,
|
|
19
15
|
QueryCallsResponse,
|
|
20
|
-
UpdateCallTypeRequest,
|
|
21
|
-
UpdateCallTypeResponse,
|
|
22
16
|
} from './gen/coordinator';
|
|
23
17
|
import type {
|
|
24
18
|
ConnectionChangedEvent,
|
|
@@ -48,12 +42,12 @@ export class StreamVideoClient {
|
|
|
48
42
|
readonly token?: TokenOrProvider;
|
|
49
43
|
readonly logger: Logger;
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+
protected readonly writeableStateStore: StreamVideoWriteableStateStore;
|
|
52
46
|
streamClient: StreamClient;
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
protected eventHandlersToUnregister: Array<() => void> = [];
|
|
49
|
+
protected connectionPromise: Promise<void | ConnectedEvent> | undefined;
|
|
50
|
+
protected disconnectionPromise: Promise<void> | undefined;
|
|
57
51
|
|
|
58
52
|
/**
|
|
59
53
|
* You should create only one instance of `StreamVideoClient`.
|
|
@@ -379,30 +373,6 @@ export class StreamVideoClient {
|
|
|
379
373
|
return this.streamClient.get<GetEdgesResponse>(`/edges`);
|
|
380
374
|
};
|
|
381
375
|
|
|
382
|
-
// server-side only endpoints
|
|
383
|
-
createCallType = async (data: CreateCallTypeRequest) => {
|
|
384
|
-
return this.streamClient.post<CreateCallTypeResponse>(`/calltypes`, data);
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
getCallType = async (name: string) => {
|
|
388
|
-
return this.streamClient.get<GetCallTypeResponse>(`/calltypes/${name}`);
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
updateCallType = async (name: string, data: UpdateCallTypeRequest) => {
|
|
392
|
-
return this.streamClient.put<UpdateCallTypeResponse>(
|
|
393
|
-
`/calltypes/${name}`,
|
|
394
|
-
data,
|
|
395
|
-
);
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
deleteCallType = async (name: string) => {
|
|
399
|
-
return this.streamClient.delete(`/calltypes/${name}`);
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
listCallTypes = async () => {
|
|
403
|
-
return this.streamClient.get<ListCallTypeResponse>(`/calltypes`);
|
|
404
|
-
};
|
|
405
|
-
|
|
406
376
|
/**
|
|
407
377
|
* addDevice - Adds a push device for a user.
|
|
408
378
|
*
|
|
@@ -476,26 +446,6 @@ export class StreamVideoClient {
|
|
|
476
446
|
});
|
|
477
447
|
};
|
|
478
448
|
|
|
479
|
-
/**
|
|
480
|
-
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
481
|
-
* The resulting token should be passed to the client side when the users register or logs in.
|
|
482
|
-
*
|
|
483
|
-
* @param {string} userID The User ID
|
|
484
|
-
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
485
|
-
* @param {number} [iat] The timestamp when a token has been issued
|
|
486
|
-
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
487
|
-
*
|
|
488
|
-
* @return {string} Returns a token
|
|
489
|
-
*/
|
|
490
|
-
createToken(
|
|
491
|
-
userID: string,
|
|
492
|
-
exp?: number,
|
|
493
|
-
iat?: number,
|
|
494
|
-
call_cids?: string[],
|
|
495
|
-
) {
|
|
496
|
-
return this.streamClient.createToken(userID, exp, iat, call_cids);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
449
|
/**
|
|
500
450
|
* A callback that can be used to create ringing calls from push notifications. If the call already exists, it will do nothing.
|
|
501
451
|
* @param call_cid
|
|
@@ -529,7 +479,7 @@ export class StreamVideoClient {
|
|
|
529
479
|
* @param user the user to connect.
|
|
530
480
|
* @param tokenOrProvider a token or a function that returns a token.
|
|
531
481
|
*/
|
|
532
|
-
|
|
482
|
+
protected connectAnonymousUser = async (
|
|
533
483
|
user: UserWithId,
|
|
534
484
|
tokenOrProvider: TokenOrProvider,
|
|
535
485
|
) => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { StreamVideoClient } from './StreamVideoClient';
|
|
2
|
+
import { StreamClientOptions } from './coordinator/connection/types';
|
|
3
|
+
import {
|
|
4
|
+
CreateCallTypeRequest,
|
|
5
|
+
CreateCallTypeResponse,
|
|
6
|
+
GetCallTypeResponse,
|
|
7
|
+
ListCallTypeResponse,
|
|
8
|
+
UpdateCallTypeRequest,
|
|
9
|
+
UpdateCallTypeResponse,
|
|
10
|
+
} from './gen/coordinator';
|
|
11
|
+
|
|
12
|
+
export class StreamVideoServerClient extends StreamVideoClient {
|
|
13
|
+
constructor(apiKey: string, options: StreamClientOptions) {
|
|
14
|
+
super({ apiKey, options });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* createToken - Creates a token to authenticate this user. This function is used server side.
|
|
19
|
+
* The resulting token should be passed to the client side when the users register or logs in.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} userID The User ID
|
|
22
|
+
* @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
|
|
23
|
+
* @param {number} [iat] The timestamp when a token has been issued
|
|
24
|
+
* @param call_cids for anonymous tokens you have to provide the call cids the use can join
|
|
25
|
+
*
|
|
26
|
+
* @return {string} Returns a token
|
|
27
|
+
*/
|
|
28
|
+
createToken(
|
|
29
|
+
userID: string,
|
|
30
|
+
exp?: number,
|
|
31
|
+
iat?: number,
|
|
32
|
+
call_cids?: string[],
|
|
33
|
+
) {
|
|
34
|
+
return this.streamClient.createToken(userID, exp, iat, call_cids);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getCallTypes = () => {
|
|
38
|
+
return this.streamClient.get<ListCallTypeResponse>('/calltypes');
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
getCallType = (name: string) => {
|
|
42
|
+
return this.streamClient.get<GetCallTypeResponse>(`/calltypes/${name}`);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
createCallType = (data: CreateCallTypeRequest) => {
|
|
46
|
+
return this.streamClient.post<CreateCallTypeResponse>('/calltypes', data);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
deleteCallType = (name: string) => {
|
|
50
|
+
return this.streamClient.delete<void>(`/calltypes/${name}`);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
updateCallType = (name: string, data: UpdateCallTypeRequest) => {
|
|
54
|
+
return this.streamClient.put<UpdateCallTypeResponse>(
|
|
55
|
+
`/calltypes/${name}`,
|
|
56
|
+
data,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
});
|
|
@@ -69,7 +69,7 @@ export class StreamClient {
|
|
|
69
69
|
defaultWSTimeout: number;
|
|
70
70
|
resolveConnectionId!: Function;
|
|
71
71
|
rejectConnectionId!: Function;
|
|
72
|
-
connectionIdPromise
|
|
72
|
+
connectionIdPromise?: Promise<string | undefined>;
|
|
73
73
|
private nextRequestAbortController: AbortController | null = null;
|
|
74
74
|
private waitForConnectPromise?: Promise<void>;
|
|
75
75
|
private resolveConnectPromise?: Function;
|
|
@@ -125,12 +125,12 @@ export class StreamClient {
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
this.connectionIdPromise =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
this.connectionIdPromise = this.secret
|
|
129
|
+
? undefined
|
|
130
|
+
: new Promise<string | undefined>((resolve, reject) => {
|
|
131
|
+
this.resolveConnectionId = resolve;
|
|
132
|
+
this.rejectConnectionId = reject;
|
|
133
|
+
});
|
|
134
134
|
|
|
135
135
|
this.setBaseURL(
|
|
136
136
|
this.options.baseURL || 'https://video.stream-io-api.com/video',
|
|
@@ -63,24 +63,24 @@ describe('call.session events', () => {
|
|
|
63
63
|
const handler = watchCallSessionParticipantJoined(state);
|
|
64
64
|
handler({
|
|
65
65
|
type: 'call.session_participant_joined',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
participant: {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
user: {
|
|
69
|
+
id: 'user-id',
|
|
70
|
+
role: 'user',
|
|
71
|
+
},
|
|
72
|
+
user_session_id: '123',
|
|
70
73
|
},
|
|
71
|
-
user_session_id: '123',
|
|
72
74
|
});
|
|
73
75
|
expect(state.metadata).toEqual({
|
|
74
76
|
session: {
|
|
75
77
|
participants: [
|
|
76
78
|
{
|
|
77
|
-
joined_at: expect.any(String),
|
|
78
79
|
user: {
|
|
79
80
|
id: 'user-id',
|
|
80
81
|
role: 'user',
|
|
81
82
|
},
|
|
82
83
|
user_session_id: '123',
|
|
83
|
-
role: 'user',
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
86
|
participants_count_by_role: {
|
|
@@ -114,12 +114,14 @@ describe('call.session events', () => {
|
|
|
114
114
|
const handler = watchCallSessionParticipantLeft(state);
|
|
115
115
|
handler({
|
|
116
116
|
type: 'call.session_participant_left',
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
participant: {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
user: {
|
|
120
|
+
id: 'user-id',
|
|
121
|
+
role: 'user',
|
|
122
|
+
},
|
|
123
|
+
user_session_id: '123',
|
|
121
124
|
},
|
|
122
|
-
user_session_id: '123',
|
|
123
125
|
});
|
|
124
126
|
expect(state.metadata).toEqual({
|
|
125
127
|
session: {
|
package/src/events/sessions.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const watchCallSessionEnded = (state: CallState) => {
|
|
|
33
33
|
export const watchCallSessionParticipantJoined = (state: CallState) => {
|
|
34
34
|
return function onCallParticipantJoined(event: StreamVideoEvent) {
|
|
35
35
|
if (event.type !== 'call.session_participant_joined') return;
|
|
36
|
-
const {
|
|
36
|
+
const { participant } = event;
|
|
37
37
|
state.setMetadata((metadata) => {
|
|
38
38
|
if (!metadata || !metadata.session) {
|
|
39
39
|
state.logger(
|
|
@@ -45,20 +45,12 @@ export const watchCallSessionParticipantJoined = (state: CallState) => {
|
|
|
45
45
|
}
|
|
46
46
|
const { session } = metadata;
|
|
47
47
|
const { participants, participants_count_by_role } = session;
|
|
48
|
+
const { user } = participant;
|
|
48
49
|
return {
|
|
49
50
|
...metadata,
|
|
50
51
|
session: {
|
|
51
52
|
...session,
|
|
52
|
-
participants: [
|
|
53
|
-
...participants,
|
|
54
|
-
{
|
|
55
|
-
// FIXME OL: ideally, this comes from the backend
|
|
56
|
-
joined_at: new Date().toISOString(),
|
|
57
|
-
user,
|
|
58
|
-
role: user.role,
|
|
59
|
-
user_session_id,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
53
|
+
participants: [...participants, participant],
|
|
62
54
|
participants_count_by_role: {
|
|
63
55
|
...participants_count_by_role,
|
|
64
56
|
[user.role]: (participants_count_by_role[user.role] || 0) + 1,
|
|
@@ -77,7 +69,7 @@ export const watchCallSessionParticipantJoined = (state: CallState) => {
|
|
|
77
69
|
export const watchCallSessionParticipantLeft = (state: CallState) => {
|
|
78
70
|
return function onCallParticipantLeft(event: StreamVideoEvent) {
|
|
79
71
|
if (event.type !== 'call.session_participant_left') return;
|
|
80
|
-
const { user, user_session_id } = event;
|
|
72
|
+
const { user, user_session_id } = event.participant;
|
|
81
73
|
state.setMetadata((metadata) => {
|
|
82
74
|
if (!metadata || !metadata.session) {
|
|
83
75
|
state.logger(
|
|
@@ -1180,6 +1180,12 @@ export interface CallSessionParticipantJoinedEvent {
|
|
|
1180
1180
|
* @memberof CallSessionParticipantJoinedEvent
|
|
1181
1181
|
*/
|
|
1182
1182
|
created_at: string;
|
|
1183
|
+
/**
|
|
1184
|
+
*
|
|
1185
|
+
* @type {CallParticipantResponse}
|
|
1186
|
+
* @memberof CallSessionParticipantJoinedEvent
|
|
1187
|
+
*/
|
|
1188
|
+
participant: CallParticipantResponse;
|
|
1183
1189
|
/**
|
|
1184
1190
|
* Call session ID
|
|
1185
1191
|
* @type {string}
|
|
@@ -1192,18 +1198,6 @@ export interface CallSessionParticipantJoinedEvent {
|
|
|
1192
1198
|
* @memberof CallSessionParticipantJoinedEvent
|
|
1193
1199
|
*/
|
|
1194
1200
|
type: string;
|
|
1195
|
-
/**
|
|
1196
|
-
*
|
|
1197
|
-
* @type {UserResponse}
|
|
1198
|
-
* @memberof CallSessionParticipantJoinedEvent
|
|
1199
|
-
*/
|
|
1200
|
-
user: UserResponse;
|
|
1201
|
-
/**
|
|
1202
|
-
* The user session ID of the user that joined the call session
|
|
1203
|
-
* @type {string}
|
|
1204
|
-
* @memberof CallSessionParticipantJoinedEvent
|
|
1205
|
-
*/
|
|
1206
|
-
user_session_id: string;
|
|
1207
1201
|
}
|
|
1208
1202
|
/**
|
|
1209
1203
|
* This event is sent when a participant leaves a call session
|
|
@@ -1223,6 +1217,12 @@ export interface CallSessionParticipantLeftEvent {
|
|
|
1223
1217
|
* @memberof CallSessionParticipantLeftEvent
|
|
1224
1218
|
*/
|
|
1225
1219
|
created_at: string;
|
|
1220
|
+
/**
|
|
1221
|
+
*
|
|
1222
|
+
* @type {CallParticipantResponse}
|
|
1223
|
+
* @memberof CallSessionParticipantLeftEvent
|
|
1224
|
+
*/
|
|
1225
|
+
participant: CallParticipantResponse;
|
|
1226
1226
|
/**
|
|
1227
1227
|
* Call session ID
|
|
1228
1228
|
* @type {string}
|
|
@@ -1235,18 +1235,6 @@ export interface CallSessionParticipantLeftEvent {
|
|
|
1235
1235
|
* @memberof CallSessionParticipantLeftEvent
|
|
1236
1236
|
*/
|
|
1237
1237
|
type: string;
|
|
1238
|
-
/**
|
|
1239
|
-
*
|
|
1240
|
-
* @type {UserResponse}
|
|
1241
|
-
* @memberof CallSessionParticipantLeftEvent
|
|
1242
|
-
*/
|
|
1243
|
-
user: UserResponse;
|
|
1244
|
-
/**
|
|
1245
|
-
* The user session ID of the user that left the call session
|
|
1246
|
-
* @type {string}
|
|
1247
|
-
* @memberof CallSessionParticipantLeftEvent
|
|
1248
|
-
*/
|
|
1249
|
-
user_session_id: string;
|
|
1250
1238
|
}
|
|
1251
1239
|
/**
|
|
1252
1240
|
*
|