@stream-io/video-client 1.4.8 → 1.5.0-0
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 +231 -0
- package/dist/index.browser.es.js +1976 -1476
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +1974 -1473
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1976 -1476
- package/dist/index.es.js.map +1 -1
- package/dist/src/Call.d.ts +93 -9
- package/dist/src/StreamSfuClient.d.ts +72 -56
- package/dist/src/StreamVideoClient.d.ts +2 -2
- package/dist/src/coordinator/connection/client.d.ts +3 -4
- package/dist/src/coordinator/connection/types.d.ts +5 -1
- package/dist/src/devices/InputMediaDeviceManager.d.ts +4 -0
- package/dist/src/devices/MicrophoneManager.d.ts +1 -1
- package/dist/src/events/callEventHandlers.d.ts +1 -3
- package/dist/src/events/internal.d.ts +4 -0
- package/dist/src/gen/video/sfu/event/events.d.ts +106 -4
- package/dist/src/gen/video/sfu/models/models.d.ts +64 -65
- package/dist/src/helpers/ensureExhausted.d.ts +1 -0
- package/dist/src/helpers/withResolvers.d.ts +14 -0
- package/dist/src/logger.d.ts +1 -0
- package/dist/src/rpc/createClient.d.ts +2 -0
- package/dist/src/rpc/index.d.ts +1 -0
- package/dist/src/rpc/retryable.d.ts +23 -0
- package/dist/src/rtc/Dispatcher.d.ts +1 -1
- package/dist/src/rtc/IceTrickleBuffer.d.ts +0 -1
- package/dist/src/rtc/Publisher.d.ts +24 -25
- package/dist/src/rtc/Subscriber.d.ts +12 -11
- package/dist/src/rtc/helpers/rtcConfiguration.d.ts +2 -0
- package/dist/src/rtc/helpers/tracks.d.ts +3 -3
- package/dist/src/rtc/signal.d.ts +1 -1
- package/dist/src/store/CallState.d.ts +46 -2
- package/package.json +5 -5
- package/src/Call.ts +618 -563
- package/src/StreamSfuClient.ts +277 -246
- package/src/StreamVideoClient.ts +15 -16
- package/src/__tests__/Call.test.ts +145 -2
- package/src/__tests__/StreamVideoClient.api.test.ts +168 -0
- package/src/coordinator/connection/client.ts +25 -8
- package/src/coordinator/connection/connection.ts +2 -1
- package/src/coordinator/connection/types.ts +6 -0
- package/src/devices/BrowserPermission.ts +1 -1
- package/src/devices/CameraManager.ts +1 -1
- package/src/devices/InputMediaDeviceManager.ts +12 -3
- package/src/devices/MicrophoneManager.ts +3 -3
- package/src/devices/devices.ts +1 -1
- package/src/events/__tests__/mutes.test.ts +10 -13
- package/src/events/__tests__/participant.test.ts +75 -0
- package/src/events/callEventHandlers.ts +4 -7
- package/src/events/internal.ts +20 -3
- package/src/events/mutes.ts +5 -3
- package/src/events/participant.ts +48 -15
- package/src/gen/video/sfu/event/events.ts +451 -8
- package/src/gen/video/sfu/models/models.ts +211 -204
- package/src/helpers/ensureExhausted.ts +5 -0
- package/src/helpers/withResolvers.ts +43 -0
- package/src/logger.ts +3 -1
- package/src/rpc/__tests__/retryable.test.ts +72 -0
- package/src/rpc/createClient.ts +21 -0
- package/src/rpc/index.ts +1 -0
- package/src/rpc/retryable.ts +57 -0
- package/src/rtc/Dispatcher.ts +6 -2
- package/src/rtc/IceTrickleBuffer.ts +2 -2
- package/src/rtc/Publisher.ts +127 -163
- package/src/rtc/Subscriber.ts +94 -155
- package/src/rtc/__tests__/Publisher.test.ts +18 -95
- package/src/rtc/__tests__/Subscriber.test.ts +63 -99
- package/src/rtc/__tests__/videoLayers.test.ts +2 -2
- package/src/rtc/helpers/rtcConfiguration.ts +11 -0
- package/src/rtc/helpers/tracks.ts +27 -7
- package/src/rtc/signal.ts +3 -3
- package/src/rtc/videoLayers.ts +1 -10
- package/src/stats/SfuStatsReporter.ts +1 -0
- package/src/store/CallState.ts +109 -2
- package/src/store/__tests__/CallState.test.ts +48 -37
- package/dist/src/rtc/flows/join.d.ts +0 -20
- package/src/rtc/flows/join.ts +0 -65
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FinishedUnaryCall,
|
|
3
|
+
RpcError,
|
|
4
|
+
UnaryCall,
|
|
5
|
+
} from '@protobuf-ts/runtime-rpc';
|
|
6
|
+
import { TwirpErrorCode } from '@protobuf-ts/twirp-transport';
|
|
7
|
+
import { retryInterval, sleep } from '../coordinator/connection/utils';
|
|
8
|
+
import { Error as SfuError } from '../gen/video/sfu/models/models';
|
|
9
|
+
import { getLogger } from '../logger';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An internal interface which asserts that "retryable" SFU responses
|
|
13
|
+
* contain a field called "error".
|
|
14
|
+
* Ideally, this should be coming from the Protobuf definitions.
|
|
15
|
+
*/
|
|
16
|
+
export interface SfuResponseWithError {
|
|
17
|
+
/**
|
|
18
|
+
* An optional error field which should be present in all SFU responses.
|
|
19
|
+
*/
|
|
20
|
+
error?: SfuError;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a closure which wraps the given RPC call and retries invoking
|
|
25
|
+
* the RPC until it succeeds or the maximum number of retries is reached.
|
|
26
|
+
*
|
|
27
|
+
* For each retry, there would be a delay to avoid request bursts toward the SFU.
|
|
28
|
+
*
|
|
29
|
+
* @param rpc the closure around the RPC call to execute.
|
|
30
|
+
* @param signal the signal to abort the RPC call and retries loop.
|
|
31
|
+
*/
|
|
32
|
+
export const retryable = async <
|
|
33
|
+
I extends object,
|
|
34
|
+
O extends SfuResponseWithError,
|
|
35
|
+
>(
|
|
36
|
+
rpc: () => UnaryCall<I, O>,
|
|
37
|
+
signal?: AbortSignal,
|
|
38
|
+
): Promise<FinishedUnaryCall<I, O>> => {
|
|
39
|
+
let attempt = 0;
|
|
40
|
+
let result: FinishedUnaryCall<I, O> | undefined = undefined;
|
|
41
|
+
do {
|
|
42
|
+
if (attempt > 0) await sleep(retryInterval(attempt));
|
|
43
|
+
try {
|
|
44
|
+
result = await rpc();
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const isRequestCancelled =
|
|
47
|
+
err instanceof RpcError &&
|
|
48
|
+
err.code === TwirpErrorCode[TwirpErrorCode.cancelled];
|
|
49
|
+
const isAborted = signal?.aborted ?? false;
|
|
50
|
+
if (isRequestCancelled || isAborted) throw err;
|
|
51
|
+
getLogger(['sfu-client', 'rpc'])('debug', `rpc failed (${attempt})`, err);
|
|
52
|
+
attempt++;
|
|
53
|
+
}
|
|
54
|
+
} while (!result || result.response.error?.shouldRetry);
|
|
55
|
+
|
|
56
|
+
return result;
|
|
57
|
+
};
|
package/src/rtc/Dispatcher.ts
CHANGED
|
@@ -41,6 +41,7 @@ const sfuEventKinds: { [key in SfuEventKinds]: undefined } = {
|
|
|
41
41
|
pinsUpdated: undefined,
|
|
42
42
|
callEnded: undefined,
|
|
43
43
|
participantUpdated: undefined,
|
|
44
|
+
participantMigrationComplete: undefined,
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
export const isSfuEvent = (
|
|
@@ -55,11 +56,14 @@ export class Dispatcher {
|
|
|
55
56
|
Record<SfuEventKinds, CallEventListener<any>[] | undefined>
|
|
56
57
|
> = {};
|
|
57
58
|
|
|
58
|
-
dispatch = <K extends SfuEventKinds>(
|
|
59
|
+
dispatch = <K extends SfuEventKinds>(
|
|
60
|
+
message: DispatchableMessage<K>,
|
|
61
|
+
logTag: string,
|
|
62
|
+
) => {
|
|
59
63
|
const eventKind = message.eventPayload.oneofKind;
|
|
60
64
|
if (!eventKind) return;
|
|
61
65
|
const payload = message.eventPayload[eventKind];
|
|
62
|
-
this.logger('debug', `Dispatching ${eventKind}`, payload);
|
|
66
|
+
this.logger('debug', `Dispatching ${eventKind}, tag=${logTag}`, payload);
|
|
63
67
|
const listeners = this.subscribers[eventKind];
|
|
64
68
|
if (!listeners) return;
|
|
65
69
|
for (const fn of listeners) {
|
|
@@ -10,7 +10,6 @@ import { getLogger } from '../logger';
|
|
|
10
10
|
export class IceTrickleBuffer {
|
|
11
11
|
readonly subscriberCandidates = new ReplaySubject<ICETrickle>();
|
|
12
12
|
readonly publisherCandidates = new ReplaySubject<ICETrickle>();
|
|
13
|
-
private readonly logger = getLogger(['sfu-client']);
|
|
14
13
|
|
|
15
14
|
push = (iceTrickle: ICETrickle) => {
|
|
16
15
|
if (iceTrickle.peerType === PeerType.SUBSCRIBER) {
|
|
@@ -18,7 +17,8 @@ export class IceTrickleBuffer {
|
|
|
18
17
|
} else if (iceTrickle.peerType === PeerType.PUBLISHER_UNSPECIFIED) {
|
|
19
18
|
this.publisherCandidates.next(iceTrickle);
|
|
20
19
|
} else {
|
|
21
|
-
|
|
20
|
+
const logger = getLogger(['sfu-client']);
|
|
21
|
+
logger('warn', `ICETrickle, Unknown peer type`, iceTrickle);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|