@stream-io/video-client 1.4.8 → 1.5.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.
package/dist/index.es.js CHANGED
@@ -6536,7 +6536,7 @@ function getIceCandidate(candidate) {
6536
6536
  }
6537
6537
  }
6538
6538
 
6539
- const version = "1.4.8" ;
6539
+ const version = "1.5.0" ;
6540
6540
  const [major, minor, patch] = version.split('.');
6541
6541
  let sdkInfo = {
6542
6542
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -10838,10 +10838,6 @@ class BrowserPermission {
10838
10838
  const signal = this.disposeController.signal;
10839
10839
  this.ready = (async () => {
10840
10840
  const assumeGranted = (error) => {
10841
- this.logger('warn', "Can't query permissions, assuming granted", {
10842
- permission,
10843
- error,
10844
- });
10845
10841
  this.setState('granted');
10846
10842
  };
10847
10843
  if (!canQueryPermissions()) {
@@ -10859,7 +10855,7 @@ class BrowserPermission {
10859
10855
  }
10860
10856
  }
10861
10857
  catch (err) {
10862
- assumeGranted(err);
10858
+ assumeGranted();
10863
10859
  }
10864
10860
  })();
10865
10861
  }
@@ -13390,7 +13386,9 @@ class Call {
13390
13386
  userIdsToMute.push(participant.userId);
13391
13387
  }
13392
13388
  }
13393
- return this.muteUser(userIdsToMute, type);
13389
+ if (userIdsToMute.length > 0) {
13390
+ return this.muteUser(userIdsToMute, type);
13391
+ }
13394
13392
  };
13395
13393
  /**
13396
13394
  * Mutes the user with the given `userId`.
@@ -14620,7 +14618,7 @@ class StableWSConnection {
14620
14618
  const insights = buildWsFatalInsight(this, convertErrorToJson(err));
14621
14619
  postInsights?.('ws_fatal', insights);
14622
14620
  }
14623
- this.client.rejectConnectionId?.();
14621
+ this.client.rejectConnectionId?.(err);
14624
14622
  throw err;
14625
14623
  }
14626
14624
  }
@@ -14878,7 +14876,7 @@ class TokenManager {
14878
14876
  if (this.user && !this.token) {
14879
14877
  return this.token;
14880
14878
  }
14881
- throw new Error(`Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`);
14879
+ throw new Error(`User token is not set. Either client.connectUser wasn't called or client.disconnect was called`);
14882
14880
  };
14883
14881
  this.isStatic = () => this.type === 'static';
14884
14882
  this.loadTokenPromise = null;
@@ -15573,7 +15571,7 @@ class StreamClient {
15573
15571
  });
15574
15572
  };
15575
15573
  this.getUserAgent = () => {
15576
- const version = "1.4.8" ;
15574
+ const version = "1.5.0" ;
15577
15575
  return (this.userAgent ||
15578
15576
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
15579
15577
  };
@@ -15723,12 +15721,16 @@ class StreamVideoClient {
15723
15721
  if (!this.streamClient.user && !this.connectionPromise) {
15724
15722
  return;
15725
15723
  }
15724
+ const userId = this.streamClient.user?.id;
15726
15725
  const disconnectUser = () => this.streamClient.disconnectUser(timeout);
15727
15726
  this.disconnectionPromise = this.connectionPromise
15728
15727
  ? this.connectionPromise.then(() => disconnectUser())
15729
15728
  : disconnectUser();
15730
15729
  this.disconnectionPromise.finally(() => (this.disconnectionPromise = undefined));
15731
15730
  await this.disconnectionPromise;
15731
+ if (userId) {
15732
+ StreamVideoClient._instanceMap.delete(userId);
15733
+ }
15732
15734
  this.eventHandlersToUnregister.forEach((unregister) => unregister());
15733
15735
  this.eventHandlersToUnregister = [];
15734
15736
  this.writeableStateStore.setConnectedUser(undefined);
@@ -15934,12 +15936,44 @@ class StreamVideoClient {
15934
15936
  const user = apiKeyOrArgs.user;
15935
15937
  const token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
15936
15938
  if (user) {
15939
+ let id = user.id;
15940
+ if (user.type === 'anonymous') {
15941
+ id = '!anon';
15942
+ }
15943
+ if (id) {
15944
+ if (StreamVideoClient._instanceMap.has(apiKeyOrArgs.apiKey + id)) {
15945
+ this.logger('warn', `A StreamVideoClient already exists for ${user.type === 'anonymous' ? 'an anyonymous user' : id}; Prefer using getOrCreateInstance method`);
15946
+ }
15947
+ user.id = id;
15948
+ StreamVideoClient._instanceMap.set(apiKeyOrArgs.apiKey + id, this);
15949
+ }
15937
15950
  this.connectUser(user, token).catch((err) => {
15938
15951
  this.logger('error', 'Failed to connect', err);
15939
15952
  });
15940
15953
  }
15941
15954
  }
15942
15955
  }
15956
+ static getOrCreateInstance(args) {
15957
+ const user = args.user;
15958
+ if (!user.id) {
15959
+ if (args.user.type === 'anonymous') {
15960
+ user.id = '!anon';
15961
+ }
15962
+ else {
15963
+ throw new Error('User ID is required for a non-anonymous user');
15964
+ }
15965
+ }
15966
+ if (!args.token && !args.tokenProvider) {
15967
+ if (args.user.type !== 'anonymous' && args.user.type !== 'guest') {
15968
+ throw new Error('TokenProvider or token is required for a user that is not a guest or anonymous');
15969
+ }
15970
+ }
15971
+ let instance = StreamVideoClient._instanceMap.get(args.apiKey + user.id);
15972
+ if (!instance) {
15973
+ instance = new StreamVideoClient({ ...args, user });
15974
+ }
15975
+ return instance;
15976
+ }
15943
15977
  /**
15944
15978
  * Return the reactive state store, use this if you want to be notified about changes to the client state
15945
15979
  */
@@ -16051,6 +16085,7 @@ class StreamVideoClient {
16051
16085
  return await this.addDevice(id, push_provider, push_provider_name, userID, true);
16052
16086
  }
16053
16087
  }
16088
+ StreamVideoClient._instanceMap = new Map();
16054
16089
 
16055
16090
  export { AudioSettingsRequestDefaultDeviceEnum, AudioSettingsResponseDefaultDeviceEnum, BlockListOptionsBehaviorEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, ChannelConfigWithInfoAutomodBehaviorEnum, ChannelConfigWithInfoAutomodEnum, ChannelConfigWithInfoBlocklistBehaviorEnum, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, MicrophoneManager, MicrophoneManagerState, NoiseCancellationSettingsModeEnum, OwnCapability, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, models as SfuModels, SpeakerManager, SpeakerState, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore, TranscriptionSettingsRequestModeEnum, TranscriptionSettingsResponseModeEnum, VideoSettingsRequestCameraFacingEnum, VideoSettingsResponseCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, getAudioBrowserPermission, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceInfo, getLogger, getOSInfo, getScreenShareStream, getSdkInfo, getVideoBrowserPermission, getVideoDevices, getVideoStream, getWebRTCInfo, hasAudio, hasScreenShare, hasScreenShareAudio, hasVideo, isPinned, livestreamOrAudioRoomSortPreset, logLevels, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, setWebRTCInfo, speakerLayoutSortPreset, speaking };
16056
16091
  //# sourceMappingURL=index.es.js.map