@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,42 @@
|
|
|
1
|
+
import { Observable, Subject } from 'rxjs';
|
|
2
|
+
import { take } from 'rxjs/operators';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
6
|
+
* not emitted a value yet.
|
|
7
|
+
*
|
|
8
|
+
* @param observable$ the observable to get the value from.
|
|
9
|
+
*/
|
|
10
|
+
export const getCurrentValue = <T>(observable$: Observable<T>) => {
|
|
11
|
+
let value!: T;
|
|
12
|
+
observable$
|
|
13
|
+
.pipe(take(1))
|
|
14
|
+
.subscribe((v) => (value = v))
|
|
15
|
+
.unsubscribe();
|
|
16
|
+
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Updates the value of the provided Subject.
|
|
22
|
+
* An `update` can either be a new value or a function which takes
|
|
23
|
+
* the current value and returns a new value.
|
|
24
|
+
*
|
|
25
|
+
* @param subject the subject to update.
|
|
26
|
+
* @param update the update to apply to the subject.
|
|
27
|
+
* @return the updated value.
|
|
28
|
+
*/
|
|
29
|
+
export const setCurrentValue = <T>(
|
|
30
|
+
subject: Subject<T>,
|
|
31
|
+
update: T | ((currentValue: T) => T),
|
|
32
|
+
) => {
|
|
33
|
+
const currentValue = getCurrentValue(subject);
|
|
34
|
+
const next =
|
|
35
|
+
// TypeScript needs more context to infer the type of update
|
|
36
|
+
typeof update === 'function' && update instanceof Function
|
|
37
|
+
? update(currentValue)
|
|
38
|
+
: update;
|
|
39
|
+
|
|
40
|
+
subject.next(next);
|
|
41
|
+
return getCurrentValue(subject);
|
|
42
|
+
};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
|
|
2
|
+
import { combineLatestWith, distinctUntilChanged, map } from 'rxjs/operators';
|
|
3
|
+
import * as RxUtils from './rxUtils';
|
|
4
|
+
import { Call as CallController } from '../rtc/Call';
|
|
5
|
+
import { CallMetadata } from '../rtc/CallMetadata';
|
|
6
|
+
import { TrackType } from '../gen/video/sfu/models/models';
|
|
7
|
+
import type {
|
|
8
|
+
StreamVideoLocalParticipant,
|
|
9
|
+
StreamVideoParticipant,
|
|
10
|
+
StreamVideoParticipantPatch,
|
|
11
|
+
StreamVideoParticipantPatches,
|
|
12
|
+
} from '../rtc/types';
|
|
13
|
+
import type { CallStatsReport } from '../stats/types';
|
|
14
|
+
import type { User } from '../coordinator/connection/types';
|
|
15
|
+
import type { CallAccepted } from '../gen/coordinator';
|
|
16
|
+
|
|
17
|
+
export class StreamVideoWriteableStateStore {
|
|
18
|
+
/**
|
|
19
|
+
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
20
|
+
*/
|
|
21
|
+
connectedUserSubject = new BehaviorSubject<User | undefined>(undefined);
|
|
22
|
+
/**
|
|
23
|
+
* A store that keeps track of all created calls that have not been yet accepted, rejected nor cancelled.
|
|
24
|
+
*/
|
|
25
|
+
pendingCallsSubject = new BehaviorSubject<CallMetadata[]>([]);
|
|
26
|
+
/**
|
|
27
|
+
* A list of objects describing incoming calls.
|
|
28
|
+
*/
|
|
29
|
+
incomingCalls$: Observable<CallMetadata[]>;
|
|
30
|
+
/**
|
|
31
|
+
* A list of objects describing calls initiated by the current user (connectedUser).
|
|
32
|
+
*/
|
|
33
|
+
outgoingCalls$: Observable<CallMetadata[]>;
|
|
34
|
+
/**
|
|
35
|
+
* A store that keeps track of all the notifications describing accepted call.
|
|
36
|
+
*/
|
|
37
|
+
// todo: Currently not updating this Subject
|
|
38
|
+
// FIXME OL: what is the difference (from customer perspective) between "activeCall" and "acceptedCall"?
|
|
39
|
+
acceptedCallSubject = new BehaviorSubject<CallAccepted | undefined>(
|
|
40
|
+
undefined,
|
|
41
|
+
);
|
|
42
|
+
/**
|
|
43
|
+
* A store that keeps reference to a call controller instance.
|
|
44
|
+
*/
|
|
45
|
+
activeCallSubject = new BehaviorSubject<CallController | undefined>(
|
|
46
|
+
undefined,
|
|
47
|
+
);
|
|
48
|
+
/**
|
|
49
|
+
* All participants of the current call (including the logged-in user).
|
|
50
|
+
*/
|
|
51
|
+
participantsSubject = new ReplaySubject<
|
|
52
|
+
(StreamVideoParticipant | StreamVideoLocalParticipant)[]
|
|
53
|
+
>(1);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Remote participants of the current call (this includes every participant except the logged-in user).
|
|
57
|
+
*/
|
|
58
|
+
remoteParticipants$: Observable<StreamVideoParticipant[]>;
|
|
59
|
+
/**
|
|
60
|
+
* The local participant of the current call (the logged-in user).
|
|
61
|
+
*/
|
|
62
|
+
localParticipant$: Observable<StreamVideoLocalParticipant | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Pinned participants of the current call.
|
|
65
|
+
*/
|
|
66
|
+
pinnedParticipants$: Observable<StreamVideoParticipant[]>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The currently elected dominant speaker in the active call.
|
|
70
|
+
*/
|
|
71
|
+
dominantSpeaker$: Observable<StreamVideoParticipant | undefined>;
|
|
72
|
+
|
|
73
|
+
callStatsReportSubject = new BehaviorSubject<CallStatsReport | undefined>(
|
|
74
|
+
undefined,
|
|
75
|
+
);
|
|
76
|
+
callRecordingInProgressSubject = new ReplaySubject<boolean>(1);
|
|
77
|
+
hasOngoingScreenShare$: Observable<boolean>;
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
this.localParticipant$ = this.participantsSubject.pipe(
|
|
81
|
+
map((participants) => participants.find((p) => p.isLoggedInUser)),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
this.remoteParticipants$ = this.participantsSubject.pipe(
|
|
85
|
+
map((participants) => participants.filter((p) => !p.isLoggedInUser)),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
this.pinnedParticipants$ = this.participantsSubject.pipe(
|
|
89
|
+
map((participants) => participants.filter((p) => p.isPinned)),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
this.dominantSpeaker$ = this.participantsSubject.pipe(
|
|
93
|
+
map((participants) => participants.find((p) => p.isDominantSpeaker)),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
this.incomingCalls$ = this.pendingCallsSubject.pipe(
|
|
97
|
+
combineLatestWith(this.connectedUserSubject),
|
|
98
|
+
map(([pendingCalls, connectedUser]) =>
|
|
99
|
+
pendingCalls.filter(
|
|
100
|
+
(call) => call.call.created_by.id !== connectedUser?.id,
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
this.outgoingCalls$ = this.pendingCallsSubject.pipe(
|
|
106
|
+
combineLatestWith(this.connectedUserSubject),
|
|
107
|
+
map(([pendingCalls, connectedUser]) =>
|
|
108
|
+
pendingCalls.filter(
|
|
109
|
+
(call) => call.call.created_by.id === connectedUser?.id,
|
|
110
|
+
),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
this.activeCallSubject.subscribe((callController) => {
|
|
115
|
+
if (callController) {
|
|
116
|
+
this.setCurrentValue(
|
|
117
|
+
this.pendingCallsSubject,
|
|
118
|
+
this.getCurrentValue(this.pendingCallsSubject).filter(
|
|
119
|
+
(call) => call.call.cid !== callController.data.call.cid,
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
this.setCurrentValue(this.acceptedCallSubject, undefined);
|
|
123
|
+
} else {
|
|
124
|
+
this.setCurrentValue(this.callRecordingInProgressSubject, false);
|
|
125
|
+
this.setCurrentValue(this.participantsSubject, []);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
this.hasOngoingScreenShare$ = this.participantsSubject.pipe(
|
|
130
|
+
map((participants) => {
|
|
131
|
+
return participants.some((p) =>
|
|
132
|
+
p.publishedTracks.includes(TrackType.SCREEN_SHARE),
|
|
133
|
+
);
|
|
134
|
+
}),
|
|
135
|
+
distinctUntilChanged(),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
141
|
+
* not emitted a value yet.
|
|
142
|
+
*
|
|
143
|
+
* @param observable$ the observable to get the value from.
|
|
144
|
+
*/
|
|
145
|
+
getCurrentValue = RxUtils.getCurrentValue;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Updates the value of the provided Subject.
|
|
149
|
+
* An `update` can either be a new value or a function which takes
|
|
150
|
+
* the current value and returns a new value.
|
|
151
|
+
*
|
|
152
|
+
* @param subject the subject to update.
|
|
153
|
+
* @param update the update to apply to the subject.
|
|
154
|
+
* @return the updated value.
|
|
155
|
+
*/
|
|
156
|
+
setCurrentValue = RxUtils.setCurrentValue;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Will try to find the participant with the given sessionId in the active call.
|
|
160
|
+
*
|
|
161
|
+
* @param sessionId the sessionId of the participant to find.
|
|
162
|
+
* @returns the participant with the given sessionId or undefined if not found.
|
|
163
|
+
*/
|
|
164
|
+
findParticipantBySessionId = (
|
|
165
|
+
sessionId: string,
|
|
166
|
+
): StreamVideoParticipant | undefined => {
|
|
167
|
+
const participants = this.getCurrentValue(this.participantsSubject);
|
|
168
|
+
return participants.find((p) => p.sessionId === sessionId);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Updates a participant in the active call identified by the given `sessionId`.
|
|
173
|
+
* If the participant can't be found, this operation is no-op.
|
|
174
|
+
*
|
|
175
|
+
* @param sessionId the session ID of the participant to update.
|
|
176
|
+
* @param patch the patch to apply to the participant.
|
|
177
|
+
* @returns the updated participant or `undefined` if the participant couldn't be found.
|
|
178
|
+
*/
|
|
179
|
+
updateParticipant = (
|
|
180
|
+
sessionId: string,
|
|
181
|
+
patch:
|
|
182
|
+
| StreamVideoParticipantPatch
|
|
183
|
+
| ((p: StreamVideoParticipant) => StreamVideoParticipantPatch),
|
|
184
|
+
) => {
|
|
185
|
+
const participant = this.findParticipantBySessionId(sessionId);
|
|
186
|
+
if (!participant) {
|
|
187
|
+
console.warn(`Participant with sessionId ${sessionId} not found`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const thePatch = typeof patch === 'function' ? patch(participant) : patch;
|
|
192
|
+
const updatedParticipant:
|
|
193
|
+
| StreamVideoParticipant
|
|
194
|
+
| StreamVideoLocalParticipant = {
|
|
195
|
+
// FIXME OL: this is not a deep merge, we might want to revisit this
|
|
196
|
+
...participant,
|
|
197
|
+
...thePatch,
|
|
198
|
+
};
|
|
199
|
+
return this.setCurrentValue(this.participantsSubject, (participants) =>
|
|
200
|
+
participants.map((p) =>
|
|
201
|
+
p.sessionId === sessionId ? updatedParticipant : p,
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Updates all participants in the active call whose session ID is in the given `sessionIds`.
|
|
208
|
+
* If no patch are provided, this operation is no-op.
|
|
209
|
+
*
|
|
210
|
+
* @param patch the patch to apply to the participants.
|
|
211
|
+
* @returns all participants, with all patch applied.
|
|
212
|
+
*/
|
|
213
|
+
updateParticipants = (patch: StreamVideoParticipantPatches) => {
|
|
214
|
+
if (Object.keys(patch).length === 0) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
return this.setCurrentValue(this.participantsSubject, (participants) =>
|
|
218
|
+
participants.map((p) => {
|
|
219
|
+
const thePatch = patch[p.sessionId];
|
|
220
|
+
if (thePatch) {
|
|
221
|
+
return {
|
|
222
|
+
...p,
|
|
223
|
+
...thePatch,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return p;
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A reactive store that exposes state variables in a reactive manner - you can subscribe to changes of the different state variables. This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
234
|
+
*
|
|
235
|
+
*/
|
|
236
|
+
export class StreamVideoReadOnlyStateStore {
|
|
237
|
+
/**
|
|
238
|
+
* Data describing a user successfully connected over WS to coordinator server.
|
|
239
|
+
*/
|
|
240
|
+
connectedUser$: Observable<User | undefined>;
|
|
241
|
+
/**
|
|
242
|
+
* A list of objects describing all created calls that have not been yet accepted, rejected nor cancelled.
|
|
243
|
+
*/
|
|
244
|
+
pendingCalls$: Observable<CallMetadata[]>;
|
|
245
|
+
/**
|
|
246
|
+
* A list of objects describing calls initiated by the current user (connectedUser).
|
|
247
|
+
*/
|
|
248
|
+
outgoingCalls$: Observable<CallMetadata[]>;
|
|
249
|
+
/**
|
|
250
|
+
* A list of objects describing incoming calls.
|
|
251
|
+
*/
|
|
252
|
+
incomingCalls$: Observable<CallMetadata[]>;
|
|
253
|
+
/**
|
|
254
|
+
* The call data describing an incoming call accepted by a participant.
|
|
255
|
+
* Serves as a flag decide, whether an incoming call should be joined.
|
|
256
|
+
*/
|
|
257
|
+
acceptedCall$: Observable<CallAccepted | undefined>;
|
|
258
|
+
/**
|
|
259
|
+
* The call controller instance representing the call the user attends.
|
|
260
|
+
* The controller instance exposes call metadata as well.
|
|
261
|
+
* `activeCall$` will be set after calling [`join` on a `Call` instance](./Call.md/#join) and cleared after calling [`leave`](./Call.md/#leave).
|
|
262
|
+
*/
|
|
263
|
+
activeCall$: Observable<CallController | undefined>;
|
|
264
|
+
/**
|
|
265
|
+
* The currently elected dominant speaker in the active call.
|
|
266
|
+
*/
|
|
267
|
+
dominantSpeaker$: Observable<StreamVideoParticipant | undefined>;
|
|
268
|
+
/**
|
|
269
|
+
* All participants of the current call (this includes the current user and other participants as well).
|
|
270
|
+
*/
|
|
271
|
+
participants$: Observable<
|
|
272
|
+
(StreamVideoParticipant | StreamVideoLocalParticipant)[]
|
|
273
|
+
>;
|
|
274
|
+
/**
|
|
275
|
+
* The local participant of the current call (the logged-in user).
|
|
276
|
+
*/
|
|
277
|
+
localParticipant$: Observable<StreamVideoLocalParticipant | undefined>;
|
|
278
|
+
/**
|
|
279
|
+
* Remote participants of the current call (this includes every participant except the logged-in user).
|
|
280
|
+
*/
|
|
281
|
+
remoteParticipants$: Observable<StreamVideoParticipant[]>;
|
|
282
|
+
/**
|
|
283
|
+
* Pinned participants of the current call.
|
|
284
|
+
*/
|
|
285
|
+
pinnedParticipants$: Observable<StreamVideoParticipant[]>;
|
|
286
|
+
/**
|
|
287
|
+
* Emits true whenever there is an active screen sharing session within
|
|
288
|
+
* the current call. Useful for displaying a "screen sharing" indicator and
|
|
289
|
+
* switching the layout to a screen sharing layout.
|
|
290
|
+
*
|
|
291
|
+
* The actual screen sharing track isn't exposed here, but can be retrieved
|
|
292
|
+
* from the list of call participants. We also don't want to be limiting
|
|
293
|
+
* to the number of share screen tracks are displayed in a call.
|
|
294
|
+
*/
|
|
295
|
+
hasOngoingScreenShare$: Observable<boolean>;
|
|
296
|
+
/**
|
|
297
|
+
* The latest stats report of the current call.
|
|
298
|
+
* When stats gathering is enabled, this observable will emit a new value
|
|
299
|
+
* at a regular (configurable) interval.
|
|
300
|
+
*
|
|
301
|
+
* Consumers of this observable can implement their own batching logic
|
|
302
|
+
* in case they want to show historical stats data.
|
|
303
|
+
*/
|
|
304
|
+
callStatsReport$: Observable<CallStatsReport | undefined>;
|
|
305
|
+
/**
|
|
306
|
+
* Emits a boolean indicating whether a call recording is currently in progress.
|
|
307
|
+
*/
|
|
308
|
+
callRecordingInProgress$: Observable<boolean>;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* This method allows you the get the current value of a state variable.
|
|
312
|
+
*
|
|
313
|
+
* @param observable the observable to get the current value of.
|
|
314
|
+
* @returns the current value of the observable.
|
|
315
|
+
*/
|
|
316
|
+
getCurrentValue: <T>(observable: Observable<T>) => T;
|
|
317
|
+
|
|
318
|
+
constructor(store: StreamVideoWriteableStateStore) {
|
|
319
|
+
// convert and expose subjects as observables
|
|
320
|
+
this.connectedUser$ = store.connectedUserSubject.asObservable();
|
|
321
|
+
this.pendingCalls$ = store.pendingCallsSubject.asObservable();
|
|
322
|
+
this.acceptedCall$ = store.acceptedCallSubject.asObservable();
|
|
323
|
+
this.activeCall$ = store.activeCallSubject.asObservable();
|
|
324
|
+
this.participants$ = store.participantsSubject.asObservable();
|
|
325
|
+
this.callStatsReport$ = store.callStatsReportSubject.asObservable();
|
|
326
|
+
this.callRecordingInProgress$ =
|
|
327
|
+
store.callRecordingInProgressSubject.asObservable();
|
|
328
|
+
|
|
329
|
+
// re-expose observables
|
|
330
|
+
this.localParticipant$ = store.localParticipant$;
|
|
331
|
+
this.remoteParticipants$ = store.remoteParticipants$;
|
|
332
|
+
this.pinnedParticipants$ = store.pinnedParticipants$;
|
|
333
|
+
this.dominantSpeaker$ = store.dominantSpeaker$;
|
|
334
|
+
this.hasOngoingScreenShare$ = store.hasOngoingScreenShare$;
|
|
335
|
+
this.incomingCalls$ = store.incomingCalls$;
|
|
336
|
+
this.outgoingCalls$ = store.outgoingCalls$;
|
|
337
|
+
|
|
338
|
+
// re-expose methods
|
|
339
|
+
this.getCurrentValue = store.getCurrentValue;
|
|
340
|
+
}
|
|
341
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./dist",
|
|
4
|
+
"module": "ES2015",
|
|
5
|
+
"target": "ES2015",
|
|
6
|
+
"lib": [
|
|
7
|
+
"esnext",
|
|
8
|
+
"dom"
|
|
9
|
+
],
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"strictNullChecks": true,
|
|
19
|
+
"sourceMap": true
|
|
20
|
+
},
|
|
21
|
+
"include": [
|
|
22
|
+
"./src",
|
|
23
|
+
"index.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/typedoc.json
ADDED