@stream-io/video-client 1.61.0 → 2.0.0-beta.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +10 -10
  2. package/dist/index.browser.es.js +358 -611
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +357 -611
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.es.js +358 -611
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/src/Call.d.ts +3 -3
  9. package/dist/src/StreamVideoClient.d.ts +15 -21
  10. package/dist/src/store/CallState.d.ts +108 -266
  11. package/dist/src/store/ClientState.d.ts +62 -0
  12. package/dist/src/store/index.d.ts +1 -1
  13. package/dist/src/store/subjects.d.ts +15 -0
  14. package/dist/src/store/types.d.ts +22 -0
  15. package/dist/src/types.d.ts +3 -3
  16. package/package.json +2 -2
  17. package/src/Call.ts +14 -18
  18. package/src/StreamVideoClient.ts +40 -47
  19. package/src/__tests__/Call.autodrop.test.ts +4 -4
  20. package/src/__tests__/Call.getRingState.test.ts +2 -2
  21. package/src/__tests__/Call.lifecycle.test.ts +8 -8
  22. package/src/__tests__/Call.publishing.test.ts +2 -2
  23. package/src/__tests__/Call.ringSettled.test.ts +4 -4
  24. package/src/__tests__/Call.ringingLifecycle.test.ts +2 -2
  25. package/src/__tests__/StreamVideoClient.disconnect.test.ts +62 -0
  26. package/src/devices/__tests__/CameraManager.test.ts +2 -2
  27. package/src/devices/__tests__/DeviceManager.test.ts +2 -2
  28. package/src/devices/__tests__/DeviceManagerFilters.test.ts +2 -2
  29. package/src/devices/__tests__/MicrophoneManager.test.ts +2 -2
  30. package/src/devices/__tests__/MicrophoneManagerRN.test.ts +2 -2
  31. package/src/devices/__tests__/ScreenShareManager.test.ts +3 -3
  32. package/src/devices/__tests__/SpeakerManager.test.ts +4 -4
  33. package/src/events/__tests__/call.test.ts +3 -3
  34. package/src/helpers/__tests__/AudioBindingsWatchdog.test.ts +2 -2
  35. package/src/helpers/__tests__/DynascaleManager.test.ts +2 -2
  36. package/src/helpers/__tests__/ViewportTracker.test.ts +2 -2
  37. package/src/ringing/__tests__/RingStatePoller.test.ts +7 -7
  38. package/src/ringing/__tests__/RingTimeout.test.ts +4 -4
  39. package/src/ringing/__tests__/reconcileRingState.test.ts +3 -3
  40. package/src/rtc/__tests__/Call.reconnect.test.ts +5 -5
  41. package/src/store/CallState.ts +281 -551
  42. package/src/store/ClientState.ts +101 -0
  43. package/src/store/__tests__/CallState.test.ts +1 -1
  44. package/src/store/__tests__/ClientState.test.ts +35 -0
  45. package/src/store/__tests__/rxUtils.test.ts +67 -1
  46. package/src/store/index.ts +1 -1
  47. package/src/store/rxUtils.ts +8 -4
  48. package/src/store/subjects.ts +30 -0
  49. package/src/store/types.ts +45 -0
  50. package/src/types.ts +3 -3
  51. package/dist/src/store/stateStore.d.ts +0 -84
  52. package/src/store/stateStore.ts +0 -156
@@ -7,7 +7,7 @@ import { TwirpFetchTransport, TwirpErrorCode } from '@protobuf-ts/twirp-transpor
7
7
  import * as scopedLogger from '@stream-io/logger';
8
8
  export { LogLevelEnum } from '@stream-io/logger';
9
9
  import { parse, write } from 'sdp-transform';
10
- import { Subject, Observable, combineLatest, BehaviorSubject, ReplaySubject, shareReplay, map, distinctUntilChanged, startWith, takeWhile, distinctUntilKeyChanged, fromEventPattern, concatMap, merge, from, fromEvent, tap, debounceTime, pairwise, firstValueFrom, of, Subscription } from 'rxjs';
10
+ import { Subject, Observable, BehaviorSubject, distinctUntilChanged, shareReplay, ReplaySubject, map, combineLatest, startWith, takeWhile, distinctUntilKeyChanged, fromEventPattern, concatMap, merge, from, fromEvent, tap, debounceTime, pairwise, firstValueFrom, of, Subscription } from 'rxjs';
11
11
  import { UAParser } from 'ua-parser-js';
12
12
  import { WorkerTimer } from '@stream-io/worker-timer';
13
13
 
@@ -5081,7 +5081,7 @@ const toIceCandidate = (iceTrickle) => {
5081
5081
  }
5082
5082
  };
5083
5083
 
5084
- const version = "1.61.0";
5084
+ const version = "2.0.0-beta.1";
5085
5085
  const [major, minor, patch] = version.split('.');
5086
5086
  let sdkInfo = {
5087
5087
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -5461,11 +5461,14 @@ const isFunctionPatch = (update) => typeof update === 'function';
5461
5461
  * @param observable$ the observable to get the value from.
5462
5462
  */
5463
5463
  const getCurrentValue = (observable$) => {
5464
+ if (observable$ instanceof BehaviorSubject) {
5465
+ return observable$.getValue();
5466
+ }
5464
5467
  let value;
5465
5468
  let err = undefined;
5466
- combineLatest([observable$])
5469
+ observable$
5467
5470
  .subscribe({
5468
- next: ([v]) => {
5471
+ next: (v) => {
5469
5472
  value = v;
5470
5473
  },
5471
5474
  error: (e) => {
@@ -5614,38 +5617,39 @@ var CallingState;
5614
5617
  CallingState["OFFLINE"] = "offline";
5615
5618
  })(CallingState || (CallingState = {}));
5616
5619
 
5617
- class StreamVideoWriteableStateStore {
5618
- /**
5619
- * A store keeping data of a successfully connected user over WS to the coordinator server.
5620
- */
5621
- connectedUserSubject = new BehaviorSubject(undefined);
5622
- /**
5623
- * A list of {@link Call} objects created/tracked by this client.
5624
- */
5625
- callsSubject = new BehaviorSubject([]);
5626
- constructor() {
5627
- this.connectedUserSubject.subscribe(async (user) => {
5628
- // leave all calls when the user disconnects.
5629
- if (!user) {
5630
- const logger = videoLoggerSystem.getLogger('client-state');
5631
- for (const call of this.calls) {
5632
- if (call.state.callingState === CallingState.LEFT)
5633
- continue;
5634
- logger.info(`User disconnected, leaving call: ${call.cid}`);
5635
- await call
5636
- .leave({ message: 'client.disconnectUser() called' })
5637
- .catch((err) => {
5638
- logger.error(`Error leaving call: ${call.cid}`, err);
5639
- });
5640
- }
5641
- }
5642
- });
5643
- }
5644
- /**
5645
- * The currently connected user.
5646
- */
5620
+ function subject(initialValue) {
5621
+ return new BehaviorSubject(initialValue);
5622
+ }
5623
+ /**
5624
+ * Creates an Observable from the given subject by piping it to the
5625
+ * `distinctUntilChanged()` operator.
5626
+ */
5627
+ const duc = (source, comparator) => source.pipe(distinctUntilChanged(comparator));
5628
+ /**
5629
+ * Multicasts the given Observable, replaying the latest computed value to
5630
+ * every new subscriber instead of re-running the pipeline for each of them.
5631
+ */
5632
+ const shared = (source) => source.pipe(shareReplay({ bufferSize: 1, refCount: true }));
5633
+
5634
+ /**
5635
+ * Holds the state of the client, and the calls it created or tracks.
5636
+ * You can subscribe to the exposed observables to get notified about changes.
5637
+ */
5638
+ class ClientState {
5639
+ logger = videoLoggerSystem.getLogger('ClientState');
5640
+ connectedUserSubject = subject();
5641
+ callsSubject = subject([]);
5642
+ /** Data describing a user successfully connected over WS to the coordinator. */
5643
+ connectedUser$ = this.connectedUserSubject.asObservable();
5644
+ /** A list of {@link Call} objects created/tracked by this client. */
5645
+ calls$ = this.callsSubject.asObservable();
5646
+ /** The currently connected user. */
5647
5647
  get connectedUser() {
5648
- return this.connectedUserSubject.getValue();
5648
+ return getCurrentValue(this.connectedUserSubject);
5649
+ }
5650
+ /** A list of {@link Call} objects created/tracked by this client. */
5651
+ get calls() {
5652
+ return getCurrentValue(this.callsSubject);
5649
5653
  }
5650
5654
  /**
5651
5655
  * Sets the currently connected user.
@@ -5656,22 +5660,19 @@ class StreamVideoWriteableStateStore {
5656
5660
  setConnectedUser = (user) => {
5657
5661
  return setCurrentValue(this.connectedUserSubject, user);
5658
5662
  };
5659
- /**
5660
- * A list of {@link Call} objects created/tracked by this client.
5661
- */
5662
- get calls() {
5663
- return getCurrentValue(this.callsSubject);
5664
- }
5665
5663
  /**
5666
5664
  * Sets the list of {@link Call} objects created/tracked by this client.
5667
- * @param calls
5665
+ *
5666
+ * @internal
5667
+ * @param calls the calls to set.
5668
5668
  */
5669
5669
  setCalls = (calls) => {
5670
5670
  return setCurrentValue(this.callsSubject, calls);
5671
5671
  };
5672
5672
  /**
5673
- * Adds a {@link Call} object to the list of {@link Call} objects created/tracked by this client.
5673
+ * Adds a {@link Call} object to the list of calls tracked by this client.
5674
5674
  *
5675
+ * @internal
5675
5676
  * @param call the call to add.
5676
5677
  */
5677
5678
  registerCall = (call) => {
@@ -5682,6 +5683,7 @@ class StreamVideoWriteableStateStore {
5682
5683
  /**
5683
5684
  * Registers a {@link Call} object if it doesn't exist, otherwise updates it.
5684
5685
  *
5686
+ * @internal
5685
5687
  * @param call the call to register or update.
5686
5688
  */
5687
5689
  registerOrUpdateCall = (call) => {
@@ -5693,17 +5695,17 @@ class StreamVideoWriteableStateStore {
5693
5695
  }
5694
5696
  };
5695
5697
  /**
5696
- * Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
5698
+ * Removes a {@link Call} object from the list of calls tracked by this client.
5697
5699
  *
5698
- * @param call the call to remove
5700
+ * @internal
5701
+ * @param call the call to remove.
5699
5702
  */
5700
5703
  unregisterCall = (call) => {
5701
- const logger = videoLoggerSystem.getLogger('client-state');
5702
- logger.trace(`Unregistering call: ${call.cid}`);
5704
+ this.logger.trace(`Unregistering call: ${call.cid}`);
5703
5705
  return this.setCalls((calls) => calls.filter((c) => c !== call));
5704
5706
  };
5705
5707
  /**
5706
- * Finds a {@link Call} object in the list of {@link Call} objects created/tracked by this client.
5708
+ * Finds a {@link Call} object in the list of calls tracked by this client.
5707
5709
  *
5708
5710
  * @param type the type of call to find.
5709
5711
  * @param id the id of the call to find.
@@ -5712,38 +5714,6 @@ class StreamVideoWriteableStateStore {
5712
5714
  return this.calls.find((c) => c.type === type && c.id === id);
5713
5715
  };
5714
5716
  }
5715
- /**
5716
- * A reactive store that exposes state variables in a reactive manner.
5717
- * You can subscribe to changes of the different state variables.
5718
- * This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
5719
- */
5720
- class StreamVideoReadOnlyStateStore {
5721
- /**
5722
- * Data describing a user successfully connected over WS to coordinator server.
5723
- */
5724
- connectedUser$;
5725
- /**
5726
- * A list of {@link Call} objects created/tracked by this client.
5727
- */
5728
- calls$;
5729
- constructor(store) {
5730
- // convert and expose subjects as observables
5731
- this.connectedUser$ = store.connectedUserSubject.asObservable();
5732
- this.calls$ = store.callsSubject.asObservable();
5733
- }
5734
- /**
5735
- * The current user connected over WS to the backend.
5736
- */
5737
- get connectedUser() {
5738
- return getCurrentValue(this.connectedUser$);
5739
- }
5740
- /**
5741
- * A list of {@link Call} objects created/tracked by this client.
5742
- */
5743
- get calls() {
5744
- return getCurrentValue(this.calls$);
5745
- }
5746
- }
5747
5717
 
5748
5718
  /**
5749
5719
  * Creates a new combined {@link Comparator<T>} which sorts items by the given comparators.
@@ -6076,9 +6046,7 @@ const paginatedLayoutSortPreset = combineComparators(pinned, ifInvisibleOrUnknow
6076
6046
  */
6077
6047
  const livestreamOrAudioRoomSortPreset = combineComparators(publishing, ifInvisibleOrUnknownBy(combineComparators(dominantSpeaker, speaking, reactionType('raised-hand'), withVideoIngressSource, publishingVideo, publishingAudio)), role('admin', 'host', 'speaker'));
6078
6048
 
6079
- /**
6080
- * Returns the default egress object - when no egress data is available.
6081
- */
6049
+ /** Returns the default egress object - when no egress data is available. */
6082
6050
  const defaultEgress = {
6083
6051
  broadcasting: false,
6084
6052
  hls: { playlist_url: '', status: '' },
@@ -6089,93 +6057,120 @@ const defaultEgress = {
6089
6057
  * @react You don't have to use this class directly, as we are exposing the state through Hooks.
6090
6058
  */
6091
6059
  class CallState {
6092
- backstageSubject = new BehaviorSubject(true);
6093
- blockedUserIdsSubject = new BehaviorSubject([]);
6094
- createdAtSubject = new BehaviorSubject(new Date());
6095
- endedAtSubject = new BehaviorSubject(undefined);
6096
- startsAtSubject = new BehaviorSubject(undefined);
6097
- updatedAtSubject = new BehaviorSubject(new Date());
6098
- createdBySubject = new BehaviorSubject(undefined);
6099
- customSubject = new BehaviorSubject({});
6100
- egressSubject = new BehaviorSubject(undefined);
6101
- ingressSubject = new BehaviorSubject(undefined);
6102
- recordingSubject = new BehaviorSubject(false);
6103
- individualRecordingSubject = new BehaviorSubject(false);
6104
- rawRecordingSubject = new BehaviorSubject(false);
6105
- sessionSubject = new BehaviorSubject(undefined);
6106
- settingsSubject = new BehaviorSubject(undefined);
6107
- transcribingSubject = new BehaviorSubject(false);
6108
- captioningSubject = new BehaviorSubject(false);
6109
- e2eeEnabledSubject = new BehaviorSubject(false);
6110
- endedBySubject = new BehaviorSubject(undefined);
6111
- thumbnailsSubject = new BehaviorSubject(undefined);
6112
- membersSubject = new BehaviorSubject([]);
6113
- ownCapabilitiesSubject = new BehaviorSubject([]);
6114
- callingStateSubject = new BehaviorSubject(CallingState.UNKNOWN);
6115
- startedAtSubject = new BehaviorSubject(undefined);
6116
- participantCountSubject = new BehaviorSubject(0);
6117
- anonymousParticipantCountSubject = new BehaviorSubject(0);
6118
- participantsSubject = new BehaviorSubject([]);
6119
- callStatsReportSubject = new BehaviorSubject(undefined);
6120
- closedCaptionsSubject = new BehaviorSubject([]);
6121
- // These are tracks that were delivered to the Subscriber's onTrack event
6122
- // that we couldn't associate with a participant yet.
6123
- // This happens when the participantJoined event hasn't been received yet.
6124
- // We keep these tracks around until we can associate them with a participant.
6125
- orphanedTracks = [];
6060
+ logger = videoLoggerSystem.getLogger('CallState');
6061
+ /** A list of comparators that are used to sort the participants. */
6062
+ sortParticipantsBy = defaultSortPreset;
6063
+ backstageSubject = subject(true);
6064
+ blockedUserIdsSubject = subject([]);
6065
+ createdAtSubject = subject(new Date());
6066
+ endedAtSubject = subject();
6067
+ startsAtSubject = subject();
6068
+ updatedAtSubject = subject(new Date());
6069
+ createdBySubject = subject();
6070
+ customSubject = subject({});
6071
+ egressSubject = subject();
6072
+ ingressSubject = subject();
6073
+ recordingSubject = subject(false);
6074
+ individualRecordingSubject = subject(false);
6075
+ rawRecordingSubject = subject(false);
6076
+ sessionSubject = subject();
6077
+ settingsSubject = subject();
6078
+ transcribingSubject = subject(false);
6079
+ captioningSubject = subject(false);
6080
+ e2eeEnabledSubject = subject(false);
6081
+ endedBySubject = subject();
6082
+ thumbnailsSubject = subject();
6083
+ membersSubject = subject([]);
6084
+ ownCapabilitiesSubject = subject([]);
6085
+ callingStateSubject = subject(CallingState.UNKNOWN);
6086
+ startedAtSubject = subject();
6087
+ participantCountSubject = subject(0);
6088
+ anonymousParticipantCountSubject = subject(0);
6089
+ participantsSubject = subject([]);
6090
+ callStatsReportSubject = subject();
6091
+ closedCaptionsSubject = subject([]);
6126
6092
  callGrantsSubject = new ReplaySubject(1);
6127
- // Derived state
6093
+ /** The backstage state. */
6094
+ backstage$ = duc(this.backstageSubject);
6095
+ /** Will provide the list of blocked user IDs. */
6096
+ blockedUserIds$ = duc(this.blockedUserIdsSubject, isShallowArrayEqual);
6097
+ /** Will provide the time when this call has been created. */
6098
+ createdAt$ = this.createdAtSubject.asObservable();
6099
+ /** Will provide the time when this call has been ended. */
6100
+ endedAt$ = this.endedAtSubject.asObservable();
6101
+ /** Will provide the time when this call has been scheduled to start. */
6102
+ startsAt$ = this.startsAtSubject.asObservable();
6103
+ /** Will provide the time when this call has been updated. */
6104
+ updatedAt$ = this.updatedAtSubject.asObservable();
6105
+ /** Will provide the user who created this call. */
6106
+ createdBy$ = this.createdBySubject.asObservable();
6107
+ /** Will provide the custom data of this call. */
6108
+ custom$ = this.customSubject.asObservable();
6109
+ /** Will provide the egress data of this call. */
6110
+ egress$ = this.egressSubject.asObservable();
6111
+ /** Will provide the ingress data of this call. */
6112
+ ingress$ = this.ingressSubject.asObservable();
6113
+ /** Will provide the recording state of this call. */
6114
+ recording$ = duc(this.recordingSubject);
6115
+ /** Will provide the recording state of this call. */
6116
+ individualRecording$ = duc(this.individualRecordingSubject);
6117
+ /** Will provide the recording state of this call. */
6118
+ rawRecording$ = duc(this.rawRecordingSubject);
6119
+ /** Will provide the session data of this call. */
6120
+ session$ = this.sessionSubject.asObservable();
6121
+ /** Will provide the settings of this call. */
6122
+ settings$ = this.settingsSubject.asObservable();
6123
+ /** Will provide the transcribing state of this call. */
6124
+ transcribing$ = duc(this.transcribingSubject);
6125
+ /** Will provide the closed captioning state of this call. */
6126
+ captioning$ = duc(this.captioningSubject);
6127
+ /**
6128
+ * Whether end-to-end encryption is active for this call, as reported by the
6129
+ * SFU in the join response.
6130
+ */
6131
+ e2eeEnabled$ = duc(this.e2eeEnabledSubject);
6132
+ /** Will provide the user who ended this call. */
6133
+ endedBy$ = this.endedBySubject.asObservable();
6134
+ /** Will provide the thumbnails of this call. */
6135
+ thumbnails$ = this.thumbnailsSubject.asObservable();
6136
+ /** The list of members in the current call. */
6137
+ members$ = this.membersSubject.asObservable();
6138
+ /** The calling state. */
6139
+ callingState$ = duc(this.callingStateSubject);
6128
6140
  /**
6129
6141
  * The time the call session actually started.
6130
6142
  * Useful for displaying the call duration.
6131
6143
  */
6132
- startedAt$;
6144
+ startedAt$ = this.startedAtSubject.asObservable();
6133
6145
  /**
6134
6146
  * The server-side counted number of participants connected to the current call.
6135
6147
  * This number includes the anonymous participants as well.
6136
6148
  */
6137
- participantCount$;
6149
+ participantCount$ = duc(this.participantCountSubject);
6138
6150
  /**
6139
6151
  * The server-side counted number of anonymous participants connected to the current call.
6140
6152
  * This number excludes the regular participants.
6141
6153
  */
6142
- anonymousParticipantCount$;
6154
+ anonymousParticipantCount$ = duc(this.anonymousParticipantCountSubject);
6143
6155
  /**
6144
6156
  * All participants of the current call (this includes the current user and other participants as well),
6145
6157
  * unsorted. This observable only updates when participants join or leave the call.
6146
6158
  */
6147
- rawParticipants$;
6148
- /**
6149
- * All participants of the current call (this includes the current user and other participants as well),
6150
- * sorted according to the current `sortByParticipantsBy` setting
6151
- */
6152
- participants$;
6153
- /**
6154
- * Remote participants of the current call (this includes every participant except the logged-in user).
6155
- */
6156
- remoteParticipants$;
6157
- /**
6158
- * The local participant of the current call (the logged-in user).
6159
- */
6160
- localParticipant$;
6161
- /**
6162
- * Pinned participants of the current call.
6163
- */
6164
- pinnedParticipants$;
6165
- /**
6166
- * The currently elected dominant speaker in the current call.
6167
- */
6168
- dominantSpeaker$;
6169
- /**
6170
- * Emits true whenever there is an active screen sharing session within
6171
- * the current call. Useful for displaying a "screen sharing" indicator and
6172
- * switching the layout to a screen sharing layout.
6173
- *
6174
- * The actual screen sharing track isn't exposed here, but can be retrieved
6175
- * from the list of call participants. We also don't want to be limiting
6176
- * to the number of share screen tracks are displayed in a call.
6177
- */
6178
- hasOngoingScreenShare$;
6159
+ rawParticipants$ = shared(this.participantsSubject.asObservable());
6160
+ /** All participants of the current call sorted according to the current `sortByParticipantsBy` setting. */
6161
+ participants$ = shared(this.participantsSubject.asObservable().pipe(
6162
+ // maintain stable-sort by mutating the participants stored in the original subject
6163
+ map((ps) => ps.sort(this.sortParticipantsBy))));
6164
+ /** The local participant of the current call. */
6165
+ localParticipant$ = shared(this.participants$.pipe(map((ps) => ps.find((p) => p.isLocalParticipant))));
6166
+ /** Remote participants of the current call (all except the local participant). */
6167
+ remoteParticipants$ = shared(this.participants$.pipe(map((ps) => ps.filter((p) => !p.isLocalParticipant))));
6168
+ /** Pinned participants of the current call. */
6169
+ pinnedParticipants$ = shared(this.participants$.pipe(map((ps) => ps.filter((p) => !!p.pin))));
6170
+ /** The currently elected dominant speaker in the current call. */
6171
+ dominantSpeaker$ = shared(this.participants$.pipe(map((ps) => ps.find((p) => p.isDominantSpeaker))));
6172
+ /** Emits true whenever there is an active screen sharing session within the current call. */
6173
+ hasOngoingScreenShare$ = shared(this.participants$.pipe(map((ps) => ps.some((p) => hasScreenShare(p))), distinctUntilChanged()));
6179
6174
  /**
6180
6175
  * The latest stats report of the current call.
6181
6176
  * When stats gathering is enabled, this observable will emit a new value
@@ -6184,232 +6179,66 @@ class CallState {
6184
6179
  * Consumers of this observable can implement their own batching logic
6185
6180
  * in case they want to show historical stats data.
6186
6181
  */
6187
- callStatsReport$;
6188
- /**
6189
- * The list of members in the current call.
6190
- */
6191
- members$;
6192
- /**
6193
- * The list of capabilities of the current user.
6194
- */
6195
- ownCapabilities$;
6196
- /**
6197
- * The calling state.
6198
- */
6199
- callingState$;
6200
- /**
6201
- * The backstage state.
6202
- */
6203
- backstage$;
6204
- /**
6205
- * Will provide the list of blocked user IDs.
6206
- */
6207
- blockedUserIds$;
6208
- /**
6209
- * Will provide the time when this call has been created.
6210
- */
6211
- createdAt$;
6212
- /**
6213
- * Will provide the time when this call has been ended.
6214
- */
6215
- endedAt$;
6216
- /**
6217
- * Will provide the time when this call has been scheduled to start.
6218
- */
6219
- startsAt$;
6220
- /**
6221
- * Will provide the time when this call has been updated.
6222
- */
6223
- updatedAt$;
6224
- /**
6225
- * Will provide the user who created this call.
6226
- */
6227
- createdBy$;
6228
- /**
6229
- * Will provide the custom data of this call.
6230
- */
6231
- custom$;
6232
- /**
6233
- * Will provide the egress data of this call.
6234
- */
6235
- egress$;
6236
- /**
6237
- * Will provide the ingress data of this call.
6238
- */
6239
- ingress$;
6240
- /**
6241
- * Will provide the recording state of this call.
6242
- */
6243
- recording$;
6244
- /**
6245
- * Will provide the recording state of this call.
6246
- */
6247
- individualRecording$;
6248
- /**
6249
- * Will provide the recording state of this call.
6250
- */
6251
- rawRecording$;
6252
- /**
6253
- * Will provide the session data of this call.
6254
- */
6255
- session$;
6256
- /**
6257
- * Will provide the settings of this call.
6258
- */
6259
- settings$;
6260
- /**
6261
- * Will provide the transcribing state of this call.
6262
- */
6263
- transcribing$;
6264
- /**
6265
- * Will provide the closed captioning state of this call.
6266
- */
6267
- captioning$;
6268
- /**
6269
- * Whether end-to-end encryption is active for this call, as reported by the
6270
- * SFU in the join response.
6271
- */
6272
- e2eeEnabled$;
6273
- /**
6274
- * Will provide the user who ended this call.
6275
- */
6276
- endedBy$;
6277
- /**
6278
- * Will provide the thumbnails of this call.
6279
- */
6280
- thumbnails$;
6281
- /**
6282
- * The queue of closed captions.
6283
- */
6284
- closedCaptions$;
6285
- logger = videoLoggerSystem.getLogger('CallState');
6286
- /**
6287
- * A list of comparators that are used to sort the participants.
6288
- */
6289
- sortParticipantsBy = defaultSortPreset;
6290
- /**
6291
- * The closed captions configuration.
6292
- */
6182
+ callStatsReport$ = this.callStatsReportSubject.asObservable();
6183
+ /** The queue of closed captions. */
6184
+ closedCaptions$ = this.closedCaptionsSubject.asObservable();
6185
+ /** The list of capabilities of the current user. */
6186
+ ownCapabilities$ = shared(combineLatest([
6187
+ this.ownCapabilitiesSubject,
6188
+ this.callGrantsSubject.pipe(startWith(undefined)),
6189
+ ]).pipe(map(([capabilities, grants]) => {
6190
+ if (!grants)
6191
+ return capabilities;
6192
+ const { canPublishAudio, canPublishVideo, canScreenshare } = grants;
6193
+ const update = {
6194
+ [OwnCapability.SEND_AUDIO]: canPublishAudio,
6195
+ [OwnCapability.SEND_VIDEO]: canPublishVideo,
6196
+ [OwnCapability.SCREENSHARE]: canScreenshare,
6197
+ };
6198
+ const nextCapabilities = [...capabilities];
6199
+ for (const _capability in update) {
6200
+ const capability = _capability;
6201
+ const allowed = update[capability];
6202
+ // grants take precedence over capabilities, reconstruct the capabilities
6203
+ if (allowed && !nextCapabilities.includes(capability)) {
6204
+ nextCapabilities.push(capability);
6205
+ }
6206
+ else if (!allowed && nextCapabilities.includes(capability)) {
6207
+ const index = nextCapabilities.indexOf(capability);
6208
+ nextCapabilities.splice(index, 1);
6209
+ }
6210
+ }
6211
+ return nextCapabilities;
6212
+ }), distinctUntilChanged(isShallowArrayEqual)));
6213
+ // These are tracks that were delivered to the Subscriber's onTrack event
6214
+ // that we couldn't associate with a participant yet.
6215
+ // This happens when the participantJoined event hasn't been received yet.
6216
+ // We keep these tracks around until we can associate them with a participant.
6217
+ orphanedTracks = [];
6218
+ /** The closed captions configuration. */
6293
6219
  closedCaptionsSettings;
6294
6220
  closedCaptionsTasks = new Map();
6295
6221
  eventHandlers;
6296
- /**
6297
- * Creates a new instance of the CallState class.
6298
- *
6299
- */
6222
+ /** Creates a new instance of the CallState class. */
6300
6223
  constructor() {
6301
- this.rawParticipants$ = this.participantsSubject
6302
- .asObservable()
6303
- .pipe(shareReplay({ bufferSize: 1, refCount: true }));
6304
- this.participants$ = this.participantsSubject.asObservable().pipe(
6305
- // maintain stable-sort by mutating the participants stored
6306
- // in the original subject
6307
- map((ps) => ps.sort(this.sortParticipantsBy)), shareReplay({ bufferSize: 1, refCount: true }));
6308
- this.localParticipant$ = this.participants$.pipe(map((participants) => participants.find((p) => p.isLocalParticipant)), shareReplay({ bufferSize: 1, refCount: true }));
6309
- this.remoteParticipants$ = this.participants$.pipe(map((participants) => participants.filter((p) => !p.isLocalParticipant)), shareReplay({ bufferSize: 1, refCount: true }));
6310
- this.pinnedParticipants$ = this.participants$.pipe(map((participants) => participants.filter((p) => !!p.pin)), shareReplay({ bufferSize: 1, refCount: true }));
6311
- this.dominantSpeaker$ = this.participants$.pipe(map((participants) => participants.find((p) => p.isDominantSpeaker)), shareReplay({ bufferSize: 1, refCount: true }));
6312
- this.hasOngoingScreenShare$ = this.participants$.pipe(map((participants) => participants.some((p) => hasScreenShare(p))), distinctUntilChanged(), shareReplay({ bufferSize: 1, refCount: true }));
6313
- // dates
6314
- this.createdAt$ = this.createdAtSubject.asObservable();
6315
- this.endedAt$ = this.endedAtSubject.asObservable();
6316
- this.startsAt$ = this.startsAtSubject.asObservable();
6317
- this.startedAt$ = this.startedAtSubject.asObservable();
6318
- this.updatedAt$ = this.updatedAtSubject.asObservable();
6319
- this.callStatsReport$ = this.callStatsReportSubject.asObservable();
6320
- this.members$ = this.membersSubject.asObservable();
6321
- // complex objects should work as streams of data
6322
- this.createdBy$ = this.createdBySubject.asObservable();
6323
- this.custom$ = this.customSubject.asObservable();
6324
- this.egress$ = this.egressSubject.asObservable();
6325
- this.ingress$ = this.ingressSubject.asObservable();
6326
- this.session$ = this.sessionSubject.asObservable();
6327
- this.settings$ = this.settingsSubject.asObservable();
6328
- this.endedBy$ = this.endedBySubject.asObservable();
6329
- this.thumbnails$ = this.thumbnailsSubject.asObservable();
6330
- this.closedCaptions$ = this.closedCaptionsSubject.asObservable();
6331
- /**
6332
- * Creates an Observable from the given subject by piping to the
6333
- * `distinctUntilChanged()` operator.
6334
- */
6335
- const duc = (subject, comparator) => subject.pipe(distinctUntilChanged(comparator));
6336
- // primitive values should only emit once the value they hold changes
6337
- this.anonymousParticipantCount$ = duc(this.anonymousParticipantCountSubject);
6338
- this.blockedUserIds$ = duc(this.blockedUserIdsSubject, isShallowArrayEqual);
6339
- this.backstage$ = duc(this.backstageSubject);
6340
- this.callingState$ = duc(this.callingStateSubject);
6341
- this.ownCapabilities$ = combineLatest([
6342
- this.ownCapabilitiesSubject,
6343
- this.callGrantsSubject.pipe(startWith(undefined)),
6344
- ]).pipe(map(([capabilities, grants]) => {
6345
- if (!grants)
6346
- return capabilities;
6347
- const { canPublishAudio, canPublishVideo, canScreenshare } = grants;
6348
- const update = {
6349
- [OwnCapability.SEND_AUDIO]: canPublishAudio,
6350
- [OwnCapability.SEND_VIDEO]: canPublishVideo,
6351
- [OwnCapability.SCREENSHARE]: canScreenshare,
6352
- };
6353
- const nextCapabilities = [...capabilities];
6354
- for (const _capability in update) {
6355
- const capability = _capability;
6356
- const allowed = update[capability];
6357
- // grants take precedence over capabilities, reconstruct the capabilities
6358
- if (allowed && !nextCapabilities.includes(capability)) {
6359
- nextCapabilities.push(capability);
6360
- }
6361
- else if (!allowed && nextCapabilities.includes(capability)) {
6362
- const index = nextCapabilities.indexOf(capability);
6363
- nextCapabilities.splice(index, 1);
6364
- }
6365
- }
6366
- return nextCapabilities;
6367
- }), distinctUntilChanged(isShallowArrayEqual), shareReplay({ bufferSize: 1, refCount: true }));
6368
- this.participantCount$ = duc(this.participantCountSubject);
6369
- this.recording$ = duc(this.recordingSubject);
6370
- this.individualRecording$ = duc(this.individualRecordingSubject);
6371
- this.rawRecording$ = duc(this.rawRecordingSubject);
6372
- this.transcribing$ = duc(this.transcribingSubject);
6373
- this.captioning$ = duc(this.captioningSubject);
6374
- this.e2eeEnabled$ = duc(this.e2eeEnabledSubject);
6375
6224
  this.eventHandlers = {
6376
- // these events are not updating the call state:
6377
- 'call.frame_recording_ready': undefined,
6378
- 'call.kicked_user': undefined,
6379
- 'call.moderation_blur': undefined,
6380
- 'call.moderation_warning': undefined,
6381
- 'call.permission_request': undefined,
6382
- 'call.recording_ready': undefined,
6383
- 'call.rtmp_broadcast_failed': undefined,
6384
- 'call.rtmp_broadcast_started': undefined,
6385
- 'call.rtmp_broadcast_stopped': undefined,
6386
- 'call.stats_report_ready': undefined,
6387
- 'call.transcription_ready': undefined,
6388
- 'call.user_feedback_submitted': undefined,
6389
- 'call.user_muted': undefined,
6390
- 'connection.error': undefined,
6391
- 'connection.ok': undefined,
6392
- 'health.check': undefined,
6393
- 'user.updated': undefined,
6394
- custom: undefined,
6395
- // events that update call state:
6396
6225
  'call.accepted': (e) => this.updateFromCallResponse(e.call),
6397
6226
  'call.blocked_user': this.blockUser,
6398
6227
  'call.closed_caption': this.updateFromClosedCaptions,
6399
6228
  'call.closed_captions_failed': () => {
6400
- this.setCurrentValue(this.captioningSubject, false);
6229
+ setCurrentValue(this.captioningSubject, false);
6401
6230
  },
6402
6231
  'call.closed_captions_started': () => {
6403
- this.setCurrentValue(this.captioningSubject, true);
6232
+ setCurrentValue(this.captioningSubject, true);
6404
6233
  },
6405
6234
  'call.closed_captions_stopped': () => {
6406
- this.setCurrentValue(this.captioningSubject, false);
6235
+ setCurrentValue(this.captioningSubject, false);
6407
6236
  },
6408
6237
  'call.created': (e) => this.updateFromCallResponse(e.call),
6409
6238
  'call.deleted': (e) => this.updateFromCallResponse(e.call),
6410
6239
  'call.ended': (e) => {
6411
6240
  this.updateFromCallResponse(e.call);
6412
- this.setCurrentValue(this.endedBySubject, e.user);
6241
+ setCurrentValue(this.endedBySubject, e.user);
6413
6242
  },
6414
6243
  'call.frame_recording_failed': (e) => {
6415
6244
  this.updateFromCallResponse(e.call);
@@ -6454,21 +6283,19 @@ class CallState {
6454
6283
  'call.session_participant_left': this.updateFromSessionParticipantLeft,
6455
6284
  'call.session_started': (e) => this.updateFromCallResponse(e.call),
6456
6285
  'call.transcription_started': () => {
6457
- this.setCurrentValue(this.transcribingSubject, true);
6286
+ setCurrentValue(this.transcribingSubject, true);
6458
6287
  },
6459
6288
  'call.transcription_stopped': () => {
6460
- this.setCurrentValue(this.transcribingSubject, false);
6289
+ setCurrentValue(this.transcribingSubject, false);
6461
6290
  },
6462
6291
  'call.transcription_failed': () => {
6463
- this.setCurrentValue(this.transcribingSubject, false);
6292
+ setCurrentValue(this.transcribingSubject, false);
6464
6293
  },
6465
6294
  'call.unblocked_user': this.unblockUser,
6466
6295
  'call.updated': (e) => this.updateFromCallResponse(e.call),
6467
6296
  };
6468
6297
  }
6469
- /**
6470
- * Runs the cleanup tasks.
6471
- */
6298
+ /** Runs the cleanup tasks. */
6472
6299
  dispose = () => {
6473
6300
  for (const [ccKey, taskId] of this.closedCaptionsTasks.entries()) {
6474
6301
  clearTimeout(taskId);
@@ -6485,39 +6312,18 @@ class CallState {
6485
6312
  setSortParticipantsBy = (comparator) => {
6486
6313
  this.sortParticipantsBy = comparator;
6487
6314
  // trigger re-sorting of participants
6488
- this.setCurrentValue(this.participantsSubject, (ps) => ps);
6315
+ setCurrentValue(this.participantsSubject, (ps) => ps);
6489
6316
  };
6490
- /**
6491
- * Returns the comparator currently used to sort the participants.
6492
- */
6317
+ /** Returns the comparator currently used to sort the participants. */
6493
6318
  getSortParticipantsBy = () => {
6494
6319
  return this.sortParticipantsBy;
6495
6320
  };
6496
- /**
6497
- * Gets the current value of an observable, or undefined if the observable has
6498
- * not emitted a value yet.
6499
- *
6500
- * @param observable$ the observable to get the value from.
6501
- */
6502
- getCurrentValue = getCurrentValue;
6503
- /**
6504
- * Updates the value of the provided Subject.
6505
- * An `update` can either be a new value or a function which takes
6506
- * the current value and returns a new value.
6507
- *
6508
- * @internal
6509
- *
6510
- * @param subject the subject to update.
6511
- * @param update the update to apply to the subject.
6512
- * @return the updated value.
6513
- */
6514
- setCurrentValue = setCurrentValue;
6515
6321
  /**
6516
6322
  * The server-side counted number of participants connected to the current call.
6517
6323
  * This number includes the anonymous participants as well.
6518
6324
  */
6519
6325
  get participantCount() {
6520
- return this.getCurrentValue(this.participantCount$);
6326
+ return getCurrentValue(this.participantCountSubject);
6521
6327
  }
6522
6328
  /**
6523
6329
  * Sets the number of participants in the current call.
@@ -6526,14 +6332,14 @@ class CallState {
6526
6332
  * @param count the number of participants.
6527
6333
  */
6528
6334
  setParticipantCount = (count) => {
6529
- return this.setCurrentValue(this.participantCountSubject, count);
6335
+ return setCurrentValue(this.participantCountSubject, count);
6530
6336
  };
6531
6337
  /**
6532
6338
  * The time the call session actually started.
6533
6339
  * Useful for displaying the call duration.
6534
6340
  */
6535
6341
  get startedAt() {
6536
- return this.getCurrentValue(this.startedAt$);
6342
+ return getCurrentValue(this.startedAtSubject);
6537
6343
  }
6538
6344
  /**
6539
6345
  * Sets the time the call session actually started.
@@ -6542,13 +6348,11 @@ class CallState {
6542
6348
  * @param startedAt the time the call session actually started.
6543
6349
  */
6544
6350
  setStartedAt = (startedAt) => {
6545
- return this.setCurrentValue(this.startedAtSubject, startedAt);
6351
+ return setCurrentValue(this.startedAtSubject, startedAt);
6546
6352
  };
6547
- /**
6548
- * Returns whether closed captions are enabled in the current call.
6549
- */
6353
+ /** Returns whether closed captions are enabled in the current call. */
6550
6354
  get captioning() {
6551
- return this.getCurrentValue(this.captioning$);
6355
+ return getCurrentValue(this.captioningSubject);
6552
6356
  }
6553
6357
  /**
6554
6358
  * Sets the closed captioning state of the current call.
@@ -6564,7 +6368,7 @@ class CallState {
6564
6368
  * This number includes the anonymous participants as well.
6565
6369
  */
6566
6370
  get anonymousParticipantCount() {
6567
- return this.getCurrentValue(this.anonymousParticipantCount$);
6371
+ return getCurrentValue(this.anonymousParticipantCountSubject);
6568
6372
  }
6569
6373
  /**
6570
6374
  * Sets the number of anonymous participants in the current call.
@@ -6573,19 +6377,15 @@ class CallState {
6573
6377
  * @param count the number of anonymous participants.
6574
6378
  */
6575
6379
  setAnonymousParticipantCount = (count) => {
6576
- return this.setCurrentValue(this.anonymousParticipantCountSubject, count);
6380
+ return setCurrentValue(this.anonymousParticipantCountSubject, count);
6577
6381
  };
6578
- /**
6579
- * The list of participants in the current call.
6580
- */
6382
+ /** The list of participants in the current call. */
6581
6383
  get participants() {
6582
- return this.getCurrentValue(this.participants$);
6384
+ return getCurrentValue(this.participants$);
6583
6385
  }
6584
- /**
6585
- * The stable list of participants in the current call, unsorted.
6586
- */
6386
+ /** The stable list of participants in the current call, unsorted. */
6587
6387
  get rawParticipants() {
6588
- return this.getCurrentValue(this.rawParticipants$);
6388
+ return getCurrentValue(this.rawParticipants$);
6589
6389
  }
6590
6390
  /**
6591
6391
  * Returns the current participants array directly from the BehaviorSubject.
@@ -6606,43 +6406,31 @@ class CallState {
6606
6406
  * @param participants the list of participants.
6607
6407
  */
6608
6408
  setParticipants = (participants) => {
6609
- return this.setCurrentValue(this.participantsSubject, participants);
6409
+ return setCurrentValue(this.participantsSubject, participants);
6610
6410
  };
6611
- /**
6612
- * The local participant in the current call.
6613
- */
6411
+ /** The local participant in the current call. */
6614
6412
  get localParticipant() {
6615
- return this.getCurrentValue(this.localParticipant$);
6413
+ return getCurrentValue(this.localParticipant$);
6616
6414
  }
6617
- /**
6618
- * The list of remote participants in the current call.
6619
- */
6415
+ /** The list of remote participants in the current call. */
6620
6416
  get remoteParticipants() {
6621
- return this.getCurrentValue(this.remoteParticipants$);
6417
+ return getCurrentValue(this.remoteParticipants$);
6622
6418
  }
6623
- /**
6624
- * The dominant speaker in the current call.
6625
- */
6419
+ /** The dominant speaker in the current call. */
6626
6420
  get dominantSpeaker() {
6627
- return this.getCurrentValue(this.dominantSpeaker$);
6421
+ return getCurrentValue(this.dominantSpeaker$);
6628
6422
  }
6629
- /**
6630
- * The list of pinned participants in the current call.
6631
- */
6423
+ /** The list of pinned participants in the current call. */
6632
6424
  get pinnedParticipants() {
6633
- return this.getCurrentValue(this.pinnedParticipants$);
6425
+ return getCurrentValue(this.pinnedParticipants$);
6634
6426
  }
6635
- /**
6636
- * Tell if there is an ongoing screen share in this call.
6637
- */
6427
+ /** Tell if there is an ongoing screen share in this call. */
6638
6428
  get hasOngoingScreenShare() {
6639
- return this.getCurrentValue(this.hasOngoingScreenShare$);
6429
+ return getCurrentValue(this.hasOngoingScreenShare$);
6640
6430
  }
6641
- /**
6642
- * The calling state.
6643
- */
6431
+ /** The calling state. */
6644
6432
  get callingState() {
6645
- return this.getCurrentValue(this.callingState$);
6433
+ return getCurrentValue(this.callingStateSubject);
6646
6434
  }
6647
6435
  /**
6648
6436
  * Sets the calling state.
@@ -6651,13 +6439,11 @@ class CallState {
6651
6439
  * @param state the new calling state.
6652
6440
  */
6653
6441
  setCallingState = (state) => {
6654
- return this.setCurrentValue(this.callingStateSubject, state);
6442
+ return setCurrentValue(this.callingStateSubject, state);
6655
6443
  };
6656
- /**
6657
- * The call stats report.
6658
- */
6444
+ /** The call stats report. */
6659
6445
  get callStatsReport() {
6660
- return this.getCurrentValue(this.callStatsReport$);
6446
+ return getCurrentValue(this.callStatsReportSubject);
6661
6447
  }
6662
6448
  /**
6663
6449
  * Returns whether the call stats report is being observed or not.
@@ -6673,13 +6459,11 @@ class CallState {
6673
6459
  * @param report the report to set.
6674
6460
  */
6675
6461
  setCallStatsReport = (report) => {
6676
- return this.setCurrentValue(this.callStatsReportSubject, report);
6462
+ return setCurrentValue(this.callStatsReportSubject, report);
6677
6463
  };
6678
- /**
6679
- * The members of the current call.
6680
- */
6464
+ /** The members of the current call. */
6681
6465
  get members() {
6682
- return this.getCurrentValue(this.members$);
6466
+ return getCurrentValue(this.membersSubject);
6683
6467
  }
6684
6468
  /**
6685
6469
  * Sets the members of the current call.
@@ -6688,13 +6472,11 @@ class CallState {
6688
6472
  * @param members the members to set.
6689
6473
  */
6690
6474
  setMembers = (members) => {
6691
- this.setCurrentValue(this.membersSubject, members);
6475
+ setCurrentValue(this.membersSubject, members);
6692
6476
  };
6693
- /**
6694
- * The capabilities of the current user for the current call.
6695
- */
6477
+ /** The capabilities of the current user for the current call. */
6696
6478
  get ownCapabilities() {
6697
- return this.getCurrentValue(this.ownCapabilities$);
6479
+ return getCurrentValue(this.ownCapabilities$);
6698
6480
  }
6699
6481
  /**
6700
6482
  * Sets the own capabilities.
@@ -6703,7 +6485,7 @@ class CallState {
6703
6485
  * @param capabilities the capabilities to set.
6704
6486
  */
6705
6487
  setOwnCapabilities = (capabilities) => {
6706
- return this.setCurrentValue(this.ownCapabilitiesSubject, capabilities);
6488
+ return setCurrentValue(this.ownCapabilitiesSubject, capabilities);
6707
6489
  };
6708
6490
  /**
6709
6491
  * Sets the call grants (used for own capabilities).
@@ -6712,141 +6494,105 @@ class CallState {
6712
6494
  * @param grants the grants to set.
6713
6495
  */
6714
6496
  setCallGrants = (grants) => {
6715
- return this.setCurrentValue(this.callGrantsSubject, grants);
6497
+ return setCurrentValue(this.callGrantsSubject, grants);
6716
6498
  };
6717
- /**
6718
- * The backstage state.
6719
- */
6499
+ /** The backstage state. */
6720
6500
  get backstage() {
6721
- return this.getCurrentValue(this.backstage$);
6501
+ return getCurrentValue(this.backstageSubject);
6722
6502
  }
6723
6503
  /**
6724
6504
  * Sets the backstage state.
6725
6505
  * @param backstage the backstage state.
6726
6506
  */
6727
6507
  setBackstage = (backstage) => {
6728
- return this.setCurrentValue(this.backstageSubject, backstage);
6508
+ return setCurrentValue(this.backstageSubject, backstage);
6729
6509
  };
6730
- /**
6731
- * Will provide the list of blocked user IDs.
6732
- */
6510
+ /** Will provide the list of blocked user IDs. */
6733
6511
  get blockedUserIds() {
6734
- return this.getCurrentValue(this.blockedUserIds$);
6512
+ return getCurrentValue(this.blockedUserIdsSubject);
6735
6513
  }
6736
- /**
6737
- * Will provide the time when this call has been created.
6738
- */
6514
+ /** Will provide the time when this call has been created. */
6739
6515
  get createdAt() {
6740
- return this.getCurrentValue(this.createdAt$);
6516
+ return getCurrentValue(this.createdAtSubject);
6741
6517
  }
6742
- /**
6743
- * Will provide the time when this call has been ended.
6744
- */
6518
+ /** Will provide the time when this call has been ended. */
6745
6519
  get endedAt() {
6746
- return this.getCurrentValue(this.endedAt$);
6520
+ return getCurrentValue(this.endedAtSubject);
6747
6521
  }
6748
6522
  /**
6749
6523
  * Sets the time when this call has been ended.
6750
6524
  * @param endedAt the time when this call has been ended.
6751
6525
  */
6752
6526
  setEndedAt = (endedAt) => {
6753
- return this.setCurrentValue(this.endedAtSubject, endedAt);
6527
+ return setCurrentValue(this.endedAtSubject, endedAt);
6754
6528
  };
6755
- /**
6756
- * Will provide the time when this call has been scheduled to start.
6757
- */
6529
+ /** Will provide the time when this call has been scheduled to start. */
6758
6530
  get startsAt() {
6759
- return this.getCurrentValue(this.startsAt$);
6531
+ return getCurrentValue(this.startsAtSubject);
6760
6532
  }
6761
- /**
6762
- * Will provide the time when this call has been updated.
6763
- */
6533
+ /** Will provide the time when this call has been updated. */
6764
6534
  get updatedAt() {
6765
- return this.getCurrentValue(this.updatedAt$);
6535
+ return getCurrentValue(this.updatedAtSubject);
6766
6536
  }
6767
- /**
6768
- * Will provide the user who created this call.
6769
- */
6537
+ /** Will provide the user who created this call. */
6770
6538
  get createdBy() {
6771
- return this.getCurrentValue(this.createdBy$);
6539
+ return getCurrentValue(this.createdBySubject);
6772
6540
  }
6773
- /**
6774
- * Will provide the custom data of this call.
6775
- */
6541
+ /** Will provide the custom data of this call. */
6776
6542
  get custom() {
6777
- return this.getCurrentValue(this.custom$);
6543
+ return getCurrentValue(this.customSubject);
6778
6544
  }
6779
6545
  /**
6780
6546
  * Will provide the egress data of this call.
6781
6547
  */
6782
6548
  get egress() {
6783
- return this.getCurrentValue(this.egress$);
6549
+ return getCurrentValue(this.egressSubject);
6784
6550
  }
6785
- /**
6786
- * Will provide the ingress data of this call.
6787
- */
6551
+ /** Will provide the ingress data of this call. */
6788
6552
  get ingress() {
6789
- return this.getCurrentValue(this.ingress$);
6553
+ return getCurrentValue(this.ingressSubject);
6790
6554
  }
6791
- /**
6792
- * Will provide the composite recording state of this call.
6793
- */
6555
+ /** Will provide the composite recording state of this call. */
6794
6556
  get recording() {
6795
- return this.getCurrentValue(this.recording$);
6557
+ return getCurrentValue(this.recordingSubject);
6796
6558
  }
6797
- /**
6798
- * Will provide the individual recording state of this call.
6799
- */
6559
+ /** Will provide the individual recording state of this call. */
6800
6560
  get individualRecording() {
6801
- return this.getCurrentValue(this.individualRecording$);
6561
+ return getCurrentValue(this.individualRecordingSubject);
6802
6562
  }
6803
- /**
6804
- * Will provide the raw recording state of this call.
6805
- */
6563
+ /** Will provide the raw recording state of this call. */
6806
6564
  get rawRecording() {
6807
- return this.getCurrentValue(this.rawRecording$);
6565
+ return getCurrentValue(this.rawRecordingSubject);
6808
6566
  }
6809
- /**
6810
- * Will provide the session data of this call.
6811
- */
6567
+ /** Will provide the session data of this call. */
6812
6568
  get session() {
6813
- return this.getCurrentValue(this.session$);
6569
+ return getCurrentValue(this.sessionSubject);
6814
6570
  }
6815
- /**
6816
- * Will provide the settings of this call.
6817
- */
6571
+ /** Will provide the settings of this call. */
6818
6572
  get settings() {
6819
- return this.getCurrentValue(this.settings$);
6573
+ return getCurrentValue(this.settingsSubject);
6820
6574
  }
6821
- /**
6822
- * Will provide the transcribing state of this call.
6823
- */
6575
+ /** Will provide the transcribing state of this call. */
6824
6576
  get transcribing() {
6825
- return this.getCurrentValue(this.transcribing$);
6577
+ return getCurrentValue(this.transcribingSubject);
6826
6578
  }
6827
- /**
6828
- * Whether end-to-end encryption is active for this call.
6829
- */
6579
+ /** Whether end-to-end encryption is active for this call. */
6830
6580
  get e2eeEnabled() {
6831
- return this.getCurrentValue(this.e2eeEnabled$);
6581
+ return getCurrentValue(this.e2eeEnabledSubject);
6832
6582
  }
6833
- /**
6834
- * Will provide the user who ended this call.
6835
- */
6583
+ /** Will provide the user who ended this call. */
6836
6584
  get endedBy() {
6837
- return this.getCurrentValue(this.endedBy$);
6585
+ return getCurrentValue(this.endedBySubject);
6838
6586
  }
6839
6587
  /**
6840
6588
  * Will provide the thumbnails of this call, if enabled in the call settings.
6841
6589
  */
6842
6590
  get thumbnails() {
6843
- return this.getCurrentValue(this.thumbnails$);
6591
+ return getCurrentValue(this.thumbnailsSubject);
6844
6592
  }
6845
- /**
6846
- * Returns the current queue of closed captions.
6847
- */
6593
+ /** Returns the current queue of closed captions. */
6848
6594
  get closedCaptions() {
6849
- return this.getCurrentValue(this.closedCaptions$);
6595
+ return getCurrentValue(this.closedCaptionsSubject);
6850
6596
  }
6851
6597
  /**
6852
6598
  * Will try to find the participant with the given sessionId in the current call.
@@ -6857,9 +6603,7 @@ class CallState {
6857
6603
  findParticipantBySessionId = (sessionId) => {
6858
6604
  return this.participants.find((p) => p.sessionId === sessionId);
6859
6605
  };
6860
- /**
6861
- * Returns a new lookup table of participants indexed by their session ID.
6862
- */
6606
+ /** Returns a new lookup table of participants indexed by their session ID. */
6863
6607
  getParticipantLookupBySessionId = () => {
6864
6608
  return this.participants.reduce((lookupTable, participant) => {
6865
6609
  lookupTable[participant.sessionId] = participant;
@@ -7094,25 +6838,25 @@ class CallState {
7094
6838
  */
7095
6839
  updateFromCallResponse = (call) => {
7096
6840
  this.setBackstage(call.backstage);
7097
- this.setCurrentValue(this.blockedUserIdsSubject, call.blocked_user_ids);
7098
- this.setCurrentValue(this.createdAtSubject, new Date(call.created_at));
7099
- this.setCurrentValue(this.updatedAtSubject, new Date(call.updated_at));
7100
- this.setCurrentValue(this.startsAtSubject, call.starts_at ? new Date(call.starts_at) : undefined);
6841
+ setCurrentValue(this.blockedUserIdsSubject, call.blocked_user_ids);
6842
+ setCurrentValue(this.createdAtSubject, new Date(call.created_at));
6843
+ setCurrentValue(this.updatedAtSubject, new Date(call.updated_at));
6844
+ setCurrentValue(this.startsAtSubject, call.starts_at ? new Date(call.starts_at) : undefined);
7101
6845
  this.setEndedAt(call.ended_at ? new Date(call.ended_at) : undefined);
7102
- this.setCurrentValue(this.createdBySubject, call.created_by);
7103
- this.setCurrentValue(this.customSubject, call.custom);
7104
- this.setCurrentValue(this.egressSubject, call.egress);
7105
- this.setCurrentValue(this.ingressSubject, call.ingress);
6846
+ setCurrentValue(this.createdBySubject, call.created_by);
6847
+ setCurrentValue(this.customSubject, call.custom);
6848
+ setCurrentValue(this.egressSubject, call.egress);
6849
+ setCurrentValue(this.ingressSubject, call.ingress);
7106
6850
  const { individual_recording, composite_recording, raw_recording } = call.egress;
7107
- this.setCurrentValue(this.recordingSubject, call.recording || composite_recording?.status === 'running');
7108
- this.setCurrentValue(this.individualRecordingSubject, individual_recording?.status === 'running');
7109
- this.setCurrentValue(this.rawRecordingSubject, raw_recording?.status === 'running');
7110
- const s = this.setCurrentValue(this.sessionSubject, call.session);
6851
+ setCurrentValue(this.recordingSubject, call.recording || composite_recording?.status === 'running');
6852
+ setCurrentValue(this.individualRecordingSubject, individual_recording?.status === 'running');
6853
+ setCurrentValue(this.rawRecordingSubject, raw_recording?.status === 'running');
6854
+ const s = setCurrentValue(this.sessionSubject, call.session);
7111
6855
  this.updateParticipantCountFromSession(s);
7112
- this.setCurrentValue(this.settingsSubject, call.settings);
7113
- this.setCurrentValue(this.transcribingSubject, call.transcribing);
7114
- this.setCurrentValue(this.captioningSubject, call.captioning);
7115
- this.setCurrentValue(this.thumbnailsSubject, call.thumbnails);
6856
+ setCurrentValue(this.settingsSubject, call.settings);
6857
+ setCurrentValue(this.transcribingSubject, call.transcribing);
6858
+ setCurrentValue(this.captioningSubject, call.captioning);
6859
+ setCurrentValue(this.thumbnailsSubject, call.thumbnails);
7116
6860
  };
7117
6861
  /**
7118
6862
  * Merges a polled ring state into the current session. Only the ring fields
@@ -7123,7 +6867,7 @@ class CallState {
7123
6867
  * @param ringState the ring state as returned by the coordinator.
7124
6868
  */
7125
6869
  updateFromRingState = (ringState) => {
7126
- this.setCurrentValue(this.sessionSubject, (session) => {
6870
+ setCurrentValue(this.sessionSubject, (session) => {
7127
6871
  if (!session || session.id !== ringState.session_id)
7128
6872
  return session;
7129
6873
  return {
@@ -7174,21 +6918,21 @@ class CallState {
7174
6918
  this.setAnonymousParticipantCount(participantCount?.anonymous || 0);
7175
6919
  this.setStartedAt(startedAt ? Timestamp.toDate(startedAt) : new Date());
7176
6920
  this.setServerSidePins(pins);
7177
- this.setCurrentValue(this.e2eeEnabledSubject, e2EeEnabled);
6921
+ setCurrentValue(this.e2eeEnabledSubject, e2EeEnabled);
7178
6922
  };
7179
6923
  updateFromMemberRemoved = (event) => {
7180
6924
  this.updateFromCallResponse(event.call);
7181
- this.setCurrentValue(this.membersSubject, (members) => members.filter((m) => event.members.indexOf(m.user_id) === -1));
6925
+ setCurrentValue(this.membersSubject, (members) => members.filter((m) => event.members.indexOf(m.user_id) === -1));
7182
6926
  };
7183
6927
  updateFromMemberAdded = (event) => {
7184
6928
  this.updateFromCallResponse(event.call);
7185
- this.setCurrentValue(this.membersSubject, (members) => [
6929
+ setCurrentValue(this.membersSubject, (members) => [
7186
6930
  ...members,
7187
6931
  ...event.members,
7188
6932
  ]);
7189
6933
  };
7190
6934
  updateFromHLSBroadcastStopped = () => {
7191
- this.setCurrentValue(this.egressSubject, (egress = defaultEgress) => ({
6935
+ setCurrentValue(this.egressSubject, (egress = defaultEgress) => ({
7192
6936
  ...egress,
7193
6937
  broadcasting: false,
7194
6938
  hls: {
@@ -7198,7 +6942,7 @@ class CallState {
7198
6942
  }));
7199
6943
  };
7200
6944
  updateFromHLSBroadcastingFailed = () => {
7201
- this.setCurrentValue(this.egressSubject, (egress = defaultEgress) => ({
6945
+ setCurrentValue(this.egressSubject, (egress = defaultEgress) => ({
7202
6946
  ...egress,
7203
6947
  broadcasting: false,
7204
6948
  hls: {
@@ -7210,13 +6954,13 @@ class CallState {
7210
6954
  updateFromRecordingEvent = (type, running) => {
7211
6955
  // handle the legacy format, where `type` is absent in the emitted events
7212
6956
  if (type === undefined || type === 'composite') {
7213
- this.setCurrentValue(this.recordingSubject, running);
6957
+ setCurrentValue(this.recordingSubject, running);
7214
6958
  }
7215
6959
  else if (type === 'individual') {
7216
- this.setCurrentValue(this.individualRecordingSubject, running);
6960
+ setCurrentValue(this.individualRecordingSubject, running);
7217
6961
  }
7218
6962
  else if (type === 'raw') {
7219
- this.setCurrentValue(this.rawRecordingSubject, running);
6963
+ setCurrentValue(this.rawRecordingSubject, running);
7220
6964
  }
7221
6965
  else {
7222
6966
  ensureExhausted(type, 'Unknown recording type');
@@ -7233,7 +6977,7 @@ class CallState {
7233
6977
  this.setAnonymousParticipantCount(session.anonymous_participant_count || 0);
7234
6978
  };
7235
6979
  updateFromSessionParticipantCountUpdate = (event) => {
7236
- const s = this.setCurrentValue(this.sessionSubject, (session) => {
6980
+ const s = setCurrentValue(this.sessionSubject, (session) => {
7237
6981
  if (!session)
7238
6982
  return session;
7239
6983
  return {
@@ -7245,7 +6989,7 @@ class CallState {
7245
6989
  this.updateParticipantCountFromSession(s);
7246
6990
  };
7247
6991
  updateFromSessionParticipantLeft = (event) => {
7248
- const s = this.setCurrentValue(this.sessionSubject, (session) => {
6992
+ const s = setCurrentValue(this.sessionSubject, (session) => {
7249
6993
  if (!session)
7250
6994
  return session;
7251
6995
  const { participants, participants_count_by_role } = session;
@@ -7262,7 +7006,7 @@ class CallState {
7262
7006
  this.updateParticipantCountFromSession(s);
7263
7007
  };
7264
7008
  updateFromSessionParticipantJoined = (event) => {
7265
- const s = this.setCurrentValue(this.sessionSubject, (session) => {
7009
+ const s = setCurrentValue(this.sessionSubject, (session) => {
7266
7010
  if (!session)
7267
7011
  return session;
7268
7012
  const { participants, participants_count_by_role } = session;
@@ -7299,7 +7043,7 @@ class CallState {
7299
7043
  };
7300
7044
  updateMembers = (event) => {
7301
7045
  this.updateFromCallResponse(event.call);
7302
- this.setCurrentValue(this.membersSubject, (members) => members.map((member) => {
7046
+ setCurrentValue(this.membersSubject, (members) => members.map((member) => {
7303
7047
  const memberUpdate = event.members.find((m) => m.user_id === member.user_id);
7304
7048
  return memberUpdate ? memberUpdate : member;
7305
7049
  }));
@@ -7324,14 +7068,14 @@ class CallState {
7324
7068
  });
7325
7069
  };
7326
7070
  unblockUser = (event) => {
7327
- this.setCurrentValue(this.blockedUserIdsSubject, (current) => {
7071
+ setCurrentValue(this.blockedUserIdsSubject, (current) => {
7328
7072
  if (!current)
7329
7073
  return current;
7330
7074
  return current.filter((id) => id !== event.user.id);
7331
7075
  });
7332
7076
  };
7333
7077
  blockUser = (event) => {
7334
- this.setCurrentValue(this.blockedUserIdsSubject, (current) => [
7078
+ setCurrentValue(this.blockedUserIdsSubject, (current) => [
7335
7079
  ...(current || []),
7336
7080
  event.user.id,
7337
7081
  ]);
@@ -7342,7 +7086,7 @@ class CallState {
7342
7086
  }
7343
7087
  };
7344
7088
  updateFromClosedCaptions = (event) => {
7345
- this.setCurrentValue(this.closedCaptionsSubject, (queue) => {
7089
+ setCurrentValue(this.closedCaptionsSubject, (queue) => {
7346
7090
  const { closed_caption } = event;
7347
7091
  const keyOf = (c) => `${c.speaker_id}/${c.start_time}`;
7348
7092
  const currentKey = keyOf(closed_caption);
@@ -7354,7 +7098,7 @@ class CallState {
7354
7098
  // schedule the removal of the closed caption after the retention time
7355
7099
  if (visibilityDurationMs > 0) {
7356
7100
  const taskId = setTimeout(() => {
7357
- this.setCurrentValue(this.closedCaptionsSubject, (captions) => captions.filter((caption) => caption !== closed_caption));
7101
+ setCurrentValue(this.closedCaptionsSubject, (captions) => captions.filter((caption) => caption !== closed_caption));
7358
7102
  this.closedCaptionsTasks.delete(currentKey);
7359
7103
  }, visibilityDurationMs);
7360
7104
  this.closedCaptionsTasks.set(currentKey, taskId);
@@ -15576,7 +15320,7 @@ class Call {
15576
15320
  lastStatsOptions;
15577
15321
  ringTimeout;
15578
15322
  ringStatePoller;
15579
- clientStore;
15323
+ clientState;
15580
15324
  streamClient;
15581
15325
  clientEventReporter;
15582
15326
  sfuClient;
@@ -15643,7 +15387,7 @@ class Call {
15643
15387
  * Use the [`StreamVideoClient.call`](./StreamVideoClient.md/#call)
15644
15388
  * method to construct a `Call` instance.
15645
15389
  */
15646
- constructor({ type, id, streamClient, clientEventReporter, members, ownCapabilities, sortParticipantsBy, clientStore, ringing = false, watching = false, }) {
15390
+ constructor({ type, id, streamClient, clientEventReporter, members, ownCapabilities, sortParticipantsBy, clientState, ringing = false, watching = false, }) {
15647
15391
  this.type = type;
15648
15392
  this.id = id;
15649
15393
  this.cid = `${type}:${id}`;
@@ -15651,7 +15395,7 @@ class Call {
15651
15395
  this.watching = watching;
15652
15396
  this.streamClient = streamClient;
15653
15397
  this.clientEventReporter = clientEventReporter;
15654
- this.clientStore = clientStore;
15398
+ this.clientState = clientState;
15655
15399
  this.streamClientBasePath = `/call/${this.type}/${this.id}`;
15656
15400
  this.logger = videoLoggerSystem.getLogger('Call');
15657
15401
  const callTypeConfig = CallTypes.get(type);
@@ -15770,7 +15514,7 @@ class Call {
15770
15514
  };
15771
15515
  handleRingingCall = () => {
15772
15516
  const callSession = this.state.session;
15773
- const receiver_id = this.clientStore.connectedUser?.id;
15517
+ const receiver_id = this.clientState.connectedUser?.id;
15774
15518
  const ended_at = callSession?.ended_at;
15775
15519
  const created_by_id = this.state.createdBy?.id;
15776
15520
  if (this.currentUserId && created_by_id === this.currentUserId) {
@@ -15999,7 +15743,7 @@ class Call {
15999
15743
  this.ringingSubject.next(false);
16000
15744
  this.cancelAutoDrop();
16001
15745
  this.cancelRingStatePolling();
16002
- this.clientStore.unregisterCall(this);
15746
+ this.clientState.unregisterCall(this);
16003
15747
  globalThis.streamRNVideoSDK?.callManager.stop({
16004
15748
  isRingingTypeCall: this.ringing,
16005
15749
  shouldStopCallManager: this.callManagerStarted,
@@ -16058,7 +15802,7 @@ class Call {
16058
15802
  * Retrieves the current user ID.
16059
15803
  */
16060
15804
  get currentUserId() {
16061
- return this.clientStore.connectedUser?.id;
15805
+ return this.clientState.connectedUser?.id;
16062
15806
  }
16063
15807
  /**
16064
15808
  * A flag indicating whether self-subscription is enabled for the call.
@@ -16119,8 +15863,8 @@ class Call {
16119
15863
  this.ringingSubject.next(true);
16120
15864
  // we remove the instance from the calls list to enable the following filter in useCalls hook
16121
15865
  // const calls = useCalls().filter((c) => c.ringing);
16122
- const calls = this.clientStore.calls.filter((c) => c.cid !== this.cid);
16123
- this.clientStore.setCalls([this, ...calls]);
15866
+ const calls = this.clientState.calls.filter((c) => c.cid !== this.cid);
15867
+ this.clientState.setCalls([this, ...calls]);
16124
15868
  await this.applyDeviceConfig(settings, { publish: false });
16125
15869
  };
16126
15870
  /**
@@ -16154,7 +15898,7 @@ class Call {
16154
15898
  }
16155
15899
  if (this.streamClient._hasConnectionID()) {
16156
15900
  this.watching = true;
16157
- this.clientStore.registerOrUpdateCall(this);
15901
+ this.clientState.registerOrUpdateCall(this);
16158
15902
  }
16159
15903
  await this.applyDeviceConfig(response.call.settings, { publish: false });
16160
15904
  return response;
@@ -16173,7 +15917,7 @@ class Call {
16173
15917
  }
16174
15918
  if (this.streamClient._hasConnectionID()) {
16175
15919
  this.watching = true;
16176
- this.clientStore.registerOrUpdateCall(this);
15920
+ this.clientState.registerOrUpdateCall(this);
16177
15921
  }
16178
15922
  await this.applyDeviceConfig(response.call.settings, { publish: false });
16179
15923
  return response;
@@ -16294,7 +16038,7 @@ class Call {
16294
16038
  }
16295
16039
  if (callingX) {
16296
16040
  // for Android/iOS, we need to start the call in the callingx library as soon as possible
16297
- await callingX.joinCall(this, this.clientStore.calls, supersededByLeave);
16041
+ await callingX.joinCall(this, this.clientState.calls, supersededByLeave);
16298
16042
  if (supersededByLeave()) {
16299
16043
  this.logger.debug('Join superseded by leave; not setting up');
16300
16044
  return;
@@ -16824,7 +16568,7 @@ class Call {
16824
16568
  }
16825
16569
  if (this.streamClient._hasConnectionID()) {
16826
16570
  this.watching = true;
16827
- this.clientStore.registerOrUpdateCall(this);
16571
+ this.clientState.registerOrUpdateCall(this);
16828
16572
  }
16829
16573
  return joinResponse;
16830
16574
  };
@@ -17512,7 +17256,7 @@ class Call {
17512
17256
  });
17513
17257
  };
17514
17258
  /**
17515
- * Will enhance the reported stats with additional participant-specific information (`callStatsReport$` state [store variable](./StreamVideoClient.md/#readonlystatestore)).
17259
+ * Will enhance the reported stats with additional participant-specific information (the `callStatsReport$` state variable).
17516
17260
  * This is usually helpful when detailed stats for a specific participant are needed.
17517
17261
  *
17518
17262
  * @param sessionId the sessionId to start reporting for.
@@ -19633,11 +19377,11 @@ class StreamClient {
19633
19377
  return await this.wsConnection.connect(this.defaultWSTimeout);
19634
19378
  };
19635
19379
  getSdkVersion = () => this.options.clientAppIdentifier?.sdkVersion ||
19636
- "1.61.0";
19380
+ "2.0.0-beta.1";
19637
19381
  getUserAgent = () => {
19638
19382
  if (!this.cachedUserAgent) {
19639
19383
  const { clientAppIdentifier = {} } = this.options;
19640
- const { sdkName = 'js', sdkVersion = "1.61.0", ...extras } = clientAppIdentifier;
19384
+ const { sdkName = 'js', sdkVersion = "2.0.0-beta.1", ...extras } = clientAppIdentifier;
19641
19385
  this.cachedUserAgent = [
19642
19386
  `stream-video-${sdkName}-v${sdkVersion}`,
19643
19387
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),
@@ -20393,16 +20137,11 @@ const mapWsJoinError = (err) => {
20393
20137
  */
20394
20138
  class StreamVideoClient {
20395
20139
  /**
20396
- * A reactive store that exposes all the state variables reactively.
20140
+ * The reactive state of this client.
20397
20141
  * You can subscribe to changes of the different state variables.
20398
- * Our library is built in a way that all state changes are exposed in this store,
20399
- * o all UI changes in your application should be handled by subscribing to these variables.
20400
- *
20401
- * @deprecated use the `client.state` getter.
20402
20142
  */
20403
- readOnlyStateStore;
20143
+ state = new ClientState();
20404
20144
  logger;
20405
- writeableStateStore;
20406
20145
  streamClient;
20407
20146
  clientEventReporter;
20408
20147
  effectsRegistered = false;
@@ -20427,8 +20166,6 @@ class StreamVideoClient {
20427
20166
  streamClient: this.streamClient,
20428
20167
  enabled: clientOptions?.clientEventsReportingEnabled ?? true,
20429
20168
  });
20430
- this.writeableStateStore = new StreamVideoWriteableStateStore();
20431
- this.readOnlyStateStore = new StreamVideoReadOnlyStateStore(this.writeableStateStore);
20432
20169
  if (typeof apiKeyOrArgs !== 'string' && apiKeyOrArgs.user) {
20433
20170
  const user = apiKeyOrArgs.user;
20434
20171
  if (user.type === 'anonymous')
@@ -20465,19 +20202,13 @@ class StreamVideoClient {
20465
20202
  }
20466
20203
  StreamVideoClient._instances.set(instanceKey, this);
20467
20204
  };
20468
- /**
20469
- * Return the reactive state store, use this if you want to be notified about changes to the client state
20470
- */
20471
- get state() {
20472
- return this.readOnlyStateStore;
20473
- }
20474
20205
  registerEffects = () => {
20475
20206
  if (this.effectsRegistered)
20476
20207
  return;
20477
20208
  this.eventHandlersToUnregister.push(this.on('call.created', (event) => this.initCallFromEvent(event)), this.on('call.ring', (event) => this.initCallFromEvent(event)), this.on('connection.changed', (event) => {
20478
20209
  if (!event.online)
20479
20210
  return;
20480
- const callsToReWatch = this.writeableStateStore.calls
20211
+ const callsToReWatch = this.state.calls
20481
20212
  .filter((call) => call.watching)
20482
20213
  .map((call) => call.cid);
20483
20214
  if (callsToReWatch.length <= 0)
@@ -20497,7 +20228,7 @@ class StreamVideoClient {
20497
20228
  const concurrencyTag = getCallInitConcurrencyTag(e.call_cid);
20498
20229
  await withoutConcurrency(concurrencyTag, async () => {
20499
20230
  const ringing = e.type === 'call.ring';
20500
- let call = this.writeableStateStore.findCall(e.call.type, e.call.id);
20231
+ let call = this.state.findCall(e.call.type, e.call.id);
20501
20232
  if (call) {
20502
20233
  if (ringing) {
20503
20234
  if (this.shouldRejectCall(call.cid)) {
@@ -20523,7 +20254,7 @@ class StreamVideoClient {
20523
20254
  type: e.call.type,
20524
20255
  id: e.call.id,
20525
20256
  members: e.members,
20526
- clientStore: this.writeableStateStore,
20257
+ clientState: this.state,
20527
20258
  ringing,
20528
20259
  });
20529
20260
  if (ringing) {
@@ -20539,7 +20270,7 @@ class StreamVideoClient {
20539
20270
  }
20540
20271
  else {
20541
20272
  call.state.updateFromCallResponse(e.call);
20542
- this.writeableStateStore.registerCall(call);
20273
+ this.state.registerCall(call);
20543
20274
  this.logger.info(`New call created and registered: ${call.cid}`);
20544
20275
  }
20545
20276
  });
@@ -20570,7 +20301,7 @@ class StreamVideoClient {
20570
20301
  filter_conditions: { cid: { $in: callsToReWatch } },
20571
20302
  });
20572
20303
  for (const c of response.calls) {
20573
- const call = this.writeableStateStore.findCall(c.call.type, c.call.id);
20304
+ const call = this.state.findCall(c.call.type, c.call.id);
20574
20305
  if (call) {
20575
20306
  call.updateFromCallStateResponse(c);
20576
20307
  }
@@ -20591,8 +20322,6 @@ class StreamVideoClient {
20591
20322
  };
20592
20323
  /**
20593
20324
  * Connects the given user to the client.
20594
- * Only one user can connect at a time, if you want to change users, call `disconnectUser` before connecting a new user.
20595
- * If the connection is successful, the connected user [state variable](#readonlystatestore) will be updated accordingly.
20596
20325
  *
20597
20326
  * @param user the user to connect.
20598
20327
  * @param tokenOrProvider a token or a function that returns a token.
@@ -20636,24 +20365,40 @@ class StreamVideoClient {
20636
20365
  });
20637
20366
  // connectUserResponse will be void if connectUser called twice for the same user
20638
20367
  if (connectUserResponse?.me) {
20639
- this.writeableStateStore.setConnectedUser(connectUserResponse.me);
20368
+ this.state.setConnectedUser(connectUserResponse.me);
20640
20369
  }
20641
20370
  this.registerEffects();
20642
20371
  return connectUserResponse;
20643
20372
  };
20373
+ /**
20374
+ * Leaves every call this client still tracks. Runs while the coordinator
20375
+ * connection is alive, so that the leave requests each call sends reach the
20376
+ * backend.
20377
+ */
20378
+ leaveAllCalls = async () => {
20379
+ for (const call of this.state.calls) {
20380
+ if (call.state.callingState === CallingState.LEFT)
20381
+ continue;
20382
+ this.logger.info(`User disconnected, leaving call: ${call.cid}`);
20383
+ await call
20384
+ .leave({ message: 'client.disconnectUser() called' })
20385
+ .catch((err) => {
20386
+ this.logger.error(`Error leaving call: ${call.cid}`, err);
20387
+ });
20388
+ }
20389
+ };
20644
20390
  /**
20645
20391
  * Disconnects the currently connected user from the client.
20646
- *
20647
- * If the connection is successfully disconnected, the connected user [state variable](#readonlystatestore) will be updated accordingly
20392
+ * Leaves every call the user is still in, and updates `client.state`accordingly.
20648
20393
  *
20649
20394
  * @param timeout Max number of ms, to wait for close event of websocket, before forcefully assuming successful disconnection.
20650
- * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
20651
20395
  */
20652
20396
  disconnectUser = async (timeout) => {
20653
20397
  await withoutConcurrency(this.connectionConcurrencyTag, async () => {
20654
20398
  const { user, key } = this.streamClient;
20655
20399
  if (!user)
20656
20400
  return;
20401
+ await this.leaveAllCalls();
20657
20402
  await this.streamClient.disconnectUser(timeout);
20658
20403
  if (user.id) {
20659
20404
  StreamVideoClient._instances.delete(getInstanceKey(key, user));
@@ -20661,13 +20406,15 @@ class StreamVideoClient {
20661
20406
  this.eventHandlersToUnregister.forEach((unregister) => unregister());
20662
20407
  this.eventHandlersToUnregister = [];
20663
20408
  this.effectsRegistered = false;
20664
- this.writeableStateStore.setConnectedUser(undefined);
20409
+ this.state.setConnectedUser(undefined);
20665
20410
  });
20666
20411
  };
20667
20412
  /**
20668
20413
  * You can subscribe to WebSocket events provided by the API.
20669
20414
  * To remove a subscription, call the `off` method or, execute the returned unsubscribe function.
20670
- * Please note that subscribing to WebSocket events is an advanced use-case, for most use-cases it should be enough to watch for changes in the reactive [state store](#readonlystatestore).
20415
+ * Please note that subscribing to WebSocket events is an advanced use-case,
20416
+ * for most use-cases it should be enough to watch for changes in the reactive
20417
+ * `client.state`.
20671
20418
  *
20672
20419
  * @param eventName the event name or 'all'.
20673
20420
  * @param callback the callback which will be called when the event is emitted.
@@ -20694,7 +20441,7 @@ class StreamVideoClient {
20694
20441
  */
20695
20442
  call = (type, id, options = {}) => {
20696
20443
  const call = options.reuseInstance
20697
- ? this.writeableStateStore.findCall(type, id)
20444
+ ? this.state.findCall(type, id)
20698
20445
  : undefined;
20699
20446
  return (call ??
20700
20447
  new Call({
@@ -20702,7 +20449,7 @@ class StreamVideoClient {
20702
20449
  clientEventReporter: this.clientEventReporter,
20703
20450
  id: id,
20704
20451
  type: type,
20705
- clientStore: this.writeableStateStore,
20452
+ clientState: this.state,
20706
20453
  }));
20707
20454
  };
20708
20455
  /**
@@ -20732,7 +20479,7 @@ class StreamVideoClient {
20732
20479
  members: c.members,
20733
20480
  ownCapabilities: c.own_capabilities,
20734
20481
  watching: data.watch,
20735
- clientStore: this.writeableStateStore,
20482
+ clientState: this.state,
20736
20483
  });
20737
20484
  call.state.updateFromCallResponse(c.call);
20738
20485
  await call.applyDeviceConfig(c.call.settings, {
@@ -20741,7 +20488,7 @@ class StreamVideoClient {
20741
20488
  });
20742
20489
  if (data.watch) {
20743
20490
  await call.setup();
20744
- this.writeableStateStore.registerCall(call);
20491
+ this.state.registerCall(call);
20745
20492
  }
20746
20493
  calls.push(call);
20747
20494
  }
@@ -20840,7 +20587,7 @@ class StreamVideoClient {
20840
20587
  clientEventReporter: this.clientEventReporter,
20841
20588
  type: callType,
20842
20589
  id: callId,
20843
- clientStore: this.writeableStateStore,
20590
+ clientState: this.state,
20844
20591
  ringing: true,
20845
20592
  });
20846
20593
  await call.get();
@@ -21404,5 +21151,5 @@ class EncryptionManager extends TypedEventEmitter {
21404
21151
  };
21405
21152
  }
21406
21153
 
21407
- export { AudioSettingsRequestDefaultDeviceEnum, AudioSettingsResponseDefaultDeviceEnum, browsers as Browsers, Call, CallRecordingFailedEventRecordingTypeEnum, CallRecordingReadyEventRecordingTypeEnum, CallRecordingStartedEventRecordingTypeEnum, CallRecordingStoppedEventRecordingTypeEnum, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DEFAULT_LOOPBACK_RECORDING_DURATION_MS, DebounceType, DeviceManager, DeviceManagerState, DynascaleManager, EncryptionManager, EncryptionSettingsRequestModeEnum, EncryptionSettingsResponseModeEnum, ErrorFromResponse, FrameRecordingSettingsRequestModeEnum, FrameRecordingSettingsRequestQualityEnum, FrameRecordingSettingsResponseModeEnum, HLSSettingsRequestQualityTracksEnum, IndividualRecordingSettingsRequestModeEnum, IndividualRecordingSettingsRequestOutputTypesEnum, IndividualRecordingSettingsResponseModeEnum, IngressAudioEncodingOptionsRequestChannelsEnum, IngressSourceRequestFpsEnum, IngressVideoLayerRequestCodecEnum, LOOPBACK_STREAMS_WAIT_TIMEOUT_MS, LayoutSettingsRequestNameEnum, LoopbackStreamsTimeoutError, MAX_LOOPBACK_RECORDING_DURATION_MS, MIN_LOOPBACK_RECORDING_DURATION_MS, MediaStreamRecorder, MicrophoneManager, MicrophoneManagerState, NoiseCancellationSettingsModeEnum, OwnCapability, RTMPBroadcastRequestQualityEnum, RTMPSettingsRequestQualityEnum, RawRecordingSettingsRequestModeEnum, RawRecordingSettingsResponseModeEnum, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, RequestPermissionRequestPermissionsEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, SfuJoinError, models as SfuModels, SfuTimeoutError, SpeakerManager, SpeakerState, StartClosedCaptionsRequestLanguageEnum, StartTranscriptionRequestLanguageEnum, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore, TranscriptionSettingsRequestClosedCaptionModeEnum, TranscriptionSettingsRequestLanguageEnum, TranscriptionSettingsRequestModeEnum, TranscriptionSettingsResponseClosedCaptionModeEnum, TranscriptionSettingsResponseLanguageEnum, TranscriptionSettingsResponseModeEnum, TranslationSettingsLanguagesEnum, TypedEventEmitter, UpdateUserPermissionsRequestGrantPermissionsEnum, UpdateUserPermissionsRequestRevokePermissionsEnum, VideoSettingsRequestCameraFacingEnum, VideoSettingsResponseCameraFacingEnum, ViewportTracker, VisibilityState, WSAuthMessageProductsEnum, checkIfAudioOutputChangeSupported, clampLoopbackRecordingDuration, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, enableLoopbackAudio, getAudioBrowserPermission, getAudioDevices, getAudioOutputDevices, getAudioStream, getCallMediaEngineProvider, getClientDetails, getDeviceState, getLoopbackStreams, getLoopbackTracks, getScreenShareStream, getSdkInfo, getVideoBrowserPermission, getVideoDevices, getVideoStream, getWebRTCInfo, hasAudio$1 as hasAudio, hasInterruptedTrack, hasPausedTrack, hasScreenShare, hasScreenShareAudio, hasVideo, humanize, isPinned, livestreamOrAudioRoomSortPreset, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishing, publishingAudio, publishingVideo, reactionType, resolveDeviceId, role, screenSharing, setCallMediaEngineProvider, setDeviceInfo, setOSInfo, setPowerState, setSdkInfo, setThermalState, setWebRTCInfo, speakerLayoutSortPreset, speaking, videoLoggerSystem, waitForLoopbackStreams, withLoopbackAudioEnabled, withParticipantSource };
21154
+ export { AudioSettingsRequestDefaultDeviceEnum, AudioSettingsResponseDefaultDeviceEnum, browsers as Browsers, Call, CallRecordingFailedEventRecordingTypeEnum, CallRecordingReadyEventRecordingTypeEnum, CallRecordingStartedEventRecordingTypeEnum, CallRecordingStoppedEventRecordingTypeEnum, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, ClientState, CreateDeviceRequestPushProviderEnum, DEFAULT_LOOPBACK_RECORDING_DURATION_MS, DebounceType, DeviceManager, DeviceManagerState, DynascaleManager, EncryptionManager, EncryptionSettingsRequestModeEnum, EncryptionSettingsResponseModeEnum, ErrorFromResponse, FrameRecordingSettingsRequestModeEnum, FrameRecordingSettingsRequestQualityEnum, FrameRecordingSettingsResponseModeEnum, HLSSettingsRequestQualityTracksEnum, IndividualRecordingSettingsRequestModeEnum, IndividualRecordingSettingsRequestOutputTypesEnum, IndividualRecordingSettingsResponseModeEnum, IngressAudioEncodingOptionsRequestChannelsEnum, IngressSourceRequestFpsEnum, IngressVideoLayerRequestCodecEnum, LOOPBACK_STREAMS_WAIT_TIMEOUT_MS, LayoutSettingsRequestNameEnum, LoopbackStreamsTimeoutError, MAX_LOOPBACK_RECORDING_DURATION_MS, MIN_LOOPBACK_RECORDING_DURATION_MS, MediaStreamRecorder, MicrophoneManager, MicrophoneManagerState, NoiseCancellationSettingsModeEnum, OwnCapability, RTMPBroadcastRequestQualityEnum, RTMPSettingsRequestQualityEnum, RawRecordingSettingsRequestModeEnum, RawRecordingSettingsResponseModeEnum, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, RequestPermissionRequestPermissionsEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, SfuJoinError, models as SfuModels, SfuTimeoutError, SpeakerManager, SpeakerState, StartClosedCaptionsRequestLanguageEnum, StartTranscriptionRequestLanguageEnum, StreamSfuClient, StreamVideoClient, TranscriptionSettingsRequestClosedCaptionModeEnum, TranscriptionSettingsRequestLanguageEnum, TranscriptionSettingsRequestModeEnum, TranscriptionSettingsResponseClosedCaptionModeEnum, TranscriptionSettingsResponseLanguageEnum, TranscriptionSettingsResponseModeEnum, TranslationSettingsLanguagesEnum, TypedEventEmitter, UpdateUserPermissionsRequestGrantPermissionsEnum, UpdateUserPermissionsRequestRevokePermissionsEnum, VideoSettingsRequestCameraFacingEnum, VideoSettingsResponseCameraFacingEnum, ViewportTracker, VisibilityState, WSAuthMessageProductsEnum, checkIfAudioOutputChangeSupported, clampLoopbackRecordingDuration, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, enableLoopbackAudio, getAudioBrowserPermission, getAudioDevices, getAudioOutputDevices, getAudioStream, getCallMediaEngineProvider, getClientDetails, getDeviceState, getLoopbackStreams, getLoopbackTracks, getScreenShareStream, getSdkInfo, getVideoBrowserPermission, getVideoDevices, getVideoStream, getWebRTCInfo, hasAudio$1 as hasAudio, hasInterruptedTrack, hasPausedTrack, hasScreenShare, hasScreenShareAudio, hasVideo, humanize, isPinned, livestreamOrAudioRoomSortPreset, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishing, publishingAudio, publishingVideo, reactionType, resolveDeviceId, role, screenSharing, setCallMediaEngineProvider, setDeviceInfo, setOSInfo, setPowerState, setSdkInfo, setThermalState, setWebRTCInfo, speakerLayoutSortPreset, speaking, videoLoggerSystem, waitForLoopbackStreams, withLoopbackAudioEnabled, withParticipantSource };
21408
21155
  //# sourceMappingURL=index.browser.es.js.map