@stream-io/video-client 1.27.4 → 1.27.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -4301,13 +4301,6 @@ class StreamVideoWriteableStateStore {
4301
4301
  */
4302
4302
  class StreamVideoReadOnlyStateStore {
4303
4303
  constructor(store) {
4304
- /**
4305
- * This method allows you the get the current value of a state variable.
4306
- *
4307
- * @param observable the observable to get the current value of.
4308
- * @returns the current value of the observable.
4309
- */
4310
- this.getCurrentValue = getCurrentValue;
4311
4304
  // convert and expose subjects as observables
4312
4305
  this.connectedUser$ = store.connectedUserSubject.asObservable();
4313
4306
  this.calls$ = store.callsSubject.asObservable();
@@ -5644,7 +5637,7 @@ const getSdkVersion = (sdk) => {
5644
5637
  return sdk ? `${sdk.major}.${sdk.minor}.${sdk.patch}` : '0.0.0-development';
5645
5638
  };
5646
5639
 
5647
- const version = "1.27.4";
5640
+ const version = "1.27.5";
5648
5641
  const [major, minor, patch] = version.split('.');
5649
5642
  let sdkInfo = {
5650
5643
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -14544,7 +14537,7 @@ class StreamClient {
14544
14537
  this.getUserAgent = () => {
14545
14538
  if (!this.cachedUserAgent) {
14546
14539
  const { clientAppIdentifier = {} } = this.options;
14547
- const { sdkName = 'js', sdkVersion = "1.27.4", ...extras } = clientAppIdentifier;
14540
+ const { sdkName = 'js', sdkVersion = "1.27.5", ...extras } = clientAppIdentifier;
14548
14541
  this.cachedUserAgent = [
14549
14542
  `stream-video-${sdkName}-v${sdkVersion}`,
14550
14543
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),
@@ -14665,6 +14658,13 @@ class StreamClient {
14665
14658
  const getInstanceKey = (apiKey, user) => {
14666
14659
  return `${apiKey}/${user.id}`;
14667
14660
  };
14661
+ /**
14662
+ * Returns a concurrency tag for call initialization.
14663
+ * @internal
14664
+ *
14665
+ * @param cid the call cid.
14666
+ */
14667
+ const getCallInitConcurrencyTag = (cid) => `call.init-${cid}`;
14668
14668
  /**
14669
14669
  * Utility function to get the client app identifier.
14670
14670
  */
@@ -14733,7 +14733,7 @@ class StreamVideoClient {
14733
14733
  this.registerEffects = () => {
14734
14734
  if (this.effectsRegistered)
14735
14735
  return;
14736
- this.eventHandlersToUnregister.push(this.on('connection.changed', (event) => {
14736
+ this.eventHandlersToUnregister.push(this.on('call.created', (event) => this.initCallFromEvent(event)), this.on('call.ring', (event) => this.initCallFromEvent(event)), this.on('connection.changed', (event) => {
14737
14737
  if (!event.online)
14738
14738
  return;
14739
14739
  const callsToReWatch = this.writeableStateStore.calls
@@ -14750,50 +14750,52 @@ class StreamVideoClient {
14750
14750
  this.logger('error', 'Failed to re-watch calls', err);
14751
14751
  });
14752
14752
  }));
14753
- this.eventHandlersToUnregister.push(this.on('call.created', (event) => {
14754
- const { call, members } = event;
14755
- if (this.state.connectedUser?.id === call.created_by.id) {
14756
- this.logger('warn', 'Received `call.created` sent by the current user');
14757
- return;
14758
- }
14759
- this.logger('info', `New call created and registered: ${call.cid}`);
14760
- const newCall = new Call({
14761
- streamClient: this.streamClient,
14762
- type: call.type,
14763
- id: call.id,
14764
- members,
14765
- clientStore: this.writeableStateStore,
14766
- });
14767
- newCall.state.updateFromCallResponse(call);
14768
- this.writeableStateStore.registerCall(newCall);
14769
- }));
14770
- this.eventHandlersToUnregister.push(this.on('call.ring', async (event) => {
14771
- const { call, members } = event;
14772
- if (this.state.connectedUser?.id === call.created_by.id) {
14773
- this.logger('debug', 'Received `call.ring` sent by the current user so ignoring the event');
14774
- return;
14775
- }
14776
- // if `call.created` was received before `call.ring`.
14777
- // the client already has the call instance and we just need to update the state
14778
- const theCall = this.writeableStateStore.findCall(call.type, call.id);
14779
- if (theCall) {
14780
- await theCall.updateFromRingingEvent(event);
14781
- }
14782
- else {
14783
- // if client doesn't have the call instance, create the instance and fetch the latest state
14784
- // Note: related - we also have onRingingCall method to handle this case from push notifications
14785
- const newCallInstance = new Call({
14753
+ this.effectsRegistered = true;
14754
+ };
14755
+ /**
14756
+ * Initializes a call from a call created or ringing event.
14757
+ * @param e the event.
14758
+ */
14759
+ this.initCallFromEvent = async (e) => {
14760
+ if (this.state.connectedUser?.id === e.call.created_by.id) {
14761
+ this.logger('debug', `Ignoring ${e.type} event sent by the current user`);
14762
+ return;
14763
+ }
14764
+ try {
14765
+ const concurrencyTag = getCallInitConcurrencyTag(e.call_cid);
14766
+ await withoutConcurrency(concurrencyTag, async () => {
14767
+ const ringing = e.type === 'call.ring';
14768
+ let call = this.writeableStateStore.findCall(e.call.type, e.call.id);
14769
+ if (call) {
14770
+ if (ringing) {
14771
+ await call.updateFromRingingEvent(e);
14772
+ }
14773
+ else {
14774
+ call.state.updateFromCallResponse(e.call);
14775
+ }
14776
+ return;
14777
+ }
14778
+ call = new Call({
14786
14779
  streamClient: this.streamClient,
14787
- type: call.type,
14788
- id: call.id,
14789
- members,
14780
+ type: e.call.type,
14781
+ id: e.call.id,
14782
+ members: e.members,
14790
14783
  clientStore: this.writeableStateStore,
14791
- ringing: true,
14784
+ ringing,
14792
14785
  });
14793
- await newCallInstance.get();
14794
- }
14795
- }));
14796
- this.effectsRegistered = true;
14786
+ call.state.updateFromCallResponse(e.call);
14787
+ if (ringing) {
14788
+ await call.get();
14789
+ }
14790
+ else {
14791
+ this.writeableStateStore.registerCall(call);
14792
+ this.logger('info', `New call created and registered: ${call.cid}`);
14793
+ }
14794
+ });
14795
+ }
14796
+ catch (err) {
14797
+ this.logger('error', `Failed to init call from event ${e.type}`, err);
14798
+ }
14797
14799
  };
14798
14800
  /**
14799
14801
  * Connects the given user to the client.
@@ -14893,6 +14895,7 @@ class StreamVideoClient {
14893
14895
  *
14894
14896
  * @param type the type of the call.
14895
14897
  * @param id the id of the call.
14898
+ * @param options additional options for call creation.
14896
14899
  */
14897
14900
  this.call = (type, id, options = {}) => {
14898
14901
  const call = options.reuseInstance
@@ -15023,22 +15026,24 @@ class StreamVideoClient {
15023
15026
  * @returns
15024
15027
  */
15025
15028
  this.onRingingCall = async (call_cid) => {
15026
- // if we find the call and is already ringing, we don't need to create a new call
15027
- // as client would have received the call.ring state because the app had WS alive when receiving push notifications
15028
- let call = this.state.calls.find((c) => c.cid === call_cid && c.ringing);
15029
- if (!call) {
15030
- // if not it means that WS is not alive when receiving the push notifications and we need to fetch the call
15031
- const [callType, callId] = call_cid.split(':');
15032
- call = new Call({
15033
- streamClient: this.streamClient,
15034
- type: callType,
15035
- id: callId,
15036
- clientStore: this.writeableStateStore,
15037
- ringing: true,
15038
- });
15039
- await call.get();
15040
- }
15041
- return call;
15029
+ return withoutConcurrency(getCallInitConcurrencyTag(call_cid), async () => {
15030
+ // if we find the call and is already ringing, we don't need to create a new call
15031
+ // as client would have received the call.ring state because the app had WS alive when receiving push notifications
15032
+ let call = this.state.calls.find((c) => c.cid === call_cid && c.ringing);
15033
+ if (!call) {
15034
+ // if not it means that WS is not alive when receiving the push notifications and we need to fetch the call
15035
+ const [callType, callId] = call_cid.split(':');
15036
+ call = new Call({
15037
+ streamClient: this.streamClient,
15038
+ type: callType,
15039
+ id: callId,
15040
+ clientStore: this.writeableStateStore,
15041
+ ringing: true,
15042
+ });
15043
+ await call.get();
15044
+ }
15045
+ return call;
15046
+ });
15042
15047
  };
15043
15048
  /**
15044
15049
  * Connects the given anonymous user to the client.