@stream-io/video-client 1.7.1 → 1.7.2

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
@@ -3034,7 +3034,7 @@ const retryable = async (rpc, signal) => {
3034
3034
  return result;
3035
3035
  };
3036
3036
 
3037
- const version = "1.7.1";
3037
+ const version = "1.7.2";
3038
3038
  const [major, minor, patch] = version.split('.');
3039
3039
  let sdkInfo = {
3040
3040
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -3311,14 +3311,16 @@ const defaultBitratePerRid = {
3311
3311
  *
3312
3312
  * @param videoTrack the video track to find optimal layers for.
3313
3313
  * @param targetResolution the expected target resolution.
3314
- * @param preferredBitrate the preferred bitrate for the video track.
3314
+ * @param publishOptions the publish options for the track.
3315
3315
  */
3316
- const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetResolution, preferredBitrate) => {
3316
+ const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetResolution, publishOptions) => {
3317
3317
  const optimalVideoLayers = [];
3318
3318
  const settings = videoTrack.getSettings();
3319
3319
  const { width: w = 0, height: h = 0 } = settings;
3320
+ const { preferredBitrate, bitrateDownscaleFactor = 2 } = publishOptions || {};
3320
3321
  const maxBitrate = getComputedMaxBitrate(targetResolution, w, h, preferredBitrate);
3321
3322
  let downscaleFactor = 1;
3323
+ let bitrateFactor = 1;
3322
3324
  ['f', 'h', 'q'].forEach((rid) => {
3323
3325
  // Reversing the order [f, h, q] to [q, h, f] as Chrome uses encoding index
3324
3326
  // when deciding which layer to disable when CPU or bandwidth is constrained.
@@ -3328,11 +3330,12 @@ const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetReso
3328
3330
  rid,
3329
3331
  width: Math.round(w / downscaleFactor),
3330
3332
  height: Math.round(h / downscaleFactor),
3331
- maxBitrate: Math.round(maxBitrate / downscaleFactor) || defaultBitratePerRid[rid],
3333
+ maxBitrate: Math.round(maxBitrate / bitrateFactor) || defaultBitratePerRid[rid],
3332
3334
  scaleResolutionDownBy: downscaleFactor,
3333
3335
  maxFramerate: 30,
3334
3336
  });
3335
3337
  downscaleFactor *= 2;
3338
+ bitrateFactor *= bitrateDownscaleFactor;
3336
3339
  });
3337
3340
  // for simplicity, we start with all layers enabled, then this function
3338
3341
  // will clear/reassign the layers that are not needed
@@ -3392,7 +3395,8 @@ const withSimulcastConstraints = (settings, optimalVideoLayers) => {
3392
3395
  rid: ridMapping[index], // reassign rid
3393
3396
  }));
3394
3397
  };
3395
- const findOptimalScreenSharingLayers = (videoTrack, preferences, defaultMaxBitrate = 3000000) => {
3398
+ const findOptimalScreenSharingLayers = (videoTrack, publishOptions, defaultMaxBitrate = 3000000) => {
3399
+ const { screenShareSettings: preferences } = publishOptions || {};
3396
3400
  const settings = videoTrack.getSettings();
3397
3401
  return [
3398
3402
  {
@@ -5173,11 +5177,10 @@ class Publisher {
5173
5177
  const targetResolution = settings?.video
5174
5178
  .target_resolution;
5175
5179
  const screenShareBitrate = settings?.screensharing.target_resolution?.bitrate;
5176
- const { preferredBitrate, preferredCodec, screenShareSettings } = opts;
5177
5180
  const videoEncodings = trackType === TrackType.VIDEO
5178
- ? findOptimalVideoLayers(track, targetResolution, preferredBitrate)
5181
+ ? findOptimalVideoLayers(track, targetResolution, opts)
5179
5182
  : trackType === TrackType.SCREEN_SHARE
5180
- ? findOptimalScreenSharingLayers(track, screenShareSettings, screenShareBitrate)
5183
+ ? findOptimalScreenSharingLayers(track, opts, screenShareBitrate)
5181
5184
  : undefined;
5182
5185
  // listen for 'ended' event on the track as it might be ended abruptly
5183
5186
  // by an external factor as permission revokes, device disconnected, etc.
@@ -5197,6 +5200,7 @@ class Publisher {
5197
5200
  this.transceiverInitOrder.push(trackType);
5198
5201
  this.transceiverRegistry[trackType] = transceiver;
5199
5202
  this.publishOptionsPerTrackType.set(trackType, opts);
5203
+ const { preferredCodec } = opts;
5200
5204
  const codec = isReactNative() && trackType === TrackType.VIDEO && !preferredCodec
5201
5205
  ? getRNOptimalCodec()
5202
5206
  : preferredCodec;
@@ -5515,9 +5519,9 @@ class Publisher {
5515
5519
  const publishOpts = this.publishOptionsPerTrackType.get(trackType);
5516
5520
  optimalLayers =
5517
5521
  trackType === TrackType.VIDEO
5518
- ? findOptimalVideoLayers(track, targetResolution, publishOpts?.preferredBitrate)
5522
+ ? findOptimalVideoLayers(track, targetResolution, publishOpts)
5519
5523
  : trackType === TrackType.SCREEN_SHARE
5520
- ? findOptimalScreenSharingLayers(track, publishOpts?.screenShareSettings)
5524
+ ? findOptimalScreenSharingLayers(track, publishOpts)
5521
5525
  : [];
5522
5526
  this.trackLayersCache[trackType] = optimalLayers;
5523
5527
  }
@@ -8401,6 +8405,11 @@ class CameraManagerState extends InputMediaDeviceManagerState {
8401
8405
  }
8402
8406
 
8403
8407
  class CameraManager extends InputMediaDeviceManager {
8408
+ /**
8409
+ * Constructs a new CameraManager.
8410
+ *
8411
+ * @param call the call instance.
8412
+ */
8404
8413
  constructor(call) {
8405
8414
  super(call, new CameraManagerState(), TrackType.VIDEO);
8406
8415
  this.targetResolution = {
@@ -8408,17 +8417,6 @@ class CameraManager extends InputMediaDeviceManager {
8408
8417
  height: 720,
8409
8418
  };
8410
8419
  }
8411
- /**
8412
- * The publish options for the camera.
8413
- *
8414
- * @internal internal use only, not part of the public API.
8415
- */
8416
- get publishOptions() {
8417
- return {
8418
- preferredCodec: this.preferredCodec,
8419
- preferredBitrate: this.preferredBitrate,
8420
- };
8421
- }
8422
8420
  /**
8423
8421
  * Select the camera direction.
8424
8422
  *
@@ -8473,16 +8471,33 @@ class CameraManager extends InputMediaDeviceManager {
8473
8471
  * @param codec the codec to use for encoding the video.
8474
8472
  */
8475
8473
  setPreferredCodec(codec) {
8476
- this.preferredCodec = codec;
8474
+ this.updatePublishOptions({ preferredCodec: codec });
8477
8475
  }
8478
8476
  /**
8479
- * Sets the preferred bitrate for encoding the video.
8477
+ * Updates the preferred publish options for the video stream.
8480
8478
  *
8481
- * @internal internal use only, not part of the public API.
8482
- * @param bitrate the bitrate to use for encoding the video.
8479
+ * @internal
8480
+ * @param options the options to use.
8481
+ */
8482
+ updatePublishOptions(options) {
8483
+ this.publishOptions = { ...this.publishOptions, ...options };
8484
+ }
8485
+ /**
8486
+ * Returns the capture resolution of the camera.
8483
8487
  */
8484
- setPreferredBitrate(bitrate) {
8485
- this.preferredBitrate = bitrate;
8488
+ getCaptureResolution() {
8489
+ const { mediaStream } = this.state;
8490
+ if (!mediaStream)
8491
+ return;
8492
+ const [videoTrack] = mediaStream.getVideoTracks();
8493
+ if (!videoTrack)
8494
+ return;
8495
+ const settings = videoTrack.getSettings();
8496
+ return {
8497
+ width: settings.width,
8498
+ height: settings.height,
8499
+ frameRate: settings.frameRate,
8500
+ };
8486
8501
  }
8487
8502
  getDevices() {
8488
8503
  return getVideoDevices();
@@ -12342,7 +12357,7 @@ class StreamClient {
12342
12357
  });
12343
12358
  };
12344
12359
  this.getUserAgent = () => {
12345
- const version = "1.7.1";
12360
+ const version = "1.7.2";
12346
12361
  return (this.userAgent ||
12347
12362
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
12348
12363
  };