@flashphoner/websdk 2.0.256 → 2.0.258

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.
@@ -7628,6 +7628,12 @@ var ERROR_INFO = Object.freeze({
7628
7628
  * @memberOf Flashphoner.constants.ERROR_INFO
7629
7629
  */
7630
7630
  CAN_NOT_SWITCH_MIC: 'Number of mics is less than 2 or microphone is already used by other application',
7631
+ /**
7632
+ * Error if cannot set a new resolution to the published track
7633
+ * @event CAN_NOT_SET_RESOLUTION
7634
+ * @memberOf Flashphoner.constants.ERROR_INFO
7635
+ */
7636
+ CAN_NOT_SET_RESOLUTION: 'Cannot switch a published stream resolution',
7631
7637
  /**
7632
7638
  * Local browser error detected
7633
7639
  * @event LOCAL_ERROR
@@ -10492,6 +10498,36 @@ var createSession = function createSession(options) {
10492
10498
  }
10493
10499
  }
10494
10500
  };
10501
+
10502
+ /**
10503
+ * Update video publishing settings on the fly
10504
+ *
10505
+ * @param {Object} stream video settings: {maxBitrate, frameRate, scaleResolutionDownBy)}
10506
+ * @return {Promice} encodings object applied
10507
+ * @memberof Stream
10508
+ */
10509
+ var updateVideoSettings = function updateVideoSettings(settings) {
10510
+ if (published() && mediaConnection) {
10511
+ return mediaConnection.updateVideoSettings(settings);
10512
+ } else {
10513
+ throw new Error("This function available for publishing stream only");
10514
+ }
10515
+ };
10516
+
10517
+ /**
10518
+ * Update video publishing resolution on the fly
10519
+ *
10520
+ * @param {Object} stream video resolution: {width, height)}
10521
+ * @return {Promice} video constaints object applied
10522
+ * @memberof Stream
10523
+ */
10524
+ var updateVideoResolution = function updateVideoResolution(resolution) {
10525
+ if (published() && mediaConnection) {
10526
+ return mediaConnection.updateVideoResolution(resolution);
10527
+ } else {
10528
+ throw new Error("This function available for publishing stream only");
10529
+ }
10530
+ };
10495
10531
  stream.play = play;
10496
10532
  stream.publish = publish;
10497
10533
  stream.stop = _stop;
@@ -10531,6 +10567,8 @@ var createSession = function createSession(options) {
10531
10567
  stream.switchToCam = switchToCam;
10532
10568
  stream.sendData = sendData;
10533
10569
  stream.getLogger = getLogger;
10570
+ stream.updateVideoSettings = updateVideoSettings;
10571
+ stream.updateVideoResolution = updateVideoResolution;
10534
10572
  streams[id_] = stream;
10535
10573
  return stream;
10536
10574
  };
@@ -12724,16 +12762,79 @@ var createConnection = function createConnection(options) {
12724
12762
  screenShare = false;
12725
12763
  };
12726
12764
  var setPublishingBitrate = function setPublishingBitrate(minBitrate, maxBitrate) {
12727
- var senders = connection.getSenders();
12728
- senders.forEach(function (sender) {
12729
- if (sender.track.kind == "video" && maxBitrate) {
12730
- var parameters = sender.getParameters();
12731
- for (var i = 0; i < parameters.encodings.length; i++) {
12732
- if (!parameters.encodings[i].maxBitrate) {
12733
- parameters.encodings[i].maxBitrate = maxBitrate * 1000;
12765
+ updateVideoSettings({
12766
+ maxBitrate: maxBitrate
12767
+ });
12768
+ };
12769
+ var updateVideoSettings = function updateVideoSettings(settings) {
12770
+ return new Promise(function (resolve, reject) {
12771
+ if (connection && settings) {
12772
+ connection.getSenders().forEach(function (sender) {
12773
+ if (sender.track.kind == "video") {
12774
+ var parameters = sender.getParameters();
12775
+ for (var i = 0; i < parameters.encodings.length; i++) {
12776
+ if (settings.maxBitrate) {
12777
+ parameters.encodings[i].maxBitrate = settings.maxBitrate * 1000;
12778
+ } else if (parameters.encodings[i].maxBitrate) {
12779
+ delete parameters.encodings[i].maxBitrate;
12780
+ }
12781
+ if (settings.frameRate) {
12782
+ parameters.encodings[i].maxFramerate = settings.frameRate;
12783
+ }
12784
+ if (settings.scaleResolutionDownBy) {
12785
+ parameters.encodings[i].scaleResolutionDownBy = settings.scaleResolutionDownBy;
12786
+ }
12787
+ }
12788
+ sender.setParameters(parameters).then(function () {
12789
+ logger.info(LOG_PREFIX, "Set video encoder parameters to " + JSON.stringify(parameters.encodings));
12790
+ resolve(parameters.encodings);
12791
+ })["catch"](function (reason) {
12792
+ logger.error(LOG_PREFIX, reason);
12793
+ reject(reason);
12794
+ });
12734
12795
  }
12735
- }
12736
- sender.setParameters(parameters).then(function () {});
12796
+ });
12797
+ }
12798
+ });
12799
+ };
12800
+ var updateVideoResolution = function updateVideoResolution(resolution) {
12801
+ return new Promise(function (resolve, reject) {
12802
+ if (connection && localVideo && localVideo.srcObject && !customStream && resolution) {
12803
+ connection.getSenders().forEach(function (sender) {
12804
+ if (sender.track.kind === 'audio') return;
12805
+ sender.track.stop();
12806
+ //use the settings that were set during connection initiation
12807
+ var clonedConstraints = Object.assign({}, constraints);
12808
+ if (resolution.width) {
12809
+ clonedConstraints.video.width = {
12810
+ ideal: resolution.width
12811
+ };
12812
+ }
12813
+ if (resolution.height) {
12814
+ clonedConstraints.video.height = {
12815
+ ideal: resolution.height
12816
+ };
12817
+ }
12818
+ clonedConstraints.audio = false;
12819
+ navigator.mediaDevices.getUserMedia(clonedConstraints).then(function (newStream) {
12820
+ var newVideoTrack = newStream.getVideoTracks()[0];
12821
+ newVideoTrack.enabled = localVideo.srcObject.getVideoTracks()[0].enabled;
12822
+ var audioTrack = localVideo.srcObject.getAudioTracks()[0];
12823
+ sender.replaceTrack(newVideoTrack);
12824
+ localVideo.srcObject = newStream;
12825
+ // On Safari mobile _newStream_ doesn't contain audio track, so we need to add track from previous stream
12826
+ if (localVideo.srcObject.getAudioTracks().length == 0 && audioTrack) {
12827
+ localVideo.srcObject.addTrack(audioTrack);
12828
+ }
12829
+ logger.info(LOG_PREFIX, "Set video constraints to " + JSON.stringify(clonedConstraints.video));
12830
+ resolve(clonedConstraints.video);
12831
+ })["catch"](function (reason) {
12832
+ logger.error(LOG_PREFIX, reason);
12833
+ reject(reason);
12834
+ });
12835
+ });
12836
+ } else {
12837
+ reject(constants.ERROR_INFO.CAN_NOT_SET_RESOLUTION);
12737
12838
  }
12738
12839
  });
12739
12840
  };
@@ -12769,6 +12870,8 @@ var createConnection = function createConnection(options) {
12769
12870
  exports.switchToScreen = switchToScreen;
12770
12871
  exports.switchToCam = switchToCam;
12771
12872
  exports.setPublishingBitrate = setPublishingBitrate;
12873
+ exports.updateVideoSettings = updateVideoSettings;
12874
+ exports.updateVideoResolution = updateVideoResolution;
12772
12875
  connections[id] = exports;
12773
12876
  resolve(exports);
12774
12877
  });
@@ -13437,10 +13540,14 @@ function normalizeConstraints(constraints) {
13437
13540
 
13438
13541
  //WCS-1972. fixed "TypeError"
13439
13542
  // Set default FPS value
13440
- var frameRate = !constraints.video.frameRate || constraints.video.frameRate == 0 ? 30 : constraints.video.frameRate;
13441
- constraints.video.frameRate = {
13442
- ideal: frameRate
13443
- };
13543
+ if (browserDetails.browser === "chrome" && browserDetails.version >= 134) {
13544
+ // Do not normalize framerate in Chrome 134 #WCS-4360
13545
+ } else {
13546
+ var frameRate = !constraints.video.frameRate || constraints.video.frameRate == 0 ? 30 : constraints.video.frameRate;
13547
+ constraints.video.frameRate = {
13548
+ ideal: frameRate
13549
+ };
13550
+ }
13444
13551
  }
13445
13552
  }
13446
13553
  if (constraints.audio) {