@stream-io/video-client 1.17.1 → 1.18.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.
package/dist/index.cjs.js CHANGED
@@ -7465,7 +7465,7 @@ const aggregate = (stats) => {
7465
7465
  return report;
7466
7466
  };
7467
7467
 
7468
- const version = "1.17.1";
7468
+ const version = "1.18.1";
7469
7469
  const [major, minor, patch] = version.split('.');
7470
7470
  let sdkInfo = {
7471
7471
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -7486,15 +7486,9 @@ const getSdkInfo = () => {
7486
7486
  const setOSInfo = (info) => {
7487
7487
  osInfo = info;
7488
7488
  };
7489
- const getOSInfo = () => {
7490
- return osInfo;
7491
- };
7492
7489
  const setDeviceInfo = (info) => {
7493
7490
  deviceInfo = info;
7494
7491
  };
7495
- const getDeviceInfo = () => {
7496
- return deviceInfo;
7497
- };
7498
7492
  const getWebRTCInfo = () => {
7499
7493
  return webRtcInfo;
7500
7494
  };
@@ -7562,26 +7556,40 @@ const setPowerState = (powerMode) => {
7562
7556
  const getDeviceState = () => {
7563
7557
  return deviceState;
7564
7558
  };
7565
- const getClientDetails = () => {
7559
+ const getClientDetails = async () => {
7566
7560
  if (isReactNative()) {
7567
7561
  // Since RN doesn't support web, sharing browser info is not required
7568
7562
  return {
7569
- sdk: getSdkInfo(),
7570
- os: getOSInfo(),
7571
- device: getDeviceInfo(),
7563
+ sdk: sdkInfo,
7564
+ os: osInfo,
7565
+ device: deviceInfo,
7572
7566
  };
7573
7567
  }
7568
+ // @ts-expect-error - userAgentData is not yet in the TS types
7569
+ const userAgentDataApi = navigator.userAgentData;
7570
+ let userAgentData;
7571
+ if (userAgentDataApi && userAgentDataApi.getHighEntropyValues) {
7572
+ try {
7573
+ userAgentData = await userAgentDataApi.getHighEntropyValues([
7574
+ 'platform',
7575
+ 'platformVersion',
7576
+ ]);
7577
+ }
7578
+ catch (e) {
7579
+ // Ignore the error
7580
+ }
7581
+ }
7574
7582
  const userAgent = new uaParserJs.UAParser(navigator.userAgent);
7575
7583
  const { browser, os, device, cpu } = userAgent.getResult();
7576
7584
  return {
7577
- sdk: getSdkInfo(),
7585
+ sdk: sdkInfo,
7578
7586
  browser: {
7579
7587
  name: browser.name || navigator.userAgent,
7580
7588
  version: browser.version || '',
7581
7589
  },
7582
7590
  os: {
7583
- name: os.name || '',
7584
- version: os.version || '',
7591
+ name: userAgentData?.platform || os.name || '',
7592
+ version: userAgentData?.platformVersion || os.version || '',
7585
7593
  architecture: cpu.architecture || '',
7586
7594
  },
7587
7595
  device: {
@@ -7810,8 +7818,6 @@ const globalOverrideKey = Symbol('globalOverrideKey');
7810
7818
  class DynascaleManager {
7811
7819
  /**
7812
7820
  * Creates a new DynascaleManager instance.
7813
- *
7814
- * @param call the call to manage.
7815
7821
  */
7816
7822
  constructor(callState, speaker) {
7817
7823
  /**
@@ -10449,6 +10455,7 @@ class Call {
10449
10455
  this.leaveCallHooks.forEach((hook) => hook());
10450
10456
  this.initialized = false;
10451
10457
  this.hasJoinedOnce = false;
10458
+ this.ringingSubject.next(false);
10452
10459
  this.clientStore.unregisterCall(this);
10453
10460
  this.camera.dispose();
10454
10461
  this.microphone.dispose();
@@ -10507,7 +10514,7 @@ class Call {
10507
10514
  this.state.updateFromCallResponse(response.call);
10508
10515
  this.state.setMembers(response.members);
10509
10516
  this.state.setOwnCapabilities(response.own_capabilities);
10510
- if (params?.ring || this.ringing) {
10517
+ if (params?.ring) {
10511
10518
  // the call response can indicate where the call is still ringing or not
10512
10519
  this.ringingSubject.next(true);
10513
10520
  }
@@ -10529,7 +10536,7 @@ class Call {
10529
10536
  this.state.updateFromCallResponse(response.call);
10530
10537
  this.state.setMembers(response.members);
10531
10538
  this.state.setOwnCapabilities(response.own_capabilities);
10532
- if (data?.ring || this.ringing) {
10539
+ if (data?.ring) {
10533
10540
  // the call response can indicate where the call is still ringing or not
10534
10541
  this.ringingSubject.next(true);
10535
10542
  }
@@ -10619,8 +10626,13 @@ class Call {
10619
10626
  statsOptions = joinResponse.stats_options;
10620
10627
  }
10621
10628
  catch (error) {
10622
- // restore the previous call state if the join-flow fails
10623
- this.state.setCallingState(callingState);
10629
+ // prevent triggering reconnect flow if the state is OFFLINE
10630
+ const avoidRestoreState = this.state.callingState === exports.CallingState.OFFLINE &&
10631
+ callingState === exports.CallingState.RECONNECTING;
10632
+ if (!avoidRestoreState) {
10633
+ // restore the previous call state if the join-flow fails
10634
+ this.state.setCallingState(callingState);
10635
+ }
10624
10636
  throw error;
10625
10637
  }
10626
10638
  }
@@ -10641,7 +10653,7 @@ class Call {
10641
10653
  : previousSfuClient;
10642
10654
  this.sfuClient = sfuClient;
10643
10655
  this.dynascaleManager.setSfuClient(sfuClient);
10644
- const clientDetails = getClientDetails();
10656
+ const clientDetails = await getClientDetails();
10645
10657
  // we don't need to send JoinRequest if we are re-using an existing healthy SFU client
10646
10658
  if (previousSfuClient !== sfuClient) {
10647
10659
  // prepare a generic SDP and send it to the SFU.
@@ -10900,7 +10912,7 @@ class Call {
10900
10912
  this.state.updateFromCallResponse(joinResponse.call);
10901
10913
  this.state.setMembers(joinResponse.members);
10902
10914
  this.state.setOwnCapabilities(joinResponse.own_capabilities);
10903
- if (data?.ring && !this.ringing) {
10915
+ if (data?.ring) {
10904
10916
  this.ringingSubject.next(true);
10905
10917
  }
10906
10918
  if (this.ringing && !this.isCreatedByMe) {
@@ -11769,7 +11781,7 @@ class Call {
11769
11781
  * @param custom Custom data
11770
11782
  */
11771
11783
  this.submitFeedback = async (rating, { reason, custom, } = {}) => {
11772
- const { sdkName, sdkVersion, ...platform } = getSdkSignature(getClientDetails());
11784
+ const { sdkName, sdkVersion, ...platform } = getSdkSignature(await getClientDetails());
11773
11785
  return this.streamClient.post(`${this.streamClientBasePath}/feedback`, {
11774
11786
  rating,
11775
11787
  reason,
@@ -12453,7 +12465,7 @@ class StableWSConnection {
12453
12465
  }
12454
12466
  }
12455
12467
  catch (err) {
12456
- await this.client._setupConnectionIdPromise();
12468
+ this.client._setupConnectionIdPromise();
12457
12469
  this.isConnecting = false;
12458
12470
  // @ts-ignore
12459
12471
  this._log(`_connect() - Error - `, err);
@@ -12766,8 +12778,7 @@ class StreamClient {
12766
12778
  if (this.userID) {
12767
12779
  throw new Error('Use client.disconnect() before trying to connect as a different user. connectUser was called twice.');
12768
12780
  }
12769
- if ((this._isUsingServerAuth() || this.node) &&
12770
- !this.options.allowServerSideConnect) {
12781
+ if ((this.secret || this.node) && !this.options.allowServerSideConnect) {
12771
12782
  this.logger('warn', 'Please do not use connectUser server side. Use our @stream-io/node-sdk instead: https://getstream.io/video/docs/api/');
12772
12783
  }
12773
12784
  // we generate the client id client side
@@ -12835,7 +12846,7 @@ class StreamClient {
12835
12846
  this.logger('info', 'client:openConnection() - openConnection called twice, healthy connection already exists');
12836
12847
  return;
12837
12848
  }
12838
- await this._setupConnectionIdPromise();
12849
+ this._setupConnectionIdPromise();
12839
12850
  this.clientID = `${this.userID}--${randomId()}`;
12840
12851
  const newWsPromise = this.connect();
12841
12852
  this.wsPromiseSafe = makeSafePromise(newWsPromise);
@@ -12872,7 +12883,7 @@ class StreamClient {
12872
12883
  */
12873
12884
  this.connectAnonymousUser = async (user, tokenOrProvider) => {
12874
12885
  addConnectionEventListeners(this.updateNetworkConnectionStatus);
12875
- await this._setupConnectionIdPromise();
12886
+ this._setupConnectionIdPromise();
12876
12887
  this.anonymous = true;
12877
12888
  await this._setToken(user, tokenOrProvider, this.anonymous);
12878
12889
  this._setUser(user);
@@ -12922,12 +12933,16 @@ class StreamClient {
12922
12933
  }));
12923
12934
  };
12924
12935
  this._logApiRequest = (type, url, data, config) => {
12936
+ if (getLogLevel() !== 'trace')
12937
+ return;
12925
12938
  this.logger('trace', `client: ${type} - Request - ${url}`, {
12926
12939
  payload: data,
12927
12940
  config,
12928
12941
  });
12929
12942
  };
12930
12943
  this._logApiResponse = (type, url, response) => {
12944
+ if (getLogLevel() !== 'trace')
12945
+ return;
12931
12946
  this.logger('trace', `client:${type} - Response - url: ${url} > status ${response.status}`, {
12932
12947
  response,
12933
12948
  });
@@ -13076,17 +13091,17 @@ class StreamClient {
13076
13091
  return await this.wsConnection.connect(this.defaultWSTimeout);
13077
13092
  };
13078
13093
  this.getUserAgent = () => {
13079
- const version = "1.17.1";
13080
- return (this.userAgent ||
13081
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
13082
- };
13083
- this.setUserAgent = (userAgent) => {
13084
- this.userAgent = userAgent;
13094
+ if (!this.cachedUserAgent) {
13095
+ const { clientAppIdentifier = {} } = this.options;
13096
+ const { sdkName = 'js', sdkVersion = "1.18.1", ...extras } = clientAppIdentifier;
13097
+ this.cachedUserAgent = [
13098
+ `stream-video-${sdkName}-v${sdkVersion}`,
13099
+ ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),
13100
+ `client_bundle=${"node-cjs"}`,
13101
+ ].join('|');
13102
+ }
13103
+ return this.cachedUserAgent;
13085
13104
  };
13086
- /**
13087
- * _isUsingServerAuth - Returns true if we're using server side auth
13088
- */
13089
- this._isUsingServerAuth = () => !!this.secret;
13090
13105
  this._enrichAxiosOptions = (options = {
13091
13106
  params: {},
13092
13107
  headers: {},
@@ -13199,24 +13214,32 @@ class StreamClient {
13199
13214
  const getInstanceKey = (apiKey, user) => {
13200
13215
  return `${apiKey}/${user.id}`;
13201
13216
  };
13217
+ /**
13218
+ * Utility function to get the client app identifier.
13219
+ */
13220
+ const getClientAppIdentifier = (options) => {
13221
+ const appId = options?.clientAppIdentifier || {};
13222
+ const sdkInfo = getSdkInfo();
13223
+ if (sdkInfo) {
13224
+ // ensure the sdk name and version are set correctly,
13225
+ // overriding any user-provided values
13226
+ appId.sdkName = SdkType[sdkInfo.type].toLowerCase();
13227
+ appId.sdkVersion = `${sdkInfo.major}.${sdkInfo.minor}.${sdkInfo.patch}`;
13228
+ }
13229
+ return appId;
13230
+ };
13202
13231
  /**
13203
13232
  * Creates a coordinator client.
13204
13233
  */
13205
13234
  const createCoordinatorClient = (apiKey, options) => {
13235
+ const clientAppIdentifier = getClientAppIdentifier(options);
13206
13236
  const coordinatorLogger = getLogger(['coordinator']);
13207
- const streamClient = new StreamClient(apiKey, {
13237
+ return new StreamClient(apiKey, {
13208
13238
  persistUserOnConnectionFailure: true,
13209
13239
  ...options,
13240
+ clientAppIdentifier,
13210
13241
  logger: coordinatorLogger,
13211
13242
  });
13212
- const sdkInfo = getSdkInfo();
13213
- if (sdkInfo) {
13214
- const sdkName = SdkType[sdkInfo.type].toLowerCase();
13215
- const sdkVersion = `${sdkInfo.major}.${sdkInfo.minor}.${sdkInfo.patch}`;
13216
- const userAgent = streamClient.getUserAgent();
13217
- streamClient.setUserAgent(`${userAgent}-video-${sdkName}-sdk-${sdkVersion}`);
13218
- }
13219
- return streamClient;
13220
13243
  };
13221
13244
  /**
13222
13245
  * Creates a token provider and allows integrators to provide
@@ -13646,11 +13669,9 @@ exports.getAudioDevices = getAudioDevices;
13646
13669
  exports.getAudioOutputDevices = getAudioOutputDevices;
13647
13670
  exports.getAudioStream = getAudioStream;
13648
13671
  exports.getClientDetails = getClientDetails;
13649
- exports.getDeviceInfo = getDeviceInfo;
13650
13672
  exports.getDeviceState = getDeviceState;
13651
13673
  exports.getLogLevel = getLogLevel;
13652
13674
  exports.getLogger = getLogger;
13653
- exports.getOSInfo = getOSInfo;
13654
13675
  exports.getScreenShareStream = getScreenShareStream;
13655
13676
  exports.getSdkInfo = getSdkInfo;
13656
13677
  exports.getVideoBrowserPermission = getVideoBrowserPermission;