@stream-io/video-client 0.0.1-alpha.10
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/LICENSE +219 -0
- package/README.md +14 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +296 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/Batcher.ts.html +214 -0
- package/coverage/lcov-report/src/CallDropScheduler.ts.html +661 -0
- package/coverage/lcov-report/src/StreamSfuClient.ts.html +640 -0
- package/coverage/lcov-report/src/StreamVideoClient.ts.html +1594 -0
- package/coverage/lcov-report/src/config/defaultConfigs.ts.html +130 -0
- package/coverage/lcov-report/src/config/index.html +116 -0
- package/coverage/lcov-report/src/coordinator/StreamCoordinatorClient.ts.html +430 -0
- package/coverage/lcov-report/src/coordinator/connection/base64.ts.html +325 -0
- package/coverage/lcov-report/src/coordinator/connection/client.ts.html +2527 -0
- package/coverage/lcov-report/src/coordinator/connection/connection.ts.html +2335 -0
- package/coverage/lcov-report/src/coordinator/connection/connection_fallback.ts.html +802 -0
- package/coverage/lcov-report/src/coordinator/connection/errors.ts.html +295 -0
- package/coverage/lcov-report/src/coordinator/connection/index.html +251 -0
- package/coverage/lcov-report/src/coordinator/connection/insights.ts.html +349 -0
- package/coverage/lcov-report/src/coordinator/connection/signing.ts.html +397 -0
- package/coverage/lcov-report/src/coordinator/connection/token_manager.ts.html +565 -0
- package/coverage/lcov-report/src/coordinator/connection/types.ts.html +418 -0
- package/coverage/lcov-report/src/coordinator/connection/utils.ts.html +529 -0
- package/coverage/lcov-report/src/coordinator/index.html +116 -0
- package/coverage/lcov-report/src/events/call.ts.html +583 -0
- package/coverage/lcov-report/src/events/index.html +161 -0
- package/coverage/lcov-report/src/events/internal.ts.html +226 -0
- package/coverage/lcov-report/src/events/participant.ts.html +376 -0
- package/coverage/lcov-report/src/events/speaker.ts.html +271 -0
- package/coverage/lcov-report/src/gen/google/protobuf/index.html +131 -0
- package/coverage/lcov-report/src/gen/google/protobuf/struct.ts.html +1528 -0
- package/coverage/lcov-report/src/gen/google/protobuf/timestamp.ts.html +958 -0
- package/coverage/lcov-report/src/gen/video/sfu/event/events.ts.html +5971 -0
- package/coverage/lcov-report/src/gen/video/sfu/event/index.html +116 -0
- package/coverage/lcov-report/src/gen/video/sfu/models/index.html +116 -0
- package/coverage/lcov-report/src/gen/video/sfu/models/models.ts.html +3271 -0
- package/coverage/lcov-report/src/index.html +161 -0
- package/coverage/lcov-report/src/rpc/index.html +131 -0
- package/coverage/lcov-report/src/rpc/index.ts.html +91 -0
- package/coverage/lcov-report/src/rpc/latency.ts.html +214 -0
- package/coverage/lcov-report/src/rtc/Call.ts.html +1840 -0
- package/coverage/lcov-report/src/rtc/CallMetadata.ts.html +157 -0
- package/coverage/lcov-report/src/rtc/Dispatcher.ts.html +223 -0
- package/coverage/lcov-report/src/rtc/IceTrickleBuffer.ts.html +148 -0
- package/coverage/lcov-report/src/rtc/callEventHandlers.ts.html +196 -0
- package/coverage/lcov-report/src/rtc/codecs.ts.html +268 -0
- package/coverage/lcov-report/src/rtc/helpers/iceCandidate.ts.html +133 -0
- package/coverage/lcov-report/src/rtc/helpers/index.html +131 -0
- package/coverage/lcov-report/src/rtc/helpers/tracks.ts.html +139 -0
- package/coverage/lcov-report/src/rtc/index.html +251 -0
- package/coverage/lcov-report/src/rtc/publisher.ts.html +1000 -0
- package/coverage/lcov-report/src/rtc/signal.ts.html +187 -0
- package/coverage/lcov-report/src/rtc/subscriber.ts.html +340 -0
- package/coverage/lcov-report/src/rtc/videoLayers.ts.html +394 -0
- package/coverage/lcov-report/src/stats/index.html +116 -0
- package/coverage/lcov-report/src/stats/state-store-stats-reporter.ts.html +1177 -0
- package/coverage/lcov-report/src/store/index.html +146 -0
- package/coverage/lcov-report/src/store/index.ts.html +91 -0
- package/coverage/lcov-report/src/store/rxUtils.ts.html +211 -0
- package/coverage/lcov-report/src/store/stateStore.ts.html +1108 -0
- package/coverage/lcov.info +11463 -0
- package/coverage/tmp/coverage-2131-1675959950516-2.json +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +8636 -0
- package/dist/index.js.map +1 -0
- package/dist/src/Batcher.d.ts +12 -0
- package/dist/src/CallDropScheduler.d.ts +44 -0
- package/dist/src/StreamSfuClient.d.ts +25 -0
- package/dist/src/StreamVideoClient.d.ts +145 -0
- package/dist/src/__tests__/StreamVideoClient.test.d.ts +1 -0
- package/dist/src/config/defaultConfigs.d.ts +2 -0
- package/dist/src/config/types.d.ts +29 -0
- package/dist/src/coordinator/StreamCoordinatorClient.d.ts +19 -0
- package/dist/src/coordinator/connection/base64.d.ts +2 -0
- package/dist/src/coordinator/connection/client.d.ts +174 -0
- package/dist/src/coordinator/connection/connection.d.ts +139 -0
- package/dist/src/coordinator/connection/connection_fallback.d.ts +38 -0
- package/dist/src/coordinator/connection/errors.d.ts +16 -0
- package/dist/src/coordinator/connection/events.d.ts +10 -0
- package/dist/src/coordinator/connection/insights.d.ts +58 -0
- package/dist/src/coordinator/connection/signing.d.ts +30 -0
- package/dist/src/coordinator/connection/token_manager.d.ts +39 -0
- package/dist/src/coordinator/connection/types.d.ts +87 -0
- package/dist/src/coordinator/connection/utils.d.ts +25 -0
- package/dist/src/devices.d.ts +79 -0
- package/dist/src/events/call.d.ts +26 -0
- package/dist/src/events/internal.d.ts +8 -0
- package/dist/src/events/participant.d.ts +21 -0
- package/dist/src/events/speaker.d.ts +10 -0
- package/dist/src/gen/coordinator/index.d.ts +1973 -0
- package/dist/src/gen/google/protobuf/descriptor.d.ts +1650 -0
- package/dist/src/gen/google/protobuf/duration.d.ts +113 -0
- package/dist/src/gen/google/protobuf/struct.d.ts +184 -0
- package/dist/src/gen/google/protobuf/timestamp.d.ts +158 -0
- package/dist/src/gen/video/coordinator/broadcast_v1/broadcast.d.ts +66 -0
- package/dist/src/gen/video/coordinator/call_v1/call.d.ts +254 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.d.ts +351 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.d.ts +1488 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/envelopes.d.ts +143 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/websocket.d.ts +292 -0
- package/dist/src/gen/video/coordinator/edge_v1/edge.d.ts +183 -0
- package/dist/src/gen/video/coordinator/event_v1/event.d.ts +411 -0
- package/dist/src/gen/video/coordinator/geofence_v1/geofence.d.ts +63 -0
- package/dist/src/gen/video/coordinator/member_v1/member.d.ts +59 -0
- package/dist/src/gen/video/coordinator/participant_v1/participant.d.ts +103 -0
- package/dist/src/gen/video/coordinator/push_v1/push.d.ts +240 -0
- package/dist/src/gen/video/coordinator/stat_v1/stat.d.ts +308 -0
- package/dist/src/gen/video/coordinator/user_v1/user.d.ts +112 -0
- package/dist/src/gen/video/coordinator/utils_v1/utils.d.ts +47 -0
- package/dist/src/gen/video/sfu/event/events.d.ts +736 -0
- package/dist/src/gen/video/sfu/models/models.d.ts +460 -0
- package/dist/src/gen/video/sfu/signal_rpc/signal.client.d.ts +89 -0
- package/dist/src/gen/video/sfu/signal_rpc/signal.d.ts +320 -0
- package/dist/src/helpers/browsers.d.ts +8 -0
- package/dist/src/helpers/sound-detector.d.ts +34 -0
- package/dist/src/rpc/createClient.d.ts +10 -0
- package/dist/src/rpc/index.d.ts +2 -0
- package/dist/src/rpc/latency.d.ts +9 -0
- package/dist/src/rtc/Call.d.ts +180 -0
- package/dist/src/rtc/CallMetadata.d.ts +9 -0
- package/dist/src/rtc/Dispatcher.d.ts +9 -0
- package/dist/src/rtc/IceTrickleBuffer.d.ts +11 -0
- package/dist/src/rtc/callEventHandlers.d.ts +5 -0
- package/dist/src/rtc/codecs.d.ts +2 -0
- package/dist/src/rtc/helpers/iceCandidate.d.ts +2 -0
- package/dist/src/rtc/helpers/tracks.d.ts +3 -0
- package/dist/src/rtc/publisher.d.ts +53 -0
- package/dist/src/rtc/signal.d.ts +5 -0
- package/dist/src/rtc/subscriber.d.ts +7 -0
- package/dist/src/rtc/types.d.ts +84 -0
- package/dist/src/rtc/videoLayers.d.ts +17 -0
- package/dist/src/stats/coordinator-stats-reporter.d.ts +10 -0
- package/dist/src/stats/state-store-stats-reporter.d.ts +57 -0
- package/dist/src/stats/types.d.ts +42 -0
- package/dist/src/store/index.d.ts +2 -0
- package/dist/src/store/rxUtils.d.ts +18 -0
- package/dist/src/store/stateStore.d.ts +182 -0
- package/generate-openapi.sh +32 -0
- package/index.ts +31 -0
- package/openapitools.json +7 -0
- package/package.json +54 -0
- package/rollup.config.mjs +48 -0
- package/src/Batcher.ts +43 -0
- package/src/CallDropScheduler.ts +192 -0
- package/src/StreamSfuClient.ts +185 -0
- package/src/StreamVideoClient.ts +503 -0
- package/src/__tests__/StreamVideoClient.test.ts +83 -0
- package/src/config/defaultConfigs.ts +15 -0
- package/src/config/types.ts +30 -0
- package/src/coordinator/StreamCoordinatorClient.ts +115 -0
- package/src/coordinator/connection/base64.ts +80 -0
- package/src/coordinator/connection/client.ts +814 -0
- package/src/coordinator/connection/connection.ts +750 -0
- package/src/coordinator/connection/connection_fallback.ts +239 -0
- package/src/coordinator/connection/errors.ts +70 -0
- package/src/coordinator/connection/events.ts +13 -0
- package/src/coordinator/connection/insights.ts +88 -0
- package/src/coordinator/connection/signing.ts +104 -0
- package/src/coordinator/connection/token_manager.ts +160 -0
- package/src/coordinator/connection/types.ts +111 -0
- package/src/coordinator/connection/utils.ts +148 -0
- package/src/devices.ts +266 -0
- package/src/events/call.ts +166 -0
- package/src/events/internal.ts +47 -0
- package/src/events/participant.ts +97 -0
- package/src/events/speaker.ts +62 -0
- package/src/gen/coordinator/index.ts +1956 -0
- package/src/gen/google/protobuf/descriptor.ts +3466 -0
- package/src/gen/google/protobuf/duration.ts +232 -0
- package/src/gen/google/protobuf/struct.ts +481 -0
- package/src/gen/google/protobuf/timestamp.ts +291 -0
- package/src/gen/video/coordinator/broadcast_v1/broadcast.ts +154 -0
- package/src/gen/video/coordinator/call_v1/call.ts +651 -0
- package/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.ts +463 -0
- package/src/gen/video/coordinator/client_v1_rpc/client_rpc.ts +3819 -0
- package/src/gen/video/coordinator/client_v1_rpc/envelopes.ts +424 -0
- package/src/gen/video/coordinator/client_v1_rpc/websocket.ts +719 -0
- package/src/gen/video/coordinator/edge_v1/edge.ts +532 -0
- package/src/gen/video/coordinator/event_v1/event.ts +1171 -0
- package/src/gen/video/coordinator/geofence_v1/geofence.ts +128 -0
- package/src/gen/video/coordinator/member_v1/member.ts +138 -0
- package/src/gen/video/coordinator/participant_v1/participant.ts +261 -0
- package/src/gen/video/coordinator/push_v1/push.ts +651 -0
- package/src/gen/video/coordinator/stat_v1/stat.ts +656 -0
- package/src/gen/video/coordinator/user_v1/user.ts +277 -0
- package/src/gen/video/coordinator/utils_v1/utils.ts +98 -0
- package/src/gen/video/sfu/event/events.ts +1962 -0
- package/src/gen/video/sfu/models/models.ts +1062 -0
- package/src/gen/video/sfu/signal_rpc/signal.client.ts +108 -0
- package/src/gen/video/sfu/signal_rpc/signal.ts +906 -0
- package/src/helpers/browsers.ts +13 -0
- package/src/helpers/sound-detector.ts +85 -0
- package/src/rpc/createClient.ts +50 -0
- package/src/rpc/index.ts +2 -0
- package/src/rpc/latency.ts +43 -0
- package/src/rtc/Call.ts +585 -0
- package/src/rtc/CallMetadata.ts +24 -0
- package/src/rtc/Dispatcher.ts +46 -0
- package/src/rtc/IceTrickleBuffer.ts +21 -0
- package/src/rtc/callEventHandlers.ts +37 -0
- package/src/rtc/codecs.ts +61 -0
- package/src/rtc/helpers/iceCandidate.ts +16 -0
- package/src/rtc/helpers/tracks.ts +18 -0
- package/src/rtc/publisher.ts +305 -0
- package/src/rtc/signal.ts +34 -0
- package/src/rtc/subscriber.ts +85 -0
- package/src/rtc/types.ts +105 -0
- package/src/rtc/videoLayers.ts +103 -0
- package/src/stats/coordinator-stats-reporter.ts +167 -0
- package/src/stats/state-store-stats-reporter.ts +364 -0
- package/src/stats/types.ts +46 -0
- package/src/store/index.ts +2 -0
- package/src/store/rxUtils.ts +42 -0
- package/src/store/stateStore.ts +341 -0
- package/tsconfig.json +25 -0
- package/typedoc.json +11 -0
- package/vite.config.ts +11 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Dispatcher } from '../rtc/Dispatcher';
|
|
2
|
+
import { Call } from '../rtc/Call';
|
|
3
|
+
import { StreamVideoWriteableStateStore } from '../store';
|
|
4
|
+
import { StreamVideoParticipantPatches } from '../rtc/types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An event responder which handles the `changePublishQuality` event.
|
|
8
|
+
*/
|
|
9
|
+
export const watchChangePublishQuality = (
|
|
10
|
+
dispatcher: Dispatcher,
|
|
11
|
+
call: Call,
|
|
12
|
+
) => {
|
|
13
|
+
return dispatcher.on('changePublishQuality', (e) => {
|
|
14
|
+
if (e.eventPayload.oneofKind !== 'changePublishQuality') return;
|
|
15
|
+
const { videoSenders } = e.eventPayload.changePublishQuality;
|
|
16
|
+
videoSenders.forEach((videoSender) => {
|
|
17
|
+
const { layers } = videoSender;
|
|
18
|
+
call.updatePublishQuality(
|
|
19
|
+
layers.filter((l) => l.active).map((l) => l.name),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const watchConnectionQualityChanged = (
|
|
26
|
+
dispatcher: Dispatcher,
|
|
27
|
+
store: StreamVideoWriteableStateStore,
|
|
28
|
+
) => {
|
|
29
|
+
return dispatcher.on('connectionQualityChanged', (e) => {
|
|
30
|
+
if (e.eventPayload.oneofKind !== 'connectionQualityChanged') return;
|
|
31
|
+
const { connectionQualityChanged } = e.eventPayload;
|
|
32
|
+
const { connectionQualityUpdates } = connectionQualityChanged;
|
|
33
|
+
if (!connectionQualityUpdates) return;
|
|
34
|
+
store.updateParticipants(
|
|
35
|
+
connectionQualityUpdates.reduce<StreamVideoParticipantPatches>(
|
|
36
|
+
(patches, update) => {
|
|
37
|
+
const { sessionId, connectionQuality } = update;
|
|
38
|
+
patches[sessionId] = {
|
|
39
|
+
connectionQuality,
|
|
40
|
+
};
|
|
41
|
+
return patches;
|
|
42
|
+
},
|
|
43
|
+
{},
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Batcher } from '../Batcher';
|
|
2
|
+
import { Dispatcher } from '../rtc/Dispatcher';
|
|
3
|
+
import { StreamVideoWriteableStateStore } from '../store';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An event responder which handles the `participantJoined` event.
|
|
7
|
+
*/
|
|
8
|
+
export const watchParticipantJoined = (
|
|
9
|
+
dispatcher: Dispatcher,
|
|
10
|
+
store: StreamVideoWriteableStateStore,
|
|
11
|
+
userBatcher: Batcher<string>,
|
|
12
|
+
) => {
|
|
13
|
+
return dispatcher.on('participantJoined', (e) => {
|
|
14
|
+
if (e.eventPayload.oneofKind !== 'participantJoined') return;
|
|
15
|
+
const { participant } = e.eventPayload.participantJoined;
|
|
16
|
+
if (!participant) return;
|
|
17
|
+
|
|
18
|
+
const activeCall = store.getCurrentValue(store.activeCallSubject);
|
|
19
|
+
|
|
20
|
+
// FIXME: this part is being repeated in call.join event as well
|
|
21
|
+
const { users } = activeCall!.data;
|
|
22
|
+
const userData = users[participant.userId];
|
|
23
|
+
if (!userData) userBatcher.addToBatch(participant.userId);
|
|
24
|
+
|
|
25
|
+
store.setCurrentValue(store.participantsSubject, (currentParticipants) => [
|
|
26
|
+
...currentParticipants,
|
|
27
|
+
{
|
|
28
|
+
...participant,
|
|
29
|
+
user: userData,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An event responder which handles the `participantLeft` event.
|
|
37
|
+
*/
|
|
38
|
+
export const watchParticipantLeft = (
|
|
39
|
+
dispatcher: Dispatcher,
|
|
40
|
+
store: StreamVideoWriteableStateStore,
|
|
41
|
+
) => {
|
|
42
|
+
return dispatcher.on('participantLeft', (e) => {
|
|
43
|
+
if (e.eventPayload.oneofKind !== 'participantLeft') return;
|
|
44
|
+
const { participant, callCid } = e.eventPayload.participantLeft;
|
|
45
|
+
if (!participant) return;
|
|
46
|
+
|
|
47
|
+
const activeCall = store.getCurrentValue(store.activeCallSubject);
|
|
48
|
+
if (callCid !== activeCall?.data.call.cid) {
|
|
49
|
+
console.warn('Received participantLeft notification for a unknown call');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
store.setCurrentValue(store.participantsSubject, (participants) =>
|
|
54
|
+
participants.filter((p) => p.sessionId !== participant.sessionId),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An event responder which handles the `trackPublished` event.
|
|
61
|
+
* The SFU will send this event when a participant publishes a track.
|
|
62
|
+
*/
|
|
63
|
+
export const watchTrackPublished = (
|
|
64
|
+
dispatcher: Dispatcher,
|
|
65
|
+
store: StreamVideoWriteableStateStore,
|
|
66
|
+
) => {
|
|
67
|
+
return dispatcher.on('trackPublished', (e) => {
|
|
68
|
+
if (e.eventPayload.oneofKind !== 'trackPublished') return;
|
|
69
|
+
const {
|
|
70
|
+
trackPublished: { type, sessionId },
|
|
71
|
+
} = e.eventPayload;
|
|
72
|
+
store.updateParticipant(sessionId, (p) => ({
|
|
73
|
+
publishedTracks: [...p.publishedTracks, type].filter(unique),
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* An event responder which handles the `trackUnpublished` event.
|
|
80
|
+
* The SFU will send this event when a participant unpublishes a track.
|
|
81
|
+
*/
|
|
82
|
+
export const watchTrackUnpublished = (
|
|
83
|
+
dispatcher: Dispatcher,
|
|
84
|
+
store: StreamVideoWriteableStateStore,
|
|
85
|
+
) => {
|
|
86
|
+
return dispatcher.on('trackUnpublished', (e) => {
|
|
87
|
+
if (e.eventPayload.oneofKind !== 'trackUnpublished') return;
|
|
88
|
+
const {
|
|
89
|
+
trackUnpublished: { type, sessionId },
|
|
90
|
+
} = e.eventPayload;
|
|
91
|
+
store.updateParticipant(sessionId, (p) => ({
|
|
92
|
+
publishedTracks: p.publishedTracks.filter((t) => t !== type),
|
|
93
|
+
}));
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const unique = <T>(v: T, i: number, arr: T[]) => arr.indexOf(v) === i;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Dispatcher } from '../rtc/Dispatcher';
|
|
2
|
+
import { StreamVideoWriteableStateStore } from '../store';
|
|
3
|
+
import { StreamVideoParticipantPatches } from '../rtc/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Watches for `dominantSpeakerChanged` events.
|
|
7
|
+
*/
|
|
8
|
+
export const watchDominantSpeakerChanged = (
|
|
9
|
+
dispatcher: Dispatcher,
|
|
10
|
+
store: StreamVideoWriteableStateStore,
|
|
11
|
+
) => {
|
|
12
|
+
return dispatcher.on('dominantSpeakerChanged', (e) => {
|
|
13
|
+
if (e.eventPayload.oneofKind !== 'dominantSpeakerChanged') return;
|
|
14
|
+
const {
|
|
15
|
+
dominantSpeakerChanged: { sessionId },
|
|
16
|
+
} = e.eventPayload;
|
|
17
|
+
const dominantSpeaker = store.getCurrentValue(store.dominantSpeaker$);
|
|
18
|
+
if (sessionId === dominantSpeaker?.sessionId) return;
|
|
19
|
+
store.setCurrentValue(store.participantsSubject, (participants) =>
|
|
20
|
+
participants.map((participant) => {
|
|
21
|
+
// mark the new dominant speaker
|
|
22
|
+
if (participant.sessionId === sessionId) {
|
|
23
|
+
return {
|
|
24
|
+
...participant,
|
|
25
|
+
isDominantSpeaker: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// unmark the old dominant speaker
|
|
29
|
+
if (participant.isDominantSpeaker) {
|
|
30
|
+
return {
|
|
31
|
+
...participant,
|
|
32
|
+
isDominantSpeaker: false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return participant; // no change
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Watches for `audioLevelChanged` events.
|
|
43
|
+
*/
|
|
44
|
+
export const watchAudioLevelChanged = (
|
|
45
|
+
dispatcher: Dispatcher,
|
|
46
|
+
store: StreamVideoWriteableStateStore,
|
|
47
|
+
) => {
|
|
48
|
+
return dispatcher.on('audioLevelChanged', (e) => {
|
|
49
|
+
if (e.eventPayload.oneofKind !== 'audioLevelChanged') return;
|
|
50
|
+
|
|
51
|
+
const { audioLevels } = e.eventPayload.audioLevelChanged;
|
|
52
|
+
store.updateParticipants(
|
|
53
|
+
audioLevels.reduce<StreamVideoParticipantPatches>((patches, current) => {
|
|
54
|
+
patches[current.sessionId] = {
|
|
55
|
+
audioLevel: current.level,
|
|
56
|
+
isSpeaking: current.isSpeaking,
|
|
57
|
+
};
|
|
58
|
+
return patches;
|
|
59
|
+
}, {}),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
};
|