@stream-io/video-client 0.3.3 → 0.3.4
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 +7 -0
- package/dist/index.browser.es.js +11 -5
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +11 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +11 -5
- package/dist/index.es.js.map +1 -1
- package/dist/src/coordinator/connection/client.d.ts +9 -4
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/StreamVideoClient.ts +1 -10
- package/src/__tests__/StreamVideoClient.test.ts +13 -0
- package/src/coordinator/connection/client.ts +28 -0
|
@@ -4,8 +4,9 @@ import WebSocket from 'isomorphic-ws';
|
|
|
4
4
|
import { StableWSConnection } from './connection';
|
|
5
5
|
import { TokenManager } from './token_manager';
|
|
6
6
|
import { WSConnectionFallback } from './connection_fallback';
|
|
7
|
-
import { APIErrorResponse, ConnectAPIResponse, ErrorFromResponse, EventHandler, Logger, StreamClientOptions, StreamVideoEvent, TokenOrProvider, UserWithId } from './types';
|
|
7
|
+
import { APIErrorResponse, ConnectAPIResponse, ErrorFromResponse, EventHandler, Logger, StreamClientOptions, StreamVideoEvent, TokenOrProvider, User, UserWithId } from './types';
|
|
8
8
|
import { InsightMetrics } from './insights';
|
|
9
|
+
import { CreateGuestResponse } from '../../gen/coordinator';
|
|
9
10
|
export declare class StreamClient {
|
|
10
11
|
_user?: UserWithId;
|
|
11
12
|
anonymous: boolean;
|
|
@@ -38,6 +39,7 @@ export declare class StreamClient {
|
|
|
38
39
|
resolveConnectionId?: Function;
|
|
39
40
|
rejectConnectionId?: Function;
|
|
40
41
|
connectionIdPromise?: Promise<string | undefined>;
|
|
42
|
+
guestUserCreatePromise?: Promise<CreateGuestResponse>;
|
|
41
43
|
private nextRequestAbortController;
|
|
42
44
|
/**
|
|
43
45
|
* Initialize a client.
|
|
@@ -66,7 +68,7 @@ export declare class StreamClient {
|
|
|
66
68
|
*
|
|
67
69
|
* @return {ConnectAPIResponse} Returns a promise that resolves when the connection is setup
|
|
68
70
|
*/
|
|
69
|
-
connectUser: (user: UserWithId, userTokenOrProvider: TokenOrProvider) => Promise<void | import("
|
|
71
|
+
connectUser: (user: UserWithId, userTokenOrProvider: TokenOrProvider) => Promise<void | import("../../gen/coordinator").ConnectedEvent>;
|
|
70
72
|
_setToken: (user: UserWithId, userTokenOrProvider: TokenOrProvider, isAnonymous: boolean) => Promise<void>;
|
|
71
73
|
_setUser: (user: UserWithId) => void;
|
|
72
74
|
/**
|
|
@@ -86,7 +88,7 @@ export declare class StreamClient {
|
|
|
86
88
|
/**
|
|
87
89
|
* Creates a new WebSocket connection with the current user. Returns empty promise, if there is an active connection
|
|
88
90
|
*/
|
|
89
|
-
openConnection: () => Promise<void | import("
|
|
91
|
+
openConnection: () => Promise<void | import("../../gen/coordinator").ConnectedEvent>;
|
|
90
92
|
_normalizeDate: (before: Date | string | null) => string | null;
|
|
91
93
|
/**
|
|
92
94
|
* Disconnects the websocket and removes the user from client.
|
|
@@ -95,6 +97,9 @@ export declare class StreamClient {
|
|
|
95
97
|
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
96
98
|
*/
|
|
97
99
|
disconnectUser: (timeout?: number) => Promise<void>;
|
|
100
|
+
connectGuestUser: (user: User & {
|
|
101
|
+
type: 'guest';
|
|
102
|
+
}) => Promise<void | import("../../gen/coordinator").ConnectedEvent>;
|
|
98
103
|
/**
|
|
99
104
|
* connectAnonymousUser - Set an anonymous user and open a WebSocket connection
|
|
100
105
|
*/
|
|
@@ -144,7 +149,7 @@ export declare class StreamClient {
|
|
|
144
149
|
/**
|
|
145
150
|
* @private
|
|
146
151
|
*/
|
|
147
|
-
connect: () => Promise<void | import("
|
|
152
|
+
connect: () => Promise<void | import("../../gen/coordinator").ConnectedEvent>;
|
|
148
153
|
/**
|
|
149
154
|
* Check the connectivity with server for warmup purpose.
|
|
150
155
|
*
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.3.
|
|
1
|
+
export declare const version = "0.3.4";
|
package/package.json
CHANGED
package/src/StreamVideoClient.ts
CHANGED
|
@@ -152,16 +152,7 @@ export class StreamVideoClient {
|
|
|
152
152
|
};
|
|
153
153
|
if (user.type === 'guest') {
|
|
154
154
|
connectUser = async () => {
|
|
155
|
-
|
|
156
|
-
user: {
|
|
157
|
-
...user,
|
|
158
|
-
role: 'guest',
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
return this.streamClient.connectUser(
|
|
162
|
-
response.user,
|
|
163
|
-
response.access_token,
|
|
164
|
-
);
|
|
155
|
+
return this.streamClient.connectGuestUser(user);
|
|
165
156
|
};
|
|
166
157
|
}
|
|
167
158
|
this.connectionPromise = this.disconnectionPromise
|
|
@@ -3,6 +3,7 @@ import { StreamVideoClient } from '../StreamVideoClient';
|
|
|
3
3
|
import 'dotenv/config';
|
|
4
4
|
import { generateUUIDv4 } from '../coordinator/connection/utils';
|
|
5
5
|
import { StreamVideoServerClient } from '../StreamVideoServerClient';
|
|
6
|
+
import { User } from '../coordinator/connection/types';
|
|
6
7
|
|
|
7
8
|
const apiKey = process.env.STREAM_API_KEY!;
|
|
8
9
|
const secret = process.env.STREAM_SECRET!;
|
|
@@ -87,6 +88,18 @@ describe('StreamVideoClient', () => {
|
|
|
87
88
|
);
|
|
88
89
|
});
|
|
89
90
|
|
|
91
|
+
it('API calls should be hold until auth is done - guest user', async () => {
|
|
92
|
+
const user: User = {
|
|
93
|
+
id: 'jane-guest',
|
|
94
|
+
type: 'guest',
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
client.connectUser(user);
|
|
98
|
+
const response = await client.queryCalls({});
|
|
99
|
+
|
|
100
|
+
expect(response.calls).toBeDefined();
|
|
101
|
+
});
|
|
102
|
+
|
|
90
103
|
afterEach(() => {
|
|
91
104
|
client.disconnectUser();
|
|
92
105
|
});
|
|
@@ -30,11 +30,13 @@ import {
|
|
|
30
30
|
StreamClientOptions,
|
|
31
31
|
StreamVideoEvent,
|
|
32
32
|
TokenOrProvider,
|
|
33
|
+
User,
|
|
33
34
|
UserWithId,
|
|
34
35
|
} from './types';
|
|
35
36
|
import { InsightMetrics, postInsights } from './insights';
|
|
36
37
|
import { version } from '../../../version';
|
|
37
38
|
import { getLocationHint } from './location';
|
|
39
|
+
import { CreateGuestRequest, CreateGuestResponse } from '../../gen/coordinator';
|
|
38
40
|
|
|
39
41
|
export class StreamClient {
|
|
40
42
|
_user?: UserWithId;
|
|
@@ -70,6 +72,7 @@ export class StreamClient {
|
|
|
70
72
|
resolveConnectionId?: Function;
|
|
71
73
|
rejectConnectionId?: Function;
|
|
72
74
|
connectionIdPromise?: Promise<string | undefined>;
|
|
75
|
+
guestUserCreatePromise?: Promise<CreateGuestResponse>;
|
|
73
76
|
private nextRequestAbortController: AbortController | null = null;
|
|
74
77
|
|
|
75
78
|
/**
|
|
@@ -402,6 +405,30 @@ export class StreamClient {
|
|
|
402
405
|
this.resolveConnectionId = undefined;
|
|
403
406
|
};
|
|
404
407
|
|
|
408
|
+
connectGuestUser = async (user: User & { type: 'guest' }) => {
|
|
409
|
+
this.guestUserCreatePromise = this.doAxiosRequest<
|
|
410
|
+
CreateGuestResponse,
|
|
411
|
+
CreateGuestRequest
|
|
412
|
+
>(
|
|
413
|
+
'post',
|
|
414
|
+
'/guest',
|
|
415
|
+
{
|
|
416
|
+
user: {
|
|
417
|
+
...user,
|
|
418
|
+
role: 'guest',
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
{ publicEndpoint: true },
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
const response = await this.guestUserCreatePromise;
|
|
425
|
+
this.guestUserCreatePromise.finally(
|
|
426
|
+
() => (this.guestUserCreatePromise = undefined),
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
return this.connectUser(response.user, response.access_token);
|
|
430
|
+
};
|
|
431
|
+
|
|
405
432
|
/**
|
|
406
433
|
* connectAnonymousUser - Set an anonymous user and open a WebSocket connection
|
|
407
434
|
*/
|
|
@@ -524,6 +551,7 @@ export class StreamClient {
|
|
|
524
551
|
if (!options.publicEndpoint) {
|
|
525
552
|
await Promise.all([
|
|
526
553
|
this.tokenManager.tokenReady(),
|
|
554
|
+
this.guestUserCreatePromise,
|
|
527
555
|
this.connectionIdPromise,
|
|
528
556
|
]);
|
|
529
557
|
}
|