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