@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.es.js CHANGED
@@ -3014,7 +3014,7 @@ const retryable = async (rpc, signal) => {
3014
3014
  return result;
3015
3015
  };
3016
3016
 
3017
- const version = "1.7.1";
3017
+ const version = "1.7.2";
3018
3018
  const [major, minor, patch] = version.split('.');
3019
3019
  let sdkInfo = {
3020
3020
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -3291,14 +3291,16 @@ const defaultBitratePerRid = {
3291
3291
  *
3292
3292
  * @param videoTrack the video track to find optimal layers for.
3293
3293
  * @param targetResolution the expected target resolution.
3294
- * @param preferredBitrate the preferred bitrate for the video track.
3294
+ * @param publishOptions the publish options for the track.
3295
3295
  */
3296
- const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetResolution, preferredBitrate) => {
3296
+ const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetResolution, publishOptions) => {
3297
3297
  const optimalVideoLayers = [];
3298
3298
  const settings = videoTrack.getSettings();
3299
3299
  const { width: w = 0, height: h = 0 } = settings;
3300
+ const { preferredBitrate, bitrateDownscaleFactor = 2 } = publishOptions || {};
3300
3301
  const maxBitrate = getComputedMaxBitrate(targetResolution, w, h, preferredBitrate);
3301
3302
  let downscaleFactor = 1;
3303
+ let bitrateFactor = 1;
3302
3304
  ['f', 'h', 'q'].forEach((rid) => {
3303
3305
  // Reversing the order [f, h, q] to [q, h, f] as Chrome uses encoding index
3304
3306
  // when deciding which layer to disable when CPU or bandwidth is constrained.
@@ -3308,11 +3310,12 @@ const findOptimalVideoLayers = (videoTrack, targetResolution = defaultTargetReso
3308
3310
  rid,
3309
3311
  width: Math.round(w / downscaleFactor),
3310
3312
  height: Math.round(h / downscaleFactor),
3311
- maxBitrate: Math.round(maxBitrate / downscaleFactor) || defaultBitratePerRid[rid],
3313
+ maxBitrate: Math.round(maxBitrate / bitrateFactor) || defaultBitratePerRid[rid],
3312
3314
  scaleResolutionDownBy: downscaleFactor,
3313
3315
  maxFramerate: 30,
3314
3316
  });
3315
3317
  downscaleFactor *= 2;
3318
+ bitrateFactor *= bitrateDownscaleFactor;
3316
3319
  });
3317
3320
  // for simplicity, we start with all layers enabled, then this function
3318
3321
  // will clear/reassign the layers that are not needed
@@ -3372,7 +3375,8 @@ const withSimulcastConstraints = (settings, optimalVideoLayers) => {
3372
3375
  rid: ridMapping[index], // reassign rid
3373
3376
  }));
3374
3377
  };
3375
- const findOptimalScreenSharingLayers = (videoTrack, preferences, defaultMaxBitrate = 3000000) => {
3378
+ const findOptimalScreenSharingLayers = (videoTrack, publishOptions, defaultMaxBitrate = 3000000) => {
3379
+ const { screenShareSettings: preferences } = publishOptions || {};
3376
3380
  const settings = videoTrack.getSettings();
3377
3381
  return [
3378
3382
  {
@@ -5153,11 +5157,10 @@ class Publisher {
5153
5157
  const targetResolution = settings?.video
5154
5158
  .target_resolution;
5155
5159
  const screenShareBitrate = settings?.screensharing.target_resolution?.bitrate;
5156
- const { preferredBitrate, preferredCodec, screenShareSettings } = opts;
5157
5160
  const videoEncodings = trackType === TrackType.VIDEO
5158
- ? findOptimalVideoLayers(track, targetResolution, preferredBitrate)
5161
+ ? findOptimalVideoLayers(track, targetResolution, opts)
5159
5162
  : trackType === TrackType.SCREEN_SHARE
5160
- ? findOptimalScreenSharingLayers(track, screenShareSettings, screenShareBitrate)
5163
+ ? findOptimalScreenSharingLayers(track, opts, screenShareBitrate)
5161
5164
  : undefined;
5162
5165
  // listen for 'ended' event on the track as it might be ended abruptly
5163
5166
  // by an external factor as permission revokes, device disconnected, etc.
@@ -5177,6 +5180,7 @@ class Publisher {
5177
5180
  this.transceiverInitOrder.push(trackType);
5178
5181
  this.transceiverRegistry[trackType] = transceiver;
5179
5182
  this.publishOptionsPerTrackType.set(trackType, opts);
5183
+ const { preferredCodec } = opts;
5180
5184
  const codec = isReactNative() && trackType === TrackType.VIDEO && !preferredCodec
5181
5185
  ? getRNOptimalCodec()
5182
5186
  : preferredCodec;
@@ -5495,9 +5499,9 @@ class Publisher {
5495
5499
  const publishOpts = this.publishOptionsPerTrackType.get(trackType);
5496
5500
  optimalLayers =
5497
5501
  trackType === TrackType.VIDEO
5498
- ? findOptimalVideoLayers(track, targetResolution, publishOpts?.preferredBitrate)
5502
+ ? findOptimalVideoLayers(track, targetResolution, publishOpts)
5499
5503
  : trackType === TrackType.SCREEN_SHARE
5500
- ? findOptimalScreenSharingLayers(track, publishOpts?.screenShareSettings)
5504
+ ? findOptimalScreenSharingLayers(track, publishOpts)
5501
5505
  : [];
5502
5506
  this.trackLayersCache[trackType] = optimalLayers;
5503
5507
  }
@@ -8381,6 +8385,11 @@ class CameraManagerState extends InputMediaDeviceManagerState {
8381
8385
  }
8382
8386
 
8383
8387
  class CameraManager extends InputMediaDeviceManager {
8388
+ /**
8389
+ * Constructs a new CameraManager.
8390
+ *
8391
+ * @param call the call instance.
8392
+ */
8384
8393
  constructor(call) {
8385
8394
  super(call, new CameraManagerState(), TrackType.VIDEO);
8386
8395
  this.targetResolution = {
@@ -8388,17 +8397,6 @@ class CameraManager extends InputMediaDeviceManager {
8388
8397
  height: 720,
8389
8398
  };
8390
8399
  }
8391
- /**
8392
- * The publish options for the camera.
8393
- *
8394
- * @internal internal use only, not part of the public API.
8395
- */
8396
- get publishOptions() {
8397
- return {
8398
- preferredCodec: this.preferredCodec,
8399
- preferredBitrate: this.preferredBitrate,
8400
- };
8401
- }
8402
8400
  /**
8403
8401
  * Select the camera direction.
8404
8402
  *
@@ -8453,16 +8451,33 @@ class CameraManager extends InputMediaDeviceManager {
8453
8451
  * @param codec the codec to use for encoding the video.
8454
8452
  */
8455
8453
  setPreferredCodec(codec) {
8456
- this.preferredCodec = codec;
8454
+ this.updatePublishOptions({ preferredCodec: codec });
8457
8455
  }
8458
8456
  /**
8459
- * Sets the preferred bitrate for encoding the video.
8457
+ * Updates the preferred publish options for the video stream.
8460
8458
  *
8461
- * @internal internal use only, not part of the public API.
8462
- * @param bitrate the bitrate to use for encoding the video.
8459
+ * @internal
8460
+ * @param options the options to use.
8461
+ */
8462
+ updatePublishOptions(options) {
8463
+ this.publishOptions = { ...this.publishOptions, ...options };
8464
+ }
8465
+ /**
8466
+ * Returns the capture resolution of the camera.
8463
8467
  */
8464
- setPreferredBitrate(bitrate) {
8465
- this.preferredBitrate = bitrate;
8468
+ getCaptureResolution() {
8469
+ const { mediaStream } = this.state;
8470
+ if (!mediaStream)
8471
+ return;
8472
+ const [videoTrack] = mediaStream.getVideoTracks();
8473
+ if (!videoTrack)
8474
+ return;
8475
+ const settings = videoTrack.getSettings();
8476
+ return {
8477
+ width: settings.width,
8478
+ height: settings.height,
8479
+ frameRate: settings.frameRate,
8480
+ };
8466
8481
  }
8467
8482
  getDevices() {
8468
8483
  return getVideoDevices();
@@ -12322,7 +12337,7 @@ class StreamClient {
12322
12337
  });
12323
12338
  };
12324
12339
  this.getUserAgent = () => {
12325
- const version = "1.7.1";
12340
+ const version = "1.7.2";
12326
12341
  return (this.userAgent ||
12327
12342
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
12328
12343
  };