@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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [1.5.0](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.4.8...@stream-io/video-client-1.5.0) (2024-08-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * **client:** add a instance getter ([#1461](https://github.com/GetStream/stream-video-js/issues/1461)) ([7f4d836](https://github.com/GetStream/stream-video-js/commit/7f4d836511d9afdcd61bf5c6317611d3725953a6))
11
+
5
12
  ### [1.4.8](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.4.7...@stream-io/video-client-1.4.8) (2024-07-31)
6
13
 
7
14
 
@@ -6535,7 +6535,7 @@ function getIceCandidate(candidate) {
6535
6535
  }
6536
6536
  }
6537
6537
 
6538
- const version = "1.4.8" ;
6538
+ const version = "1.5.0" ;
6539
6539
  const [major, minor, patch] = version.split('.');
6540
6540
  let sdkInfo = {
6541
6541
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -10837,10 +10837,6 @@ class BrowserPermission {
10837
10837
  const signal = this.disposeController.signal;
10838
10838
  this.ready = (async () => {
10839
10839
  const assumeGranted = (error) => {
10840
- this.logger('warn', "Can't query permissions, assuming granted", {
10841
- permission,
10842
- error,
10843
- });
10844
10840
  this.setState('granted');
10845
10841
  };
10846
10842
  if (!canQueryPermissions()) {
@@ -10858,7 +10854,7 @@ class BrowserPermission {
10858
10854
  }
10859
10855
  }
10860
10856
  catch (err) {
10861
- assumeGranted(err);
10857
+ assumeGranted();
10862
10858
  }
10863
10859
  })();
10864
10860
  }
@@ -13389,7 +13385,9 @@ class Call {
13389
13385
  userIdsToMute.push(participant.userId);
13390
13386
  }
13391
13387
  }
13392
- return this.muteUser(userIdsToMute, type);
13388
+ if (userIdsToMute.length > 0) {
13389
+ return this.muteUser(userIdsToMute, type);
13390
+ }
13393
13391
  };
13394
13392
  /**
13395
13393
  * Mutes the user with the given `userId`.
@@ -14621,7 +14619,7 @@ class StableWSConnection {
14621
14619
  const insights = buildWsFatalInsight(this, convertErrorToJson(err));
14622
14620
  postInsights?.('ws_fatal', insights);
14623
14621
  }
14624
- this.client.rejectConnectionId?.();
14622
+ this.client.rejectConnectionId?.(err);
14625
14623
  throw err;
14626
14624
  }
14627
14625
  }
@@ -14879,7 +14877,7 @@ class TokenManager {
14879
14877
  if (this.user && !this.token) {
14880
14878
  return this.token;
14881
14879
  }
14882
- throw new Error(`Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`);
14880
+ throw new Error(`User token is not set. Either client.connectUser wasn't called or client.disconnect was called`);
14883
14881
  };
14884
14882
  this.isStatic = () => this.type === 'static';
14885
14883
  this.loadTokenPromise = null;
@@ -15574,7 +15572,7 @@ class StreamClient {
15574
15572
  });
15575
15573
  };
15576
15574
  this.getUserAgent = () => {
15577
- const version = "1.4.8" ;
15575
+ const version = "1.5.0" ;
15578
15576
  return (this.userAgent ||
15579
15577
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
15580
15578
  };
@@ -15724,12 +15722,16 @@ class StreamVideoClient {
15724
15722
  if (!this.streamClient.user && !this.connectionPromise) {
15725
15723
  return;
15726
15724
  }
15725
+ const userId = this.streamClient.user?.id;
15727
15726
  const disconnectUser = () => this.streamClient.disconnectUser(timeout);
15728
15727
  this.disconnectionPromise = this.connectionPromise
15729
15728
  ? this.connectionPromise.then(() => disconnectUser())
15730
15729
  : disconnectUser();
15731
15730
  this.disconnectionPromise.finally(() => (this.disconnectionPromise = undefined));
15732
15731
  await this.disconnectionPromise;
15732
+ if (userId) {
15733
+ StreamVideoClient._instanceMap.delete(userId);
15734
+ }
15733
15735
  this.eventHandlersToUnregister.forEach((unregister) => unregister());
15734
15736
  this.eventHandlersToUnregister = [];
15735
15737
  this.writeableStateStore.setConnectedUser(undefined);
@@ -15935,12 +15937,44 @@ class StreamVideoClient {
15935
15937
  const user = apiKeyOrArgs.user;
15936
15938
  const token = apiKeyOrArgs.token || apiKeyOrArgs.tokenProvider;
15937
15939
  if (user) {
15940
+ let id = user.id;
15941
+ if (user.type === 'anonymous') {
15942
+ id = '!anon';
15943
+ }
15944
+ if (id) {
15945
+ if (StreamVideoClient._instanceMap.has(apiKeyOrArgs.apiKey + id)) {
15946
+ this.logger('warn', `A StreamVideoClient already exists for ${user.type === 'anonymous' ? 'an anyonymous user' : id}; Prefer using getOrCreateInstance method`);
15947
+ }
15948
+ user.id = id;
15949
+ StreamVideoClient._instanceMap.set(apiKeyOrArgs.apiKey + id, this);
15950
+ }
15938
15951
  this.connectUser(user, token).catch((err) => {
15939
15952
  this.logger('error', 'Failed to connect', err);
15940
15953
  });
15941
15954
  }
15942
15955
  }
15943
15956
  }
15957
+ static getOrCreateInstance(args) {
15958
+ const user = args.user;
15959
+ if (!user.id) {
15960
+ if (args.user.type === 'anonymous') {
15961
+ user.id = '!anon';
15962
+ }
15963
+ else {
15964
+ throw new Error('User ID is required for a non-anonymous user');
15965
+ }
15966
+ }
15967
+ if (!args.token && !args.tokenProvider) {
15968
+ if (args.user.type !== 'anonymous' && args.user.type !== 'guest') {
15969
+ throw new Error('TokenProvider or token is required for a user that is not a guest or anonymous');
15970
+ }
15971
+ }
15972
+ let instance = StreamVideoClient._instanceMap.get(args.apiKey + user.id);
15973
+ if (!instance) {
15974
+ instance = new StreamVideoClient({ ...args, user });
15975
+ }
15976
+ return instance;
15977
+ }
15944
15978
  /**
15945
15979
  * Return the reactive state store, use this if you want to be notified about changes to the client state
15946
15980
  */
@@ -16052,6 +16086,7 @@ class StreamVideoClient {
16052
16086
  return await this.addDevice(id, push_provider, push_provider_name, userID, true);
16053
16087
  }
16054
16088
  }
16089
+ StreamVideoClient._instanceMap = new Map();
16055
16090
 
16056
16091
  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 };
16057
16092
  //# sourceMappingURL=index.browser.es.js.map