@stream-io/video-client 1.0.3 → 1.0.4

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.0.4](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.0.3...@stream-io/video-client-1.0.4) (2024-05-14)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * don't create publisher PC for anonymous users ([#1353](https://github.com/GetStream/stream-video-js/issues/1353)) ([7331767](https://github.com/GetStream/stream-video-js/commit/7331767bd9254082517b1f36895796032b7af149))
11
+
5
12
  ### [1.0.3](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-client-1.0.2...@stream-io/video-client-1.0.3) (2024-05-13)
6
13
 
7
14
 
@@ -9788,25 +9788,29 @@ const flatten = (report) => {
9788
9788
  };
9789
9789
  const getSdkSignature = (clientDetails) => {
9790
9790
  const { sdk, ...platform } = clientDetails;
9791
- const sdkName = sdk && sdk.type === SdkType.REACT
9792
- ? 'stream-react'
9793
- : sdk && sdk.type === SdkType.REACT_NATIVE
9794
- ? 'stream-react-native'
9795
- : 'stream-js';
9796
- const sdkVersion = sdk
9797
- ? `${sdk.major}.${sdk.minor}.${sdk.patch}`
9798
- : '0.0.0-development';
9791
+ const sdkName = getSdkName(sdk);
9792
+ const sdkVersion = getSdkVersion(sdk);
9799
9793
  return {
9800
9794
  sdkName,
9801
9795
  sdkVersion,
9802
9796
  ...platform,
9803
9797
  };
9804
9798
  };
9799
+ const getSdkName = (sdk) => {
9800
+ return sdk && sdk.type === SdkType.REACT
9801
+ ? 'stream-react'
9802
+ : sdk && sdk.type === SdkType.REACT_NATIVE
9803
+ ? 'stream-react-native'
9804
+ : 'stream-js';
9805
+ };
9806
+ const getSdkVersion = (sdk) => {
9807
+ return sdk ? `${sdk.major}.${sdk.minor}.${sdk.patch}` : '0.0.0-development';
9808
+ };
9805
9809
 
9806
9810
  /**
9807
9811
  * Creates a new StatsReporter instance that collects metrics about the ongoing call and reports them to the state store
9808
9812
  */
9809
- const createStatsReporter = ({ subscriber, publisher, state, pollingIntervalInMs = 2000, }) => {
9813
+ const createStatsReporter = ({ subscriber, publisher, state, datacenter, pollingIntervalInMs = 2000, }) => {
9810
9814
  const logger = getLogger(['stats']);
9811
9815
  const getRawStatsForTrack = async (kind, selector) => {
9812
9816
  if (kind === 'subscriber' && subscriber) {
@@ -9816,12 +9820,13 @@ const createStatsReporter = ({ subscriber, publisher, state, pollingIntervalInMs
9816
9820
  return publisher.getStats(selector);
9817
9821
  }
9818
9822
  else {
9819
- logger('warn', `Can't retrieve RTC stats for ${kind}`);
9820
9823
  return undefined;
9821
9824
  }
9822
9825
  };
9823
9826
  const getStatsForStream = async (kind, mediaStream) => {
9824
9827
  const pc = kind === 'subscriber' ? subscriber : publisher;
9828
+ if (!pc)
9829
+ return [];
9825
9830
  const statsForStream = [];
9826
9831
  for (let track of mediaStream.getTracks()) {
9827
9832
  const report = await pc.getStats(track);
@@ -9867,7 +9872,7 @@ const createStatsReporter = ({ subscriber, publisher, state, pollingIntervalInMs
9867
9872
  });
9868
9873
  }
9869
9874
  catch (e) {
9870
- logger('error', `Failed to collect stats for ${kind} if ${participant.userId}`, e);
9875
+ logger('error', `Failed to collect stats for ${kind} of ${participant.userId}`, e);
9871
9876
  }
9872
9877
  }
9873
9878
  }
@@ -9880,19 +9885,21 @@ const createStatsReporter = ({ subscriber, publisher, state, pollingIntervalInMs
9880
9885
  }))
9881
9886
  .then(aggregate),
9882
9887
  publisher
9883
- .getStats()
9884
- .then((report) => transform(report, {
9885
- kind: 'publisher',
9886
- trackKind: 'video',
9887
- }))
9888
- .then(aggregate),
9888
+ ? publisher
9889
+ .getStats()
9890
+ .then((report) => transform(report, {
9891
+ kind: 'publisher',
9892
+ trackKind: 'video',
9893
+ }))
9894
+ .then(aggregate)
9895
+ : getEmptyStats(),
9889
9896
  ]);
9890
9897
  const [subscriberRawStats, publisherRawStats] = await Promise.all([
9891
9898
  getRawStatsForTrack('subscriber'),
9892
- getRawStatsForTrack('publisher'),
9899
+ publisher ? getRawStatsForTrack('publisher') : undefined,
9893
9900
  ]);
9894
9901
  state.setCallStatsReport({
9895
- datacenter: publisher.sfuClient.edgeName,
9902
+ datacenter,
9896
9903
  publisherStats,
9897
9904
  subscriberStats,
9898
9905
  subscriberRawStats,
@@ -9969,14 +9976,9 @@ const transform = (report, opts) => {
9969
9976
  timestamp: Date.now(),
9970
9977
  };
9971
9978
  };
9972
- /**
9973
- * Aggregates generic stats.
9974
- *
9975
- * @param stats the stats to aggregate.
9976
- */
9977
- const aggregate = (stats) => {
9978
- const aggregatedStats = {
9979
- rawReport: stats,
9979
+ const getEmptyStats = (stats) => {
9980
+ return {
9981
+ rawReport: stats ?? { streams: [], timestamp: Date.now() },
9980
9982
  totalBytesSent: 0,
9981
9983
  totalBytesReceived: 0,
9982
9984
  averageJitterInMs: 0,
@@ -9987,6 +9989,14 @@ const aggregate = (stats) => {
9987
9989
  highestFramesPerSecond: 0,
9988
9990
  timestamp: Date.now(),
9989
9991
  };
9992
+ };
9993
+ /**
9994
+ * Aggregates generic stats.
9995
+ *
9996
+ * @param stats the stats to aggregate.
9997
+ */
9998
+ const aggregate = (stats) => {
9999
+ const aggregatedStats = getEmptyStats(stats);
9990
10000
  let maxArea = -1;
9991
10001
  const area = (w, h) => w * h;
9992
10002
  const qualityLimitationReasons = new Set();
@@ -10030,7 +10040,7 @@ class SfuStatsReporter {
10030
10040
  this.run = async () => {
10031
10041
  const [subscriberStats, publisherStats] = await Promise.all([
10032
10042
  this.subscriber.getStats().then(flatten).then(JSON.stringify),
10033
- this.publisher.getStats().then(flatten).then(JSON.stringify),
10043
+ this.publisher?.getStats().then(flatten).then(JSON.stringify) ?? '[]',
10034
10044
  ]);
10035
10045
  await this.sfuClient.sendStats({
10036
10046
  sdk: this.sdkName,
@@ -10059,15 +10069,8 @@ class SfuStatsReporter {
10059
10069
  this.publisher = publisher;
10060
10070
  const webRTCInfo = getWebRTCInfo();
10061
10071
  const { sdk, browser } = clientDetails;
10062
- this.sdkName =
10063
- sdk && sdk.type === SdkType.REACT
10064
- ? 'stream-react'
10065
- : sdk && sdk.type === SdkType.REACT_NATIVE
10066
- ? 'stream-react-native'
10067
- : 'stream-js';
10068
- this.sdkVersion = sdk
10069
- ? `${sdk.major}.${sdk.minor}.${sdk.patch}`
10070
- : '0.0.0-development';
10072
+ this.sdkName = getSdkName(sdk);
10073
+ this.sdkVersion = getSdkVersion(sdk);
10071
10074
  // The WebRTC version if passed from the SDK, it is taken else the browser info is sent.
10072
10075
  this.webRTCVersion =
10073
10076
  webRTCInfo?.version ||
@@ -12623,7 +12626,10 @@ class Call {
12623
12626
  connectionConfig,
12624
12627
  });
12625
12628
  }
12626
- if (!this.publisher) {
12629
+ // anonymous users can't publish anything hence, there is no need
12630
+ // to create Publisher Peer Connection for them
12631
+ const isAnonymous = this.streamClient.user?.type === 'anonymous';
12632
+ if (!this.publisher && !isAnonymous) {
12627
12633
  const audioSettings = this.state.settings?.audio;
12628
12634
  const isDtxEnabled = !!audioSettings?.opus_dtx_enabled;
12629
12635
  const isRedEnabled = !!audioSettings?.redundant_coding_enabled;
@@ -12641,6 +12647,7 @@ class Call {
12641
12647
  subscriber: this.subscriber,
12642
12648
  publisher: this.publisher,
12643
12649
  state: this.state,
12650
+ datacenter: this.sfuClient.edgeName,
12644
12651
  });
12645
12652
  }
12646
12653
  const clientDetails = getClientDetails();
@@ -12686,15 +12693,18 @@ class Call {
12686
12693
  }
12687
12694
  if (isMigrating) {
12688
12695
  await this.subscriber.migrateTo(sfuClient, connectionConfig);
12689
- await this.publisher.migrateTo(sfuClient, connectionConfig);
12696
+ await this.publisher?.migrateTo(sfuClient, connectionConfig);
12690
12697
  }
12691
12698
  else if (isReconnecting) {
12692
12699
  if (reconnected) {
12693
12700
  // update the SFU client instance on the subscriber and publisher
12694
12701
  this.subscriber.setSfuClient(sfuClient);
12695
- this.publisher.setSfuClient(sfuClient);
12696
- // and perform a full ICE restart on the publisher
12697
- await this.publisher.restartIce();
12702
+ // publisher might not be there (anonymous users)
12703
+ if (this.publisher) {
12704
+ this.publisher.setSfuClient(sfuClient);
12705
+ // and perform a full ICE restart on the publisher
12706
+ await this.publisher.restartIce();
12707
+ }
12698
12708
  }
12699
12709
  else if (previousSfuClient?.isFastReconnecting) {
12700
12710
  // reconnection wasn't possible, so we need to do a full rejoin
@@ -15193,7 +15203,7 @@ class StreamClient {
15193
15203
  });
15194
15204
  };
15195
15205
  this.getUserAgent = () => {
15196
- const version = "1.0.3" ;
15206
+ const version = "1.0.4" ;
15197
15207
  return (this.userAgent ||
15198
15208
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
15199
15209
  };