@stream-io/video-client 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.browser.es.js +325 -421
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +325 -421
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.es.js +325 -421
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/src/Call.d.ts +8 -10
  9. package/dist/src/StreamVideoClient.d.ts +3 -1
  10. package/dist/src/events/call-permissions.d.ts +0 -5
  11. package/dist/src/events/call.d.ts +0 -6
  12. package/dist/src/events/index.d.ts +0 -6
  13. package/dist/src/gen/coordinator/index.d.ts +25 -0
  14. package/dist/src/rtc/Dispatcher.d.ts +2 -2
  15. package/dist/src/rtc/Publisher.d.ts +0 -1
  16. package/dist/src/store/CallState.d.ts +164 -89
  17. package/dist/src/types.d.ts +1 -7
  18. package/dist/version.d.ts +1 -1
  19. package/package.json +1 -1
  20. package/src/Call.ts +37 -44
  21. package/src/StreamVideoClient.ts +14 -17
  22. package/src/events/__tests__/call-permissions.test.ts +1 -61
  23. package/src/events/__tests__/call.test.ts +5 -50
  24. package/src/events/call-permissions.ts +0 -14
  25. package/src/events/call.ts +5 -16
  26. package/src/events/callEventHandlers.ts +2 -57
  27. package/src/events/index.ts +0 -6
  28. package/src/gen/coordinator/index.ts +25 -0
  29. package/src/rtc/Dispatcher.ts +2 -2
  30. package/src/rtc/Publisher.ts +4 -6
  31. package/src/store/CallState.ts +475 -119
  32. package/src/store/__tests__/CallState.test.ts +447 -1
  33. package/src/types.ts +0 -8
  34. package/dist/src/events/__tests__/backstage.test.d.ts +0 -1
  35. package/dist/src/events/__tests__/members.test.d.ts +0 -1
  36. package/dist/src/events/__tests__/recording.test.d.ts +0 -1
  37. package/dist/src/events/__tests__/sessions.test.d.ts +0 -1
  38. package/dist/src/events/backstage.d.ts +0 -6
  39. package/dist/src/events/members.d.ts +0 -18
  40. package/dist/src/events/moderation.d.ts +0 -14
  41. package/dist/src/events/reactions.d.ts +0 -8
  42. package/dist/src/events/recording.d.ts +0 -18
  43. package/dist/src/events/sessions.d.ts +0 -26
  44. package/src/events/__tests__/backstage.test.ts +0 -15
  45. package/src/events/__tests__/members.test.ts +0 -135
  46. package/src/events/__tests__/recording.test.ts +0 -65
  47. package/src/events/__tests__/sessions.test.ts +0 -135
  48. package/src/events/backstage.ts +0 -15
  49. package/src/events/members.ts +0 -62
  50. package/src/events/moderation.ts +0 -35
  51. package/src/events/reactions.ts +0 -30
  52. package/src/events/recording.ts +0 -64
  53. package/src/events/sessions.ts +0 -102
package/dist/index.cjs.js CHANGED
@@ -6543,8 +6543,8 @@ class Publisher {
6543
6543
  track.removeEventListener('ended', handleTrackEnded);
6544
6544
  });
6545
6545
  if (!transceiver) {
6546
- const metadata = this.state.metadata;
6547
- const targetResolution = metadata === null || metadata === void 0 ? void 0 : metadata.settings.video.target_resolution;
6546
+ const { settings } = this.state;
6547
+ const targetResolution = settings === null || settings === void 0 ? void 0 : settings.video.target_resolution;
6548
6548
  const videoEncodings = trackType === TrackType.VIDEO
6549
6549
  ? findOptimalVideoLayers(track, targetResolution)
6550
6550
  : undefined;
@@ -6822,8 +6822,8 @@ class Publisher {
6822
6822
  }
6823
6823
  return String(media.mid);
6824
6824
  };
6825
- const metadata = this.state.metadata;
6826
- const targetResolution = metadata === null || metadata === void 0 ? void 0 : metadata.settings.video.target_resolution;
6825
+ const { settings } = this.state;
6826
+ const targetResolution = settings === null || settings === void 0 ? void 0 : settings.video.target_resolution;
6827
6827
  return this.pc
6828
6828
  .getTransceivers()
6829
6829
  .filter((t) => t.direction === 'sendonly' && t.sender.track)
@@ -6916,7 +6916,6 @@ class Publisher {
6916
6916
  this.pc = this.createPeerConnection(connectionConfig);
6917
6917
  this.sfuClient = sfuClient;
6918
6918
  this.state = state;
6919
- this.dispatcher = dispatcher;
6920
6919
  this.isDtxEnabled = isDtxEnabled;
6921
6920
  this.isRedEnabled = isRedEnabled;
6922
6921
  this.preferredVideoCodec = preferredVideoCodec;
@@ -7544,17 +7543,6 @@ const retryable = (rpc, logger) => __awaiter(void 0, void 0, void 0, function* (
7544
7543
  return rpcCallResult;
7545
7544
  });
7546
7545
 
7547
- /**
7548
- * Watches for `call.live_started` events.
7549
- */
7550
- const watchCallLiveStarted = (state) => {
7551
- return function onCallLiveStarted(event) {
7552
- if (event.type !== 'call.live_started')
7553
- return;
7554
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { backstage: false })));
7555
- };
7556
- };
7557
-
7558
7546
  /**
7559
7547
  * Gets the current value of an observable, or undefined if the observable has
7560
7548
  * not emitted a value yet.
@@ -7997,71 +7985,29 @@ class CallState {
7997
7985
  *
7998
7986
  */
7999
7987
  constructor() {
8000
- /**
8001
- * The raw call metadata object, as defined on the backend.
8002
- *
8003
- * @internal
8004
- */
8005
- this.metadataSubject = new rxjs.BehaviorSubject(undefined);
8006
- /**
8007
- * The list of members of the current call.
8008
- *
8009
- * @internal
8010
- */
7988
+ this.backstageSubject = new rxjs.BehaviorSubject(false);
7989
+ this.blockedUserIdsSubject = new rxjs.BehaviorSubject([]);
7990
+ this.createdAtSubject = new rxjs.BehaviorSubject(new Date());
7991
+ this.endedAtSubject = new rxjs.BehaviorSubject(undefined);
7992
+ this.startsAtSubject = new rxjs.BehaviorSubject(undefined);
7993
+ this.updatedAtSubject = new rxjs.BehaviorSubject(new Date());
7994
+ this.createdBySubject = new rxjs.BehaviorSubject(undefined);
7995
+ this.customSubject = new rxjs.BehaviorSubject({});
7996
+ this.egressSubject = new rxjs.BehaviorSubject(undefined);
7997
+ this.ingressSubject = new rxjs.BehaviorSubject(undefined);
7998
+ this.recordingSubject = new rxjs.BehaviorSubject(false);
7999
+ this.sessionSubject = new rxjs.BehaviorSubject(undefined);
8000
+ this.settingsSubject = new rxjs.BehaviorSubject(undefined);
8001
+ this.transcribingSubject = new rxjs.BehaviorSubject(false);
8002
+ this.endedBySubject = new rxjs.BehaviorSubject(undefined);
8011
8003
  this.membersSubject = new rxjs.BehaviorSubject([]);
8012
- /**
8013
- * The list of capabilities of the current user.
8014
- *
8015
- * @private
8016
- */
8017
8004
  this.ownCapabilitiesSubject = new rxjs.BehaviorSubject([]);
8018
- /**
8019
- * The calling state.
8020
- *
8021
- * @internal
8022
- */
8023
8005
  this.callingStateSubject = new rxjs.BehaviorSubject(exports.CallingState.UNKNOWN);
8024
- /**
8025
- * The time the call session actually started.
8026
- *
8027
- * @internal
8028
- */
8029
8006
  this.startedAtSubject = new rxjs.BehaviorSubject(undefined);
8030
- /**
8031
- * The server-side counted number of participants connected to the current call.
8032
- * This number includes the anonymous participants as well.
8033
- *
8034
- * @internal
8035
- */
8036
8007
  this.participantCountSubject = new rxjs.BehaviorSubject(0);
8037
- /**
8038
- * The server-side counted number of anonymous participants connected to the current call.
8039
- * This number excludes the regular participants.
8040
- *
8041
- * @internal
8042
- */
8043
8008
  this.anonymousParticipantCountSubject = new rxjs.BehaviorSubject(0);
8044
- /**
8045
- * All participants of the current call (including the logged-in user).
8046
- *
8047
- * @internal
8048
- */
8049
8009
  this.participantsSubject = new rxjs.BehaviorSubject([]);
8050
- /**
8051
- * The latest stats report of the current call.
8052
- * When stats gathering is enabled, this observable will emit a new value
8053
- * at a regular (configurable) interval.
8054
- *
8055
- * Consumers of this observable can implement their own batching logic
8056
- * in case they want to show historical stat data.
8057
- *
8058
- * @internal
8059
- */
8060
8010
  this.callStatsReportSubject = new rxjs.BehaviorSubject(undefined);
8061
- /**
8062
- * Emits a list of details about recordings performed for the current call.
8063
- */
8064
- this.callRecordingListSubject = new rxjs.BehaviorSubject([]);
8065
8011
  /**
8066
8012
  * A list of comparators that are used to sort the participants.
8067
8013
  *
@@ -8144,15 +8090,6 @@ class CallState {
8144
8090
  this.setCallingState = (state) => {
8145
8091
  return this.setCurrentValue(this.callingStateSubject, state);
8146
8092
  };
8147
- /**
8148
- * Sets the list of call recordings.
8149
- *
8150
- * @internal
8151
- * @param recordings the list of call recordings.
8152
- */
8153
- this.setCallRecordingsList = (recordings) => {
8154
- return this.setCurrentValue(this.callRecordingListSubject, recordings);
8155
- };
8156
8093
  /**
8157
8094
  * Sets the call stats report.
8158
8095
  *
@@ -8162,16 +8099,6 @@ class CallState {
8162
8099
  this.setCallStatsReport = (report) => {
8163
8100
  return this.setCurrentValue(this.callStatsReportSubject, report);
8164
8101
  };
8165
- /**
8166
- * Sets the metadata of the current call.
8167
- *
8168
- * @internal
8169
- *
8170
- * @param metadata the metadata to set.
8171
- */
8172
- this.setMetadata = (metadata) => {
8173
- return this.setCurrentValue(this.metadataSubject, metadata);
8174
- };
8175
8102
  /**
8176
8103
  * Sets the members of the current call.
8177
8104
  *
@@ -8270,6 +8197,19 @@ class CallState {
8270
8197
  return p;
8271
8198
  }));
8272
8199
  };
8200
+ /**
8201
+ * Updates the call state with the data received from the server.
8202
+ *
8203
+ * @internal
8204
+ *
8205
+ * @param event the video event that our backend sent us.
8206
+ */
8207
+ this.updateFromEvent = (event) => {
8208
+ const update = this.eventHandlers[event.type];
8209
+ if (update) {
8210
+ update(event);
8211
+ }
8212
+ };
8273
8213
  /**
8274
8214
  * Updates the participant pinned state with server side pinning data.
8275
8215
  *
@@ -8298,25 +8238,174 @@ class CallState {
8298
8238
  return participant;
8299
8239
  }));
8300
8240
  };
8301
- this.logger = getLogger(['call-state']);
8241
+ /**
8242
+ * Updates the call state with the data received from the server.
8243
+ *
8244
+ * @internal
8245
+ *
8246
+ * @param call the call response from the server.
8247
+ */
8248
+ this.updateFromCallResponse = (call) => {
8249
+ this.setCurrentValue(this.backstageSubject, call.backstage);
8250
+ this.setCurrentValue(this.blockedUserIdsSubject, call.blocked_user_ids);
8251
+ this.setCurrentValue(this.createdAtSubject, new Date(call.created_at));
8252
+ this.setCurrentValue(this.updatedAtSubject, new Date(call.updated_at));
8253
+ this.setCurrentValue(this.startsAtSubject, call.starts_at ? new Date(call.starts_at) : undefined);
8254
+ this.setCurrentValue(this.endedAtSubject, call.ended_at ? new Date(call.ended_at) : undefined);
8255
+ this.setCurrentValue(this.createdBySubject, call.created_by);
8256
+ this.setCurrentValue(this.customSubject, call.custom);
8257
+ this.setCurrentValue(this.egressSubject, call.egress);
8258
+ this.setCurrentValue(this.ingressSubject, call.ingress);
8259
+ this.setCurrentValue(this.recordingSubject, call.recording);
8260
+ this.setCurrentValue(this.sessionSubject, call.session);
8261
+ this.setCurrentValue(this.settingsSubject, call.settings);
8262
+ this.setCurrentValue(this.transcribingSubject, call.transcribing);
8263
+ };
8264
+ this.updateFromMemberRemoved = (event) => {
8265
+ this.setCurrentValue(this.membersSubject, (members) => members.filter((m) => event.members.indexOf(m.user_id) === -1));
8266
+ };
8267
+ this.updateFromMemberAdded = (event) => {
8268
+ this.setCurrentValue(this.membersSubject, (members) => [
8269
+ ...members,
8270
+ ...event.members,
8271
+ ]);
8272
+ };
8273
+ this.updateFromBroadcastStopped = () => {
8274
+ this.setCurrentValue(this.egressSubject, (egress) => (Object.assign(Object.assign({}, egress), { broadcasting: false })));
8275
+ };
8276
+ this.updateFromBroadcastStarted = (event) => {
8277
+ this.setCurrentValue(this.egressSubject, (egress) => (Object.assign(Object.assign({}, egress), { broadcasting: true, hls: Object.assign(Object.assign({}, egress.hls), { playlist_url: event.hls_playlist_url }) })));
8278
+ };
8279
+ this.updateFromSessionParticipantLeft = (event) => {
8280
+ this.setCurrentValue(this.sessionSubject, (session) => {
8281
+ if (!session) {
8282
+ this.logger('warn', `Received call.session_participant_left event but no session is available.`, event);
8283
+ return session;
8284
+ }
8285
+ const { participants, participants_count_by_role } = session;
8286
+ const { user, user_session_id } = event.participant;
8287
+ return Object.assign(Object.assign({}, session), { participants: participants.filter((p) => p.user_session_id !== user_session_id), participants_count_by_role: Object.assign(Object.assign({}, participants_count_by_role), { [user.role]: Math.max(0, (participants_count_by_role[user.role] || 0) - 1) }) });
8288
+ });
8289
+ };
8290
+ this.updateFromSessionParticipantJoined = (event) => {
8291
+ this.setCurrentValue(this.sessionSubject, (session) => {
8292
+ if (!session) {
8293
+ this.logger('warn', `Received call.session_participant_joined event but no session is available.`, event);
8294
+ return session;
8295
+ }
8296
+ const { participants, participants_count_by_role } = session;
8297
+ const { user } = event.participant;
8298
+ return Object.assign(Object.assign({}, session), { participants: [...participants, event.participant], participants_count_by_role: Object.assign(Object.assign({}, participants_count_by_role), { [user.role]: (participants_count_by_role[user.role] || 0) + 1 }) });
8299
+ });
8300
+ };
8301
+ this.updateMembers = (event) => {
8302
+ this.setCurrentValue(this.membersSubject, (members) => members.map((member) => {
8303
+ const memberUpdate = event.members.find((m) => m.user_id === member.user_id);
8304
+ return memberUpdate ? memberUpdate : member;
8305
+ }));
8306
+ };
8307
+ this.updateParticipantReaction = (event) => {
8308
+ const { user, custom, type, emoji_code } = event.reaction;
8309
+ this.setParticipants((participants) => {
8310
+ return participants.map((p) => {
8311
+ // skip if the reaction is not for this participant
8312
+ if (p.userId !== user.id)
8313
+ return p;
8314
+ // update the participant with the new reaction
8315
+ return Object.assign(Object.assign({}, p), { reaction: {
8316
+ type,
8317
+ emoji_code,
8318
+ custom,
8319
+ } });
8320
+ });
8321
+ });
8322
+ };
8323
+ this.unblockUser = (event) => {
8324
+ this.setCurrentValue(this.blockedUserIdsSubject, (current) => {
8325
+ if (!current)
8326
+ return current;
8327
+ return current.filter((id) => id !== event.user.id);
8328
+ });
8329
+ };
8330
+ this.blockUser = (event) => {
8331
+ this.setCurrentValue(this.blockedUserIdsSubject, (current) => [
8332
+ ...(current || []),
8333
+ event.user.id,
8334
+ ]);
8335
+ };
8336
+ this.updateOwnCapabilities = (event) => {
8337
+ var _a;
8338
+ if (event.user.id === ((_a = this.localParticipant) === null || _a === void 0 ? void 0 : _a.userId)) {
8339
+ this.setCurrentValue(this.ownCapabilitiesSubject, event.own_capabilities);
8340
+ }
8341
+ };
8342
+ this.logger = getLogger(['CallState']);
8302
8343
  this.participants$ = this.participantsSubject.pipe(operators.map((ps) => ps.sort(this.sortParticipantsBy)));
8303
8344
  this.localParticipant$ = this.participants$.pipe(operators.map((participants) => participants.find(isStreamVideoLocalParticipant)));
8304
8345
  this.remoteParticipants$ = this.participants$.pipe(operators.map((participants) => participants.filter((p) => !p.isLocalParticipant)));
8305
8346
  this.pinnedParticipants$ = this.participants$.pipe(operators.map((participants) => participants.filter((p) => !!p.pin)));
8306
8347
  this.dominantSpeaker$ = this.participants$.pipe(operators.map((participants) => participants.find((p) => p.isDominantSpeaker)));
8307
- this.hasOngoingScreenShare$ = this.participants$.pipe(operators.map((participants) => {
8308
- return participants.some((p) => p.publishedTracks.includes(TrackType.SCREEN_SHARE));
8309
- }), operators.distinctUntilChanged());
8348
+ this.hasOngoingScreenShare$ = this.participants$.pipe(operators.map((participants) => participants.some((p) => p.publishedTracks.includes(TrackType.SCREEN_SHARE))), operators.distinctUntilChanged());
8310
8349
  this.startedAt$ = this.startedAtSubject.asObservable();
8311
8350
  this.participantCount$ = this.participantCountSubject.asObservable();
8312
8351
  this.anonymousParticipantCount$ =
8313
8352
  this.anonymousParticipantCountSubject.asObservable();
8314
8353
  this.callStatsReport$ = this.callStatsReportSubject.asObservable();
8315
- this.callRecordingList$ = this.callRecordingListSubject.asObservable();
8316
- this.metadata$ = this.metadataSubject.asObservable();
8317
8354
  this.members$ = this.membersSubject.asObservable();
8318
8355
  this.ownCapabilities$ = this.ownCapabilitiesSubject.asObservable();
8319
8356
  this.callingState$ = this.callingStateSubject.asObservable();
8357
+ this.backstage$ = this.backstageSubject.asObservable();
8358
+ this.blockedUserIds$ = this.blockedUserIdsSubject.asObservable();
8359
+ this.createdAt$ = this.createdAtSubject.asObservable();
8360
+ this.endedAt$ = this.endedAtSubject.asObservable();
8361
+ this.startsAt$ = this.startsAtSubject.asObservable();
8362
+ this.updatedAt$ = this.updatedAtSubject.asObservable();
8363
+ this.createdBy$ = this.createdBySubject.asObservable();
8364
+ this.custom$ = this.customSubject.asObservable();
8365
+ this.egress$ = this.egressSubject.asObservable();
8366
+ this.ingress$ = this.ingressSubject.asObservable();
8367
+ this.recording$ = this.recordingSubject.asObservable();
8368
+ this.session$ = this.sessionSubject.asObservable();
8369
+ this.settings$ = this.settingsSubject.asObservable();
8370
+ this.transcribing$ = this.transcribingSubject.asObservable();
8371
+ this.endedBy$ = this.endedBySubject.asObservable();
8372
+ this.eventHandlers = {
8373
+ // these events are not updating the call state:
8374
+ 'call.permission_request': undefined,
8375
+ 'call.user_muted': undefined,
8376
+ 'connection.error': undefined,
8377
+ 'connection.ok': undefined,
8378
+ 'health.check': undefined,
8379
+ custom: undefined,
8380
+ // events that update call state:
8381
+ 'call.accepted': (e) => this.updateFromCallResponse(e.call),
8382
+ 'call.created': (e) => this.updateFromCallResponse(e.call),
8383
+ 'call.notification': (e) => this.updateFromCallResponse(e.call),
8384
+ 'call.rejected': (e) => this.updateFromCallResponse(e.call),
8385
+ 'call.ring': (e) => this.updateFromCallResponse(e.call),
8386
+ 'call.live_started': (e) => this.updateFromCallResponse(e.call),
8387
+ 'call.updated': (e) => this.updateFromCallResponse(e.call),
8388
+ 'call.session_started': (e) => this.updateFromCallResponse(e.call),
8389
+ 'call.session_ended': (e) => this.updateFromCallResponse(e.call),
8390
+ 'call.ended': (e) => {
8391
+ this.updateFromCallResponse(e.call);
8392
+ this.setCurrentValue(this.endedBySubject, e.user);
8393
+ },
8394
+ 'call.recording_started': () => this.setCurrentValue(this.recordingSubject, true),
8395
+ 'call.recording_stopped': () => this.setCurrentValue(this.recordingSubject, false),
8396
+ 'call.broadcasting_started': this.updateFromBroadcastStarted,
8397
+ 'call.broadcasting_stopped': this.updateFromBroadcastStopped,
8398
+ 'call.session_participant_joined': this.updateFromSessionParticipantJoined,
8399
+ 'call.session_participant_left': this.updateFromSessionParticipantLeft,
8400
+ 'call.blocked_user': this.blockUser,
8401
+ 'call.unblocked_user': this.unblockUser,
8402
+ 'call.permissions_updated': this.updateOwnCapabilities,
8403
+ 'call.member_added': this.updateFromMemberAdded,
8404
+ 'call.member_removed': this.updateFromMemberRemoved,
8405
+ 'call.member_updated': this.updateMembers,
8406
+ 'call.member_updated_permission': this.updateMembers,
8407
+ 'call.reaction_new': this.updateParticipantReaction,
8408
+ };
8320
8409
  }
8321
8410
  /**
8322
8411
  * The server-side counted number of participants connected to the current call.
@@ -8381,24 +8470,12 @@ class CallState {
8381
8470
  get callingState() {
8382
8471
  return this.getCurrentValue(this.callingState$);
8383
8472
  }
8384
- /**
8385
- * The list of call recordings.
8386
- */
8387
- get callRecordingsList() {
8388
- return this.getCurrentValue(this.callRecordingList$);
8389
- }
8390
8473
  /**
8391
8474
  * The call stats report.
8392
8475
  */
8393
8476
  get callStatsReport() {
8394
8477
  return this.getCurrentValue(this.callStatsReport$);
8395
8478
  }
8396
- /**
8397
- * The metadata of the current call.
8398
- */
8399
- get metadata() {
8400
- return this.getCurrentValue(this.metadata$);
8401
- }
8402
8479
  /**
8403
8480
  * The members of the current call.
8404
8481
  */
@@ -8411,6 +8488,96 @@ class CallState {
8411
8488
  get ownCapabilities() {
8412
8489
  return this.getCurrentValue(this.ownCapabilities$);
8413
8490
  }
8491
+ /**
8492
+ * The backstage state.
8493
+ */
8494
+ get backstage() {
8495
+ return this.getCurrentValue(this.backstage$);
8496
+ }
8497
+ /**
8498
+ * Will provide the list of blocked user IDs.
8499
+ */
8500
+ get blockedUserIds() {
8501
+ return this.getCurrentValue(this.blockedUserIds$);
8502
+ }
8503
+ /**
8504
+ * Will provide the time when this call has been created.
8505
+ */
8506
+ get createdAt() {
8507
+ return this.getCurrentValue(this.createdAt$);
8508
+ }
8509
+ /**
8510
+ * Will provide the time when this call has been ended.
8511
+ */
8512
+ get endedAt() {
8513
+ return this.getCurrentValue(this.endedAt$);
8514
+ }
8515
+ /**
8516
+ * Will provide the time when this call has been scheduled to start.
8517
+ */
8518
+ get startsAt() {
8519
+ return this.getCurrentValue(this.startsAt$);
8520
+ }
8521
+ /**
8522
+ * Will provide the time when this call has been updated.
8523
+ */
8524
+ get updatedAt() {
8525
+ return this.getCurrentValue(this.updatedAt$);
8526
+ }
8527
+ /**
8528
+ * Will provide the user who created this call.
8529
+ */
8530
+ get createdBy() {
8531
+ return this.getCurrentValue(this.createdBy$);
8532
+ }
8533
+ /**
8534
+ * Will provide the custom data of this call.
8535
+ */
8536
+ get custom() {
8537
+ return this.getCurrentValue(this.custom$);
8538
+ }
8539
+ /**
8540
+ * Will provide the egress data of this call.
8541
+ */
8542
+ get egress() {
8543
+ return this.getCurrentValue(this.egress$);
8544
+ }
8545
+ /**
8546
+ * Will provide the ingress data of this call.
8547
+ */
8548
+ get ingress() {
8549
+ return this.getCurrentValue(this.ingress$);
8550
+ }
8551
+ /**
8552
+ * Will provide the recording state of this call.
8553
+ */
8554
+ get recording() {
8555
+ return this.getCurrentValue(this.recording$);
8556
+ }
8557
+ /**
8558
+ * Will provide the session data of this call.
8559
+ */
8560
+ get session() {
8561
+ return this.getCurrentValue(this.session$);
8562
+ }
8563
+ /**
8564
+ * Will provide the settings of this call.
8565
+ */
8566
+ get settings() {
8567
+ return this.getCurrentValue(this.settings$);
8568
+ }
8569
+ /**
8570
+ * Will provide the transcribing state of this call.
8571
+ */
8572
+ get transcribing() {
8573
+ return this.getCurrentValue(this.transcribing$);
8574
+ }
8575
+ /**
8576
+ * Will provide the user who ended this call.
8577
+ */
8578
+ get endedBy() {
8579
+ return this.getCurrentValue(this.endedBy$);
8580
+ }
8414
8581
  }
8415
8582
 
8416
8583
  /**
@@ -8482,40 +8649,16 @@ const watchCallEnded = (call) => {
8482
8649
  return __awaiter(this, void 0, void 0, function* () {
8483
8650
  if (event.type !== 'call.ended')
8484
8651
  return;
8485
- if (call.state.callingState === exports.CallingState.RINGING ||
8486
- call.state.callingState === exports.CallingState.JOINED ||
8487
- call.state.callingState === exports.CallingState.JOINING) {
8488
- call.state.setMetadata(event.call);
8652
+ const { callingState } = call.state;
8653
+ if (callingState === exports.CallingState.RINGING ||
8654
+ callingState === exports.CallingState.JOINED ||
8655
+ callingState === exports.CallingState.JOINING) {
8489
8656
  yield call.leave();
8490
8657
  }
8491
8658
  });
8492
8659
  };
8493
8660
  };
8494
- /**
8495
- * An event handler which listens to `call.updated` events
8496
- * and updates the given call state accordingly.
8497
- */
8498
- const watchCallUpdated = (state) => {
8499
- return function onCallUpdated(event) {
8500
- if (event.type !== 'call.updated')
8501
- return;
8502
- state.setMetadata(event.call);
8503
- };
8504
- };
8505
8661
 
8506
- /**
8507
- * Event handler that watches for `call.permissions_updated` events
8508
- */
8509
- const watchCallPermissionsUpdated = (state) => {
8510
- return function onCallPermissionsUpdated(event) {
8511
- if (event.type !== 'call.permissions_updated')
8512
- return;
8513
- const { localParticipant } = state;
8514
- if (event.user.id === (localParticipant === null || localParticipant === void 0 ? void 0 : localParticipant.userId)) {
8515
- state.setOwnCapabilities(event.own_capabilities);
8516
- }
8517
- };
8518
- };
8519
8662
  /**
8520
8663
  * Event handler that watches for `callGrantsUpdated` events.
8521
8664
  *
@@ -8629,57 +8772,6 @@ const watchPinsUpdated = (state) => {
8629
8772
  };
8630
8773
  };
8631
8774
 
8632
- /**
8633
- * Watches for `call.member_added` events.
8634
- */
8635
- const watchCallMemberAdded = (state) => {
8636
- return function onCallMemberAdded(event) {
8637
- if (event.type !== 'call.member_added')
8638
- return;
8639
- state.setMembers((members) => [...members, ...event.members]);
8640
- };
8641
- };
8642
- /**
8643
- * Watches for `call.member_removed` events.
8644
- */
8645
- const watchCallMemberRemoved = (state) => {
8646
- return function onCallMemberRemoved(event) {
8647
- if (event.type !== 'call.member_removed')
8648
- return;
8649
- state.setMembers((members) => members.filter((m) => event.members.indexOf(m.user_id) === -1));
8650
- };
8651
- };
8652
- /**
8653
- * Watches for `call.member_updated_permission` events.
8654
- */
8655
- const watchCallMemberUpdatedPermission = (state) => {
8656
- return function onCallMemberUpdated(event) {
8657
- if (event.type !== 'call.member_updated_permission')
8658
- return;
8659
- state.setMembers((members) => members.map((member) => {
8660
- const memberUpdate = event.members.find((m) => m.user_id === member.user_id);
8661
- if (memberUpdate) {
8662
- member.user.role = memberUpdate.role;
8663
- member = Object.assign({}, member);
8664
- }
8665
- return member;
8666
- }));
8667
- };
8668
- };
8669
- /**
8670
- * Watches for `call.member_updated` events.
8671
- */
8672
- const watchCallMemberUpdated = (state) => {
8673
- return function onCallMemberUpdated(event) {
8674
- if (event.type !== 'call.member_updated')
8675
- return;
8676
- state.setMembers((members) => members.map((member) => {
8677
- const memberUpdate = event.members.find((m) => m.user_id === member.user_id);
8678
- return memberUpdate ? memberUpdate : member;
8679
- }));
8680
- };
8681
- };
8682
-
8683
8775
  /**
8684
8776
  * An event responder which handles the `participantJoined` event.
8685
8777
  */
@@ -8761,74 +8853,6 @@ const watchTrackUnpublished = (state) => {
8761
8853
  };
8762
8854
  const unique = (v, i, arr) => arr.indexOf(v) === i;
8763
8855
 
8764
- /**
8765
- * Watches the delivery of CallReactionEvent.
8766
- *
8767
- * @param state the state store to update.
8768
- */
8769
- const watchNewReactions = (state) => {
8770
- return function onNewReactions(event) {
8771
- if (event.type !== 'call.reaction_new')
8772
- return;
8773
- const { reaction } = event;
8774
- const { user, custom, type, emoji_code } = reaction;
8775
- state.setParticipants((participants) => {
8776
- return participants.map((p) => {
8777
- // skip if the reaction is not for this participant
8778
- if (p.userId !== user.id)
8779
- return p;
8780
- // update the participant with the new reaction
8781
- return Object.assign(Object.assign({}, p), { reaction: {
8782
- type,
8783
- emoji_code,
8784
- custom,
8785
- } });
8786
- });
8787
- });
8788
- };
8789
- };
8790
-
8791
- /**
8792
- * Watches for `call.recording_started` events.
8793
- */
8794
- const watchCallRecordingStarted = (state) => {
8795
- return function onCallRecordingStarted(event) {
8796
- if (event.type !== 'call.recording_started')
8797
- return;
8798
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { recording: true })));
8799
- };
8800
- };
8801
- /**
8802
- * Watches for `call.recording_stopped` events.
8803
- */
8804
- const watchCallRecordingStopped = (state) => {
8805
- return function onCallRecordingStopped(event) {
8806
- if (event.type !== 'call.recording_stopped')
8807
- return;
8808
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { recording: false })));
8809
- };
8810
- };
8811
- /**
8812
- * Watches for `call.broadcasting_started` events.
8813
- */
8814
- const watchCallBroadcastingStarted = (state) => {
8815
- return function onCallBroadcastingStarted(event) {
8816
- if (event.type !== 'call.broadcasting_started')
8817
- return;
8818
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { egress: Object.assign(Object.assign({}, metadata.egress), { broadcasting: true, hls: Object.assign(Object.assign({}, metadata.egress.hls), { playlist_url: event.hls_playlist_url }) }) })));
8819
- };
8820
- };
8821
- /**
8822
- * Watches for `call.broadcasting_stopped` events.
8823
- */
8824
- const watchCallBroadcastingStopped = (state) => {
8825
- return function onCallBroadcastingStopped(event) {
8826
- if (event.type !== 'call.broadcasting_stopped')
8827
- return;
8828
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { egress: Object.assign(Object.assign({}, metadata.egress), { broadcasting: false }) })));
8829
- };
8830
- };
8831
-
8832
8856
  /**
8833
8857
  * Watches for `dominantSpeakerChanged` events.
8834
8858
  */
@@ -8871,98 +8895,6 @@ const watchAudioLevelChanged = (dispatcher, state) => {
8871
8895
  });
8872
8896
  };
8873
8897
 
8874
- /**
8875
- * Watch for call.session_started events and update the call metadata.
8876
- *
8877
- * @param state the call state.
8878
- */
8879
- const watchCallSessionStarted = (state) => {
8880
- return function onCallSessionStarted(event) {
8881
- if (event.type !== 'call.session_started')
8882
- return;
8883
- state.setMetadata(event.call);
8884
- };
8885
- };
8886
- /**
8887
- * Watch for call.session_ended events and update the call metadata.
8888
- *
8889
- * @param state the call state.
8890
- */
8891
- const watchCallSessionEnded = (state) => {
8892
- return function onCallSessionEnded(event) {
8893
- if (event.type !== 'call.session_ended')
8894
- return;
8895
- state.setMetadata(event.call);
8896
- };
8897
- };
8898
- /**
8899
- * Watch for call.session_participant_joined events and update the call metadata.
8900
- *
8901
- * @param state the call state.
8902
- */
8903
- const watchCallSessionParticipantJoined = (state) => {
8904
- return function onCallParticipantJoined(event) {
8905
- if (event.type !== 'call.session_participant_joined')
8906
- return;
8907
- const { participant } = event;
8908
- state.setMetadata((metadata) => {
8909
- if (!metadata || !metadata.session) {
8910
- state.logger('warn', `Received call.session_participant_joined event but the metadata structure is invalid.`, event);
8911
- return metadata;
8912
- }
8913
- const { session } = metadata;
8914
- const { participants, participants_count_by_role } = session;
8915
- const { user } = participant;
8916
- return Object.assign(Object.assign({}, metadata), { session: Object.assign(Object.assign({}, session), { participants: [...participants, participant], participants_count_by_role: Object.assign(Object.assign({}, participants_count_by_role), { [user.role]: (participants_count_by_role[user.role] || 0) + 1 }) }) });
8917
- });
8918
- };
8919
- };
8920
- /**
8921
- * Watch for call.session_participant_left events and update the call metadata.
8922
- *
8923
- * @param state the call state.
8924
- */
8925
- const watchCallSessionParticipantLeft = (state) => {
8926
- return function onCallParticipantLeft(event) {
8927
- if (event.type !== 'call.session_participant_left')
8928
- return;
8929
- const { user, user_session_id } = event.participant;
8930
- state.setMetadata((metadata) => {
8931
- if (!metadata || !metadata.session) {
8932
- state.logger('warn', `Received call.session_participant_left event but the metadata structure is invalid.`, event);
8933
- return metadata;
8934
- }
8935
- const { session } = metadata;
8936
- const { participants, participants_count_by_role } = session;
8937
- return Object.assign(Object.assign({}, metadata), { session: Object.assign(Object.assign({}, session), { participants: participants.filter((p) => p.user_session_id !== user_session_id), participants_count_by_role: Object.assign(Object.assign({}, participants_count_by_role), { [user.role]: Math.max(0, (participants_count_by_role[user.role] || 0) - 1) }) }) });
8938
- });
8939
- };
8940
- };
8941
-
8942
- /**
8943
- * Event handler that watches for `call.blocked_user` events,
8944
- * updates the call store `blocked_user_ids` property by adding
8945
- * `event.user_id` to the list
8946
- */
8947
- const watchBlockedUser = (state) => (event) => {
8948
- if (event.type !== 'call.blocked_user')
8949
- return;
8950
- state.setMetadata((metadata) => (Object.assign(Object.assign({}, metadata), { blocked_user_ids: [...((metadata === null || metadata === void 0 ? void 0 : metadata.blocked_user_ids) || []), event.user.id] })));
8951
- };
8952
- /**
8953
- * Event handler that watches for `call.unblocked_user` events,
8954
- * updates the call store `blocked_user_ids` property by
8955
- * removing `event.user_id` from the list
8956
- */
8957
- const watchUnblockedUser = (state) => (event) => {
8958
- if (event.type !== 'call.unblocked_user')
8959
- return;
8960
- state.setMetadata((metadata) => {
8961
- const blocked_user_ids = ((metadata === null || metadata === void 0 ? void 0 : metadata.blocked_user_ids) || []).filter((userId) => event.user.id !== userId);
8962
- return Object.assign(Object.assign({}, metadata), { blocked_user_ids });
8963
- });
8964
- };
8965
-
8966
8898
  /**
8967
8899
  * Registers the default event handlers for a call during its lifecycle.
8968
8900
  *
@@ -8971,29 +8903,8 @@ const watchUnblockedUser = (state) => (event) => {
8971
8903
  * @param dispatcher the dispatcher.
8972
8904
  */
8973
8905
  const registerEventHandlers = (call, state, dispatcher) => {
8974
- const coordinatorEvents = {
8975
- 'call.blocked_user': watchBlockedUser(state),
8976
- 'call.broadcasting_started': watchCallBroadcastingStarted(state),
8977
- 'call.broadcasting_stopped': watchCallBroadcastingStopped(state),
8978
- 'call.ended': watchCallEnded(call),
8979
- 'call.live_started': watchCallLiveStarted(state),
8980
- 'call.member_added': watchCallMemberAdded(state),
8981
- 'call.member_removed': watchCallMemberRemoved(state),
8982
- 'call.member_updated': watchCallMemberUpdated(state),
8983
- 'call.member_updated_permission': watchCallMemberUpdatedPermission(state),
8984
- 'call.permissions_updated': watchCallPermissionsUpdated(state),
8985
- 'call.reaction_new': watchNewReactions(state),
8986
- 'call.recording_started': watchCallRecordingStarted(state),
8987
- 'call.recording_stopped': watchCallRecordingStopped(state),
8988
- 'call.session_started': watchCallSessionStarted(state),
8989
- 'call.session_ended': watchCallSessionEnded(state),
8990
- 'call.session_participant_joined': watchCallSessionParticipantJoined(state),
8991
- 'call.session_participant_left': watchCallSessionParticipantLeft(state),
8992
- 'call.unblocked_user': watchUnblockedUser(state),
8993
- 'call.updated': watchCallUpdated(state),
8994
- 'call.user_muted': () => console.log('call.user_muted received'),
8995
- };
8996
8906
  const eventHandlers = [
8907
+ call.on('call.ended', watchCallEnded(call)),
8997
8908
  watchLiveEnded(dispatcher, call),
8998
8909
  watchSfuErrorReports(dispatcher),
8999
8910
  watchChangePublishQuality(dispatcher, call),
@@ -9008,10 +8919,6 @@ const registerEventHandlers = (call, state, dispatcher) => {
9008
8919
  call.on('callGrantsUpdated', watchCallGrantsUpdated(state)),
9009
8920
  call.on('pinsUpdated', watchPinsUpdated(state)),
9010
8921
  ];
9011
- Object.keys(coordinatorEvents).forEach((event) => {
9012
- const eventName = event;
9013
- eventHandlers.push(call.on(eventName, coordinatorEvents[eventName]));
9014
- });
9015
8922
  if (call.ringing) {
9016
8923
  // these events are only relevant when the call is ringing
9017
8924
  eventHandlers.push(registerRingingCallEventHandlers(call));
@@ -9641,7 +9548,7 @@ class Call {
9641
9548
  * Use the [`StreamVideoClient.call`](./StreamVideoClient.md/#call)
9642
9549
  * method to construct a `Call` instance.
9643
9550
  */
9644
- constructor({ type, id, streamClient, metadata, members, ownCapabilities, sortParticipantsBy, clientStore, ringing = false, watching = false, }) {
9551
+ constructor({ type, id, streamClient, members, ownCapabilities, sortParticipantsBy, clientStore, ringing = false, watching = false, }) {
9645
9552
  /**
9646
9553
  * ViewportTracker instance
9647
9554
  */
@@ -9720,7 +9627,7 @@ class Call {
9720
9627
  if ((params === null || params === void 0 ? void 0 : params.ring) && !this.ringing) {
9721
9628
  this.ringingSubject.next(true);
9722
9629
  }
9723
- this.state.setMetadata(response.call);
9630
+ this.state.updateFromCallResponse(response.call);
9724
9631
  this.state.setMembers(response.members);
9725
9632
  this.state.setOwnCapabilities(response.own_capabilities);
9726
9633
  if (this.streamClient._hasConnectionID()) {
@@ -9739,7 +9646,7 @@ class Call {
9739
9646
  if ((data === null || data === void 0 ? void 0 : data.ring) && !this.ringing) {
9740
9647
  this.ringingSubject.next(true);
9741
9648
  }
9742
- this.state.setMetadata(response.call);
9649
+ this.state.updateFromCallResponse(response.call);
9743
9650
  this.state.setMembers(response.members);
9744
9651
  this.state.setOwnCapabilities(response.own_capabilities);
9745
9652
  if (this.streamClient._hasConnectionID()) {
@@ -9820,7 +9727,7 @@ class Call {
9820
9727
  let connectionConfig;
9821
9728
  try {
9822
9729
  const call = yield join(this.streamClient, this.type, this.id, data);
9823
- this.state.setMetadata(call.metadata);
9730
+ this.state.updateFromCallResponse(call.metadata);
9824
9731
  this.state.setMembers(call.members);
9825
9732
  this.state.setOwnCapabilities(call.ownCapabilities);
9826
9733
  connectionConfig = call.connectionConfig;
@@ -9985,7 +9892,7 @@ class Call {
9985
9892
  connectionConfig,
9986
9893
  });
9987
9894
  }
9988
- const audioSettings = (_f = this.data) === null || _f === void 0 ? void 0 : _f.settings.audio;
9895
+ const audioSettings = (_f = this.state.settings) === null || _f === void 0 ? void 0 : _f.audio;
9989
9896
  const isDtxEnabled = !!(audioSettings === null || audioSettings === void 0 ? void 0 : audioSettings.opus_dtx_enabled);
9990
9897
  const isRedEnabled = !!(audioSettings === null || audioSettings === void 0 ? void 0 : audioSettings.redundant_coding_enabled);
9991
9898
  if (!this.publisher) {
@@ -10499,9 +10406,12 @@ class Call {
10499
10406
  });
10500
10407
  /**
10501
10408
  * Starts the livestreaming of the call.
10409
+ *
10410
+ * @param data the request data.
10411
+ * @param params the request params.
10502
10412
  */
10503
- this.goLive = (params) => __awaiter(this, void 0, void 0, function* () {
10504
- return this.streamClient.post(`${this.streamClientBasePath}/go_live`, {}, params);
10413
+ this.goLive = (data = {}, params) => __awaiter(this, void 0, void 0, function* () {
10414
+ return this.streamClient.post(`${this.streamClientBasePath}/go_live`, data, params);
10505
10415
  });
10506
10416
  /**
10507
10417
  * Stops the livestreaming of the call.
@@ -10529,7 +10439,7 @@ class Call {
10529
10439
  this.update = (updates) => __awaiter(this, void 0, void 0, function* () {
10530
10440
  const response = yield this.streamClient.patch(`${this.streamClientBasePath}`, updates);
10531
10441
  const { call, members, own_capabilities } = response;
10532
- this.state.setMetadata(call);
10442
+ this.state.updateFromCallResponse(call);
10533
10443
  this.state.setMembers(members);
10534
10444
  this.state.setOwnCapabilities(own_capabilities);
10535
10445
  return response;
@@ -10602,19 +10512,20 @@ class Call {
10602
10512
  this.scheduleAutoDrop = () => {
10603
10513
  if (this.dropTimeout)
10604
10514
  clearTimeout(this.dropTimeout);
10605
- const subscription = this.state.metadata$
10606
- .pipe(rxjs.pairwise(), rxjs.tap(([prevMeta, currentMeta]) => {
10607
- if (!(currentMeta && this.clientStore.connectedUser))
10515
+ const subscription = this.state.settings$
10516
+ .pipe(rxjs.pairwise(), rxjs.tap(([prevSettings, currentSettings]) => {
10517
+ var _a;
10518
+ if (!currentSettings || !this.clientStore.connectedUser)
10608
10519
  return;
10609
- const isOutgoingCall = this.currentUserId === currentMeta.created_by.id;
10520
+ const isOutgoingCall = this.currentUserId === ((_a = this.state.createdBy) === null || _a === void 0 ? void 0 : _a.id);
10610
10521
  const [prevTimeoutMs, timeoutMs] = isOutgoingCall
10611
10522
  ? [
10612
- prevMeta === null || prevMeta === void 0 ? void 0 : prevMeta.settings.ring.auto_cancel_timeout_ms,
10613
- currentMeta.settings.ring.auto_cancel_timeout_ms,
10523
+ prevSettings === null || prevSettings === void 0 ? void 0 : prevSettings.ring.auto_cancel_timeout_ms,
10524
+ currentSettings.ring.auto_cancel_timeout_ms,
10614
10525
  ]
10615
10526
  : [
10616
- prevMeta === null || prevMeta === void 0 ? void 0 : prevMeta.settings.ring.incoming_call_timeout_ms,
10617
- currentMeta.settings.ring.incoming_call_timeout_ms,
10527
+ prevSettings === null || prevSettings === void 0 ? void 0 : prevSettings.ring.incoming_call_timeout_ms,
10528
+ currentSettings.ring.incoming_call_timeout_ms,
10618
10529
  ];
10619
10530
  if (typeof timeoutMs === 'undefined' ||
10620
10531
  timeoutMs === prevTimeoutMs ||
@@ -10631,7 +10542,6 @@ class Call {
10631
10542
  };
10632
10543
  /**
10633
10544
  * Retrieves the list of recordings for the current call or call session.
10634
- * Updates the call state with the returned array of CallRecording objects.
10635
10545
  *
10636
10546
  * If `callSessionId` is provided, it will return the recordings for that call session.
10637
10547
  * Otherwise, all recordings for the current call will be returned.
@@ -10643,9 +10553,7 @@ class Call {
10643
10553
  if (callSessionId) {
10644
10554
  endpoint = `${endpoint}/${callSessionId}`;
10645
10555
  }
10646
- const response = yield this.streamClient.get(`${endpoint}/recordings`);
10647
- this.state.setCallRecordingsList(response.recordings);
10648
- return response;
10556
+ return this.streamClient.get(`${endpoint}/recordings`);
10649
10557
  });
10650
10558
  /**
10651
10559
  * Sends a custom event to all call participants.
@@ -10669,21 +10577,24 @@ class Call {
10669
10577
  if (participantSorter) {
10670
10578
  this.state.setSortParticipantsBy(participantSorter);
10671
10579
  }
10672
- this.state.setMetadata(metadata);
10673
10580
  this.state.setMembers(members || []);
10674
10581
  this.state.setOwnCapabilities(ownCapabilities || []);
10675
10582
  this.state.setCallingState(ringing ? exports.CallingState.RINGING : exports.CallingState.IDLE);
10583
+ this.on('all', (event) => {
10584
+ // update state with the latest event data
10585
+ this.state.updateFromEvent(event);
10586
+ });
10676
10587
  this.leaveCallHooks.push(registerEventHandlers(this, this.state, this.dispatcher));
10677
10588
  this.registerEffects();
10678
10589
  this.leaveCallHooks.push(createSubscription(this.trackSubscriptionsSubject.pipe(rxjs.debounce((v) => rxjs.timer(v.type)), rxjs.map((v) => v.data)), (subscriptions) => { var _a; return (_a = this.sfuClient) === null || _a === void 0 ? void 0 : _a.updateSubscriptions(subscriptions); }));
10679
10590
  }
10680
10591
  registerEffects() {
10681
10592
  this.leaveCallHooks.push(
10682
- // handles updating the permissions context when the metadata changes.
10683
- createSubscription(this.state.metadata$, (metadata) => {
10684
- if (!metadata)
10593
+ // handles updating the permissions context when the settings change.
10594
+ createSubscription(this.state.settings$, (settings) => {
10595
+ if (!settings)
10685
10596
  return;
10686
- this.permissionsContext.setCallSettings(metadata.settings);
10597
+ this.permissionsContext.setCallSettings(settings);
10687
10598
  }),
10688
10599
  // handle the case when the user permissions are modified.
10689
10600
  createSubscription(this.state.ownCapabilities$, (ownCapabilities) => {
@@ -10707,12 +10618,11 @@ class Call {
10707
10618
  }
10708
10619
  }),
10709
10620
  // handles the case when the user is blocked by the call owner.
10710
- createSubscription(this.state.metadata$, (metadata) => __awaiter(this, void 0, void 0, function* () {
10711
- if (!metadata)
10621
+ createSubscription(this.state.blockedUserIds$, (blockedUserIds) => __awaiter(this, void 0, void 0, function* () {
10622
+ if (!blockedUserIds)
10712
10623
  return;
10713
10624
  const currentUserId = this.currentUserId;
10714
- if (currentUserId &&
10715
- metadata.blocked_user_ids.includes(currentUserId)) {
10625
+ if (currentUserId && blockedUserIds.includes(currentUserId)) {
10716
10626
  this.logger('info', 'Leaving call because of being blocked');
10717
10627
  yield this.leave();
10718
10628
  }
@@ -10764,12 +10674,6 @@ class Call {
10764
10674
  }
10765
10675
  }
10766
10676
  }
10767
- /**
10768
- * A getter for the call metadata.
10769
- */
10770
- get data() {
10771
- return this.state.metadata;
10772
- }
10773
10677
  /**
10774
10678
  * A flag indicating whether the call is "ringing" type of call.
10775
10679
  */
@@ -10788,7 +10692,7 @@ class Call {
10788
10692
  */
10789
10693
  get isCreatedByMe() {
10790
10694
  var _a;
10791
- return ((_a = this.state.metadata) === null || _a === void 0 ? void 0 : _a.created_by.id) === this.currentUserId;
10695
+ return ((_a = this.state.createdBy) === null || _a === void 0 ? void 0 : _a.id) === this.currentUserId;
10792
10696
  }
10793
10697
  }
10794
10698
 
@@ -11901,7 +11805,7 @@ class WSConnectionFallback {
11901
11805
  }
11902
11806
  }
11903
11807
 
11904
- const version = '0.2.2';
11808
+ const version = '0.3.0';
11905
11809
 
11906
11810
  const logger = getLogger(['location']);
11907
11811
  const HINT_URL = `https://hint.stream-io-video.com/`;
@@ -12595,12 +12499,12 @@ class StreamVideoClient {
12595
12499
  streamClient: this.streamClient,
12596
12500
  id: c.call.id,
12597
12501
  type: c.call.type,
12598
- metadata: c.call,
12599
12502
  members: c.members,
12600
12503
  ownCapabilities: c.own_capabilities,
12601
12504
  watching: data.watch,
12602
12505
  clientStore: this.writeableStateStore,
12603
12506
  });
12507
+ call.state.updateFromCallResponse(c.call);
12604
12508
  if (data.watch) {
12605
12509
  this.writeableStateStore.registerCall(call);
12606
12510
  }
@@ -12608,9 +12512,9 @@ class StreamVideoClient {
12608
12512
  });
12609
12513
  return Object.assign(Object.assign({}, response), { calls: calls });
12610
12514
  });
12611
- this.queryUsers = () => __awaiter(this, void 0, void 0, function* () {
12612
- console.log('Querying users is not implemented yet.');
12613
- });
12515
+ /**
12516
+ * Returns a list of available data centers available for hosting calls.
12517
+ */
12614
12518
  this.edges = () => __awaiter(this, void 0, void 0, function* () {
12615
12519
  return this.streamClient.get(`/edges`);
12616
12520
  });
@@ -12785,14 +12689,15 @@ class StreamVideoClient {
12785
12689
  return;
12786
12690
  }
12787
12691
  this.logger('info', `New call created and registered: ${call.cid}`);
12788
- this.writeableStateStore.registerCall(new Call({
12692
+ const newCall = new Call({
12789
12693
  streamClient: this.streamClient,
12790
12694
  type: call.type,
12791
12695
  id: call.id,
12792
- metadata: call,
12793
12696
  members,
12794
12697
  clientStore: this.writeableStateStore,
12795
- }));
12698
+ });
12699
+ newCall.state.updateFromCallResponse(call);
12700
+ this.writeableStateStore.registerCall(newCall);
12796
12701
  }));
12797
12702
  this.eventHandlersToUnregister.push(this.on('call.ring', (event) => __awaiter(this, void 0, void 0, function* () {
12798
12703
  if (event.type !== 'call.ring')
@@ -12806,7 +12711,6 @@ class StreamVideoClient {
12806
12711
  // if `call.created` was received before `call.ring`.
12807
12712
  // In that case, we cleanup the already tracked call.
12808
12713
  const prevCall = this.writeableStateStore.findCall(call.type, call.id);
12809
- const prevMetadata = prevCall === null || prevCall === void 0 ? void 0 : prevCall.state.metadata;
12810
12714
  yield (prevCall === null || prevCall === void 0 ? void 0 : prevCall.leave());
12811
12715
  // we create a new call
12812
12716
  const theCall = new Call({
@@ -12816,8 +12720,8 @@ class StreamVideoClient {
12816
12720
  members,
12817
12721
  clientStore: this.writeableStateStore,
12818
12722
  ringing: true,
12819
- metadata: prevMetadata,
12820
12723
  });
12724
+ theCall.state.updateFromCallResponse(call);
12821
12725
  // we fetch the latest metadata for the call from the server
12822
12726
  yield theCall.get();
12823
12727
  this.writeableStateStore.registerCall(theCall);