@webex/web-client-media-engine 3.8.4 → 3.9.0

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/esm/index.js CHANGED
@@ -30,7 +30,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30
30
  PERFORMANCE OF THIS SOFTWARE.
31
31
  ***************************************************************************** */
32
32
 
33
- function __awaiter$1(thisArg, _arguments, P, generator) {
33
+ function __awaiter$2(thisArg, _arguments, P, generator) {
34
34
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
35
  return new (P || (P = Promise))(function (resolve, reject) {
36
36
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -352,7 +352,7 @@ var DeviceKind;
352
352
  * media has successfully been obtained.
353
353
  */
354
354
  function getUserMedia(constraints) {
355
- return __awaiter$1(this, void 0, void 0, function* () {
355
+ return __awaiter$2(this, void 0, void 0, function* () {
356
356
  return navigator.mediaDevices.getUserMedia(constraints);
357
357
  });
358
358
  }
@@ -376,7 +376,7 @@ function getDisplayMedia(constraints) {
376
376
  * fulfilled.
377
377
  */
378
378
  function enumerateDevices() {
379
- return __awaiter$1(this, void 0, void 0, function* () {
379
+ return __awaiter$2(this, void 0, void 0, function* () {
380
380
  return navigator.mediaDevices.enumerateDevices();
381
381
  });
382
382
  }
@@ -398,7 +398,7 @@ function setOnDeviceChangeHandler$1(handler) {
398
398
  * @returns Array of Permission Status objects.
399
399
  */
400
400
  function checkNavigatorPermissions(deviceKinds) {
401
- return __awaiter$1(this, void 0, void 0, function* () {
401
+ return __awaiter$2(this, void 0, void 0, function* () {
402
402
  const permissionRequests = [];
403
403
  if (deviceKinds.includes(DeviceKind.VideoInput)) {
404
404
  permissionRequests.push(navigator.permissions.query({ name: 'camera' }));
@@ -416,7 +416,7 @@ function checkNavigatorPermissions(deviceKinds) {
416
416
  * @returns True if device permissions exist, false if otherwise.
417
417
  */
418
418
  function checkDevicePermissions(deviceKinds) {
419
- return __awaiter$1(this, void 0, void 0, function* () {
419
+ return __awaiter$2(this, void 0, void 0, function* () {
420
420
  try {
421
421
  const permissions = yield checkNavigatorPermissions(deviceKinds);
422
422
  if (permissions.every((permission) => permission.state === 'granted')) {
@@ -446,7 +446,7 @@ function checkDevicePermissions(deviceKinds) {
446
446
  * @returns The callback's response.
447
447
  */
448
448
  function ensureDevicePermissions(deviceKinds, callback) {
449
- return __awaiter$1(this, void 0, void 0, function* () {
449
+ return __awaiter$2(this, void 0, void 0, function* () {
450
450
  try {
451
451
  const hasDevicePermissions = yield checkDevicePermissions(deviceKinds);
452
452
  if (!hasDevicePermissions) {
@@ -513,7 +513,7 @@ class WcmeError {
513
513
  * @returns A LocalCameraStream object or an error.
514
514
  */
515
515
  function createCameraStream(constructor, constraints) {
516
- return __awaiter$1(this, void 0, void 0, function* () {
516
+ return __awaiter$2(this, void 0, void 0, function* () {
517
517
  let stream;
518
518
  try {
519
519
  stream = yield getUserMedia({ video: Object.assign({}, constraints) });
@@ -532,7 +532,7 @@ function createCameraStream(constructor, constraints) {
532
532
  * @returns A LocalMicrophoneStream object or an error.
533
533
  */
534
534
  function createMicrophoneStream(constructor, constraints) {
535
- return __awaiter$1(this, void 0, void 0, function* () {
535
+ return __awaiter$2(this, void 0, void 0, function* () {
536
536
  let stream;
537
537
  try {
538
538
  stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
@@ -551,7 +551,7 @@ function createMicrophoneStream(constructor, constraints) {
551
551
  * @returns A Promise that resolves to a LocalDisplayStream or an error.
552
552
  */
553
553
  function createDisplayStream(constructor, videoContentHint) {
554
- return __awaiter$1(this, void 0, void 0, function* () {
554
+ return __awaiter$2(this, void 0, void 0, function* () {
555
555
  let stream;
556
556
  try {
557
557
  stream = yield getDisplayMedia({ video: true });
@@ -577,7 +577,7 @@ function createDisplayStream(constructor, videoContentHint) {
577
577
  * instead.
578
578
  */
579
579
  function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStreamConstructor, videoContentHint) {
580
- return __awaiter$1(this, void 0, void 0, function* () {
580
+ return __awaiter$2(this, void 0, void 0, function* () {
581
581
  let stream;
582
582
  try {
583
583
  stream = yield getDisplayMedia({ video: true, audio: true });
@@ -605,7 +605,7 @@ function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStrea
605
605
  * @returns List of media devices in an array of MediaDeviceInfo objects.
606
606
  */
607
607
  function getDevices(deviceKind) {
608
- return __awaiter$1(this, void 0, void 0, function* () {
608
+ return __awaiter$2(this, void 0, void 0, function* () {
609
609
  let devices;
610
610
  try {
611
611
  devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
@@ -622,7 +622,7 @@ function getDevices(deviceKind) {
622
622
  * @returns List of microphone devices in an array of MediaDeviceInfo objects.
623
623
  */
624
624
  function getAudioInputDevices() {
625
- return __awaiter$1(this, void 0, void 0, function* () {
625
+ return __awaiter$2(this, void 0, void 0, function* () {
626
626
  return getDevices(DeviceKind.AudioInput);
627
627
  });
628
628
  }
@@ -632,7 +632,7 @@ function getAudioInputDevices() {
632
632
  * @returns List of speaker devices in an array of MediaDeviceInfo objects.
633
633
  */
634
634
  function getAudioOutputDevices() {
635
- return __awaiter$1(this, void 0, void 0, function* () {
635
+ return __awaiter$2(this, void 0, void 0, function* () {
636
636
  return getDevices(DeviceKind.AudioOutput);
637
637
  });
638
638
  }
@@ -642,7 +642,7 @@ function getAudioOutputDevices() {
642
642
  * @returns List of camera devices in an array of MediaDeviceInfo objects.
643
643
  */
644
644
  function getVideoInputDevices() {
645
- return __awaiter$1(this, void 0, void 0, function* () {
645
+ return __awaiter$2(this, void 0, void 0, function* () {
646
646
  return getDevices(DeviceKind.VideoInput);
647
647
  });
648
648
  }
@@ -1359,7 +1359,7 @@ class _LocalStream extends Stream {
1359
1359
  * @param effect - The effect to add.
1360
1360
  */
1361
1361
  addEffect(name, effect) {
1362
- return __awaiter$1(this, void 0, void 0, function* () {
1362
+ return __awaiter$2(this, void 0, void 0, function* () {
1363
1363
  // Load the effect
1364
1364
  this.loadingEffects.set(name, effect);
1365
1365
  const outputTrack = yield effect.load(this.outputTrack);
@@ -1410,7 +1410,7 @@ class _LocalStream extends Stream {
1410
1410
  * Cleanup the local effects.
1411
1411
  */
1412
1412
  disposeEffects() {
1413
- return __awaiter$1(this, void 0, void 0, function* () {
1413
+ return __awaiter$2(this, void 0, void 0, function* () {
1414
1414
  this.loadingEffects.clear();
1415
1415
  // Dispose of any effects currently in use
1416
1416
  if (this.effects.length > 0) {
@@ -1435,7 +1435,7 @@ class LocalAudioStream extends LocalStream {
1435
1435
  * @returns A promise which resolves when the constraints have been successfully applied.
1436
1436
  */
1437
1437
  applyConstraints(constraints) {
1438
- return __awaiter$1(this, void 0, void 0, function* () {
1438
+ return __awaiter$2(this, void 0, void 0, function* () {
1439
1439
  logger$3.log(`Applying constraints to local track:`, constraints);
1440
1440
  return this.inputTrack.applyConstraints(constraints).then(() => {
1441
1441
  this[LocalStreamEventNames.ConstraintsChange].emit();
@@ -1455,7 +1455,7 @@ class LocalVideoStream extends LocalStream {
1455
1455
  * @returns A promise which resolves when the constraints have been successfully applied.
1456
1456
  */
1457
1457
  applyConstraints(constraints) {
1458
- return __awaiter$1(this, void 0, void 0, function* () {
1458
+ return __awaiter$2(this, void 0, void 0, function* () {
1459
1459
  logger$3.log(`Applying constraints to local track:`, constraints);
1460
1460
  return this.inputTrack.applyConstraints(constraints).then(() => {
1461
1461
  this[LocalStreamEventNames.ConstraintsChange].emit();
@@ -5710,7 +5710,7 @@ class PeerConnection extends EventEmitter$4 {
5710
5710
  * other peer.
5711
5711
  */
5712
5712
  createAnswer(options) {
5713
- return __awaiter$1(this, void 0, void 0, function* () {
5713
+ return __awaiter$2(this, void 0, void 0, function* () {
5714
5714
  return this.pc.createAnswer(options);
5715
5715
  });
5716
5716
  }
@@ -5725,7 +5725,7 @@ class PeerConnection extends EventEmitter$4 {
5725
5725
  * That received offer should be delivered through the signaling server to a remote peer.
5726
5726
  */
5727
5727
  createOffer(options) {
5728
- return __awaiter$1(this, void 0, void 0, function* () {
5728
+ return __awaiter$2(this, void 0, void 0, function* () {
5729
5729
  return this.pc.createOffer(options);
5730
5730
  });
5731
5731
  }
@@ -5739,7 +5739,7 @@ class PeerConnection extends EventEmitter$4 {
5739
5739
  */
5740
5740
  setLocalDescription(description) {
5741
5741
  var _a;
5742
- return __awaiter$1(this, void 0, void 0, function* () {
5742
+ return __awaiter$2(this, void 0, void 0, function* () {
5743
5743
  // In Firefox, setLocalDescription will not throw an error if an m-line has no codecs, even
5744
5744
  // though it violates https://datatracker.ietf.org/doc/html/rfc8866. See
5745
5745
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1857612. So, we check the media lines here to
@@ -5764,7 +5764,7 @@ class PeerConnection extends EventEmitter$4 {
5764
5764
  * specified description is incompatible with one or both of the peers on the connection).
5765
5765
  */
5766
5766
  setRemoteDescription(description) {
5767
- return __awaiter$1(this, void 0, void 0, function* () {
5767
+ return __awaiter$2(this, void 0, void 0, function* () {
5768
5768
  return this.pc.setRemoteDescription(description);
5769
5769
  });
5770
5770
  }
@@ -5838,7 +5838,7 @@ class PeerConnection extends EventEmitter$4 {
5838
5838
  */
5839
5839
  getCurrentConnectionType() {
5840
5840
  var _a;
5841
- return __awaiter$1(this, void 0, void 0, function* () {
5841
+ return __awaiter$2(this, void 0, void 0, function* () {
5842
5842
  // make sure this method only can be called when the ice connection is established;
5843
5843
  const isIceConnected = this.pc.iceConnectionState === 'connected' || this.pc.iceConnectionState === 'completed';
5844
5844
  if (!isIceConnected) {
@@ -6978,7 +6978,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6978
6978
  PERFORMANCE OF THIS SOFTWARE.
6979
6979
  ***************************************************************************** */
6980
6980
 
6981
- function __awaiter(thisArg, _arguments, P, generator) {
6981
+ function __awaiter$1(thisArg, _arguments, P, generator) {
6982
6982
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6983
6983
  return new (P || (P = Promise))(function (resolve, reject) {
6984
6984
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -6990,6 +6990,42 @@ function __awaiter(thisArg, _arguments, P, generator) {
6990
6990
 
6991
6991
  var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6992
6992
 
6993
+ var __awaiter = (commonjsGlobal$1 && commonjsGlobal$1.__awaiter) || function (thisArg, _arguments, P, generator) {
6994
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6995
+ return new (P || (P = Promise))(function (resolve, reject) {
6996
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6997
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6998
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6999
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
7000
+ });
7001
+ };
7002
+ var __generator = (commonjsGlobal$1 && commonjsGlobal$1.__generator) || function (thisArg, body) {
7003
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
7004
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
7005
+ function verb(n) { return function (v) { return step([n, v]); }; }
7006
+ function step(op) {
7007
+ if (f) throw new TypeError("Generator is already executing.");
7008
+ while (_) try {
7009
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
7010
+ if (y = 0, t) op = [op[0] & 2, t.value];
7011
+ switch (op[0]) {
7012
+ case 0: case 1: t = op; break;
7013
+ case 4: _.label++; return { value: op[1], done: false };
7014
+ case 5: _.label++; y = op[1]; op = [0]; continue;
7015
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
7016
+ default:
7017
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
7018
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
7019
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
7020
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
7021
+ if (t[2]) _.ops.pop();
7022
+ _.trys.pop(); continue;
7023
+ }
7024
+ op = body.call(thisArg, _);
7025
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
7026
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7027
+ }
7028
+ };
6993
7029
  var rtcStats_1 = void 0;
6994
7030
  /**
6995
7031
  * Copies values of any nested depth.
@@ -7322,24 +7358,36 @@ var rtcStats = function (pc, logger, intervalTime, statsPreProcessor) {
7322
7358
  };
7323
7359
  navigator.mediaDevices.getDisplayMedia = gdm.bind(navigator.mediaDevices);
7324
7360
  }
7361
+ var getStatsReport = function () { return __awaiter(void 0, void 0, void 0, function () {
7362
+ return __generator(this, function (_a) {
7363
+ return [2 /*return*/, pc.getStats(null).then(function (res) {
7364
+ // Convert from stats report to js Map in order to have values set in `statsPreProcessor`
7365
+ var statsMap = new Map();
7366
+ res.forEach(function (stats, key) { return statsMap.set(key, stats); });
7367
+ return statsPreProcessor(statsMap).then(function () {
7368
+ var now = map2obj(statsMap);
7369
+ var base = deepCopy$1(now); // our new prev
7370
+ var compressed = deltaCompression(prev, now);
7371
+ trace('stats-report', formatStatsReport(compressed), compressed.timestamp !== -Infinity ? compressed.timestamp : undefined);
7372
+ prev = base;
7373
+ return Promise.resolve();
7374
+ });
7375
+ })];
7376
+ });
7377
+ }); };
7325
7378
  var interval = window.setInterval(function () {
7326
7379
  if (pc.signalingState === 'closed') {
7327
7380
  window.clearInterval(interval);
7328
7381
  return;
7329
7382
  }
7330
- pc.getStats(null).then(function (res) {
7331
- // Convert from stats report to js Map in order to have values set in `statsPreProcessor`
7332
- var statsMap = new Map();
7333
- res.forEach(function (stats, key) { return statsMap.set(key, stats); });
7334
- statsPreProcessor(statsMap).then(function () {
7335
- var now = map2obj(statsMap);
7336
- var base = deepCopy$1(now); // our new prev
7337
- var compressed = deltaCompression(prev, now);
7338
- trace('stats-report', formatStatsReport(compressed), compressed.timestamp !== -Infinity ? compressed.timestamp : undefined);
7339
- prev = base;
7340
- });
7341
- });
7383
+ getStatsReport();
7342
7384
  }, intervalTime);
7385
+ var forceStatsReport = function () { return __awaiter(void 0, void 0, void 0, function () {
7386
+ return __generator(this, function (_a) {
7387
+ return [2 /*return*/, getStatsReport()];
7388
+ });
7389
+ }); };
7390
+ return { forceStatsReport: forceStatsReport };
7343
7391
  };
7344
7392
  rtcStats_1 = rtcStats;
7345
7393
 
@@ -13791,7 +13839,7 @@ function waterfall (tasks, callback) {
13791
13839
  awaitify(waterfall);
13792
13840
 
13793
13841
  function processTasks(task, finishedCallback) {
13794
- return __awaiter(this, void 0, void 0, function* () {
13842
+ return __awaiter$1(this, void 0, void 0, function* () {
13795
13843
  try {
13796
13844
  yield task();
13797
13845
  finishedCallback();
@@ -13837,27 +13885,29 @@ class SendOnlyTransceiver extends Transceiver {
13837
13885
  this.mediaType = mediaType;
13838
13886
  }
13839
13887
  replaceSenderSource(stream) {
13840
- var _a;
13841
- return __awaiter(this, void 0, void 0, function* () {
13888
+ var _a, _b;
13889
+ return __awaiter$1(this, void 0, void 0, function* () {
13842
13890
  const trackOrNull = (_a = stream === null || stream === void 0 ? void 0 : stream.outputStream.getTracks()[0]) !== null && _a !== void 0 ? _a : null;
13843
- yield this.sender.replaceTrack(trackOrNull);
13844
- if (trackOrNull) {
13845
- logger.log(`Sender source for ${this.mediaType} replaced with track ID ${trackOrNull.id}`);
13846
- }
13847
- else {
13848
- logger.log(`Sender source for ${this.mediaType} set to null, sender stopped`);
13891
+ if (((_b = this.sender.track) === null || _b === void 0 ? void 0 : _b.id) !== (trackOrNull === null || trackOrNull === void 0 ? void 0 : trackOrNull.id)) {
13892
+ yield this.sender.replaceTrack(trackOrNull);
13893
+ if (trackOrNull) {
13894
+ logger.log(`Sender source for ${this.mediaType} replaced with track ID ${trackOrNull.id}`);
13895
+ }
13896
+ else {
13897
+ logger.log(`Sender source for ${this.mediaType} set to null, sender stopped`);
13898
+ }
13849
13899
  }
13850
13900
  });
13851
13901
  }
13852
13902
  handleTrackChange() {
13853
- return __awaiter(this, void 0, void 0, function* () {
13903
+ return __awaiter$1(this, void 0, void 0, function* () {
13854
13904
  if (this.requested) {
13855
13905
  yield this.replaceSenderSource(this.publishedStream);
13856
13906
  }
13857
13907
  });
13858
13908
  }
13859
13909
  handleStreamConstraintsChange() {
13860
- return __awaiter(this, void 0, void 0, function* () {
13910
+ return __awaiter$1(this, void 0, void 0, function* () {
13861
13911
  yield this.updateSendParameters(this.requestedIdEncodingParamsMap);
13862
13912
  });
13863
13913
  }
@@ -13871,7 +13921,7 @@ class SendOnlyTransceiver extends Transceiver {
13871
13921
  const _super = Object.create(null, {
13872
13922
  replaceTransceiver: { get: () => super.replaceTransceiver }
13873
13923
  });
13874
- return __awaiter(this, void 0, void 0, function* () {
13924
+ return __awaiter$1(this, void 0, void 0, function* () {
13875
13925
  _super.replaceTransceiver.call(this, newRtcRtpTransceiver);
13876
13926
  newRtcRtpTransceiver.direction = this.direction;
13877
13927
  if (this.requested) {
@@ -13880,7 +13930,7 @@ class SendOnlyTransceiver extends Transceiver {
13880
13930
  });
13881
13931
  }
13882
13932
  replacePublishedStream(newStream) {
13883
- return __awaiter(this, void 0, void 0, function* () {
13933
+ return __awaiter$1(this, void 0, void 0, function* () {
13884
13934
  const oldStream = this.publishedStream;
13885
13935
  oldStream === null || oldStream === void 0 ? void 0 : oldStream.off(LocalStreamEventNames.OutputTrackChange, this.handleTrackChange);
13886
13936
  oldStream === null || oldStream === void 0 ? void 0 : oldStream.off(LocalStreamEventNames.ConstraintsChange, this.handleStreamConstraintsChange);
@@ -13928,31 +13978,29 @@ class SendOnlyTransceiver extends Transceiver {
13928
13978
  return this.sender.getStats();
13929
13979
  }
13930
13980
  updateSendParameters(requestedIdEncodingParamsMap) {
13931
- return __awaiter(this, void 0, void 0, function* () {
13932
- return this.updateSendParametersQueue.push(() => __awaiter(this, void 0, void 0, function* () {
13933
- if (this.publishedStream) {
13934
- const requested = requestedIdEncodingParamsMap.size > 0;
13935
- if (this.requested !== requested) {
13936
- this.replaceSenderSource(requested ? this.publishedStream : null);
13937
- }
13938
- const sendParameters = this.sender.getParameters();
13939
- sendParameters.encodings.forEach((encoding, index) => {
13940
- var _a, _b;
13941
- const encodingParams = requestedIdEncodingParamsMap.get(index);
13942
- encoding.active = !!encodingParams;
13943
- if (encodingParams) {
13944
- const { maxPayloadBitsPerSecond, maxFs, maxWidth, maxHeight } = encodingParams;
13945
- const scaleDownRatio = getScaleDownRatio((_a = this.publishedStream) === null || _a === void 0 ? void 0 : _a.getSettings().width, (_b = this.publishedStream) === null || _b === void 0 ? void 0 : _b.getSettings().height, maxFs, maxWidth, maxHeight);
13946
- if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
13947
- encoding.maxBitrate = maxPayloadBitsPerSecond;
13948
- }
13949
- if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
13950
- encoding.scaleResolutionDownBy = scaleDownRatio;
13951
- }
13952
- }
13953
- });
13954
- yield this.sender.setParameters(sendParameters);
13981
+ return __awaiter$1(this, void 0, void 0, function* () {
13982
+ return this.updateSendParametersQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
13983
+ const requested = requestedIdEncodingParamsMap.size > 0;
13984
+ if (this.requested !== requested) {
13985
+ yield this.replaceSenderSource(requested ? this.publishedStream : null);
13955
13986
  }
13987
+ const sendParameters = this.sender.getParameters();
13988
+ sendParameters.encodings.forEach((encoding, index) => {
13989
+ var _a, _b;
13990
+ const encodingParams = requestedIdEncodingParamsMap.get(index);
13991
+ encoding.active = !!encodingParams;
13992
+ if (encodingParams) {
13993
+ const { maxPayloadBitsPerSecond, maxFs, maxWidth, maxHeight } = encodingParams;
13994
+ const scaleDownRatio = getScaleDownRatio((_a = this.publishedStream) === null || _a === void 0 ? void 0 : _a.getSettings().width, (_b = this.publishedStream) === null || _b === void 0 ? void 0 : _b.getSettings().height, maxFs, maxWidth, maxHeight);
13995
+ if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
13996
+ encoding.maxBitrate = maxPayloadBitsPerSecond;
13997
+ }
13998
+ if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
13999
+ encoding.scaleResolutionDownBy = scaleDownRatio;
14000
+ }
14001
+ }
14002
+ });
14003
+ yield this.sender.setParameters(sendParameters);
13956
14004
  this.requestedIdEncodingParamsMap = requestedIdEncodingParamsMap;
13957
14005
  }));
13958
14006
  });
@@ -14001,7 +14049,7 @@ class SendSlot {
14001
14049
  this.sendTransceiver = sendTransceiver;
14002
14050
  }
14003
14051
  publishStream(stream) {
14004
- return __awaiter(this, void 0, void 0, function* () {
14052
+ return __awaiter$1(this, void 0, void 0, function* () {
14005
14053
  if (stream === this.sendTransceiver.publishedStream) {
14006
14054
  return Promise.resolve();
14007
14055
  }
@@ -14009,7 +14057,7 @@ class SendSlot {
14009
14057
  });
14010
14058
  }
14011
14059
  unpublishStream() {
14012
- return __awaiter(this, void 0, void 0, function* () {
14060
+ return __awaiter$1(this, void 0, void 0, function* () {
14013
14061
  if (!this.sendTransceiver.publishedStream) {
14014
14062
  return Promise.resolve();
14015
14063
  }
@@ -14026,24 +14074,24 @@ class SendSlot {
14026
14074
  this.sendTransceiver.active = active;
14027
14075
  }
14028
14076
  setCodecParameters(parameters) {
14029
- return __awaiter(this, void 0, void 0, function* () {
14077
+ return __awaiter$1(this, void 0, void 0, function* () {
14030
14078
  this.sendTransceiver.setCodecParameters(parameters);
14031
14079
  });
14032
14080
  }
14033
14081
  deleteCodecParameters(parameters) {
14034
- return __awaiter(this, void 0, void 0, function* () {
14082
+ return __awaiter$1(this, void 0, void 0, function* () {
14035
14083
  this.sendTransceiver.deleteCodecParameters(parameters);
14036
14084
  });
14037
14085
  }
14038
14086
  }
14039
14087
 
14040
14088
  class StatsManager {
14041
- constructor(statsGetter, statsPreprocessor = () => __awaiter(this, void 0, void 0, function* () { })) {
14089
+ constructor(statsGetter, statsPreprocessor = () => __awaiter$1(this, void 0, void 0, function* () { })) {
14042
14090
  this.statsGetter = statsGetter;
14043
14091
  this.statsPreProcessor = statsPreprocessor;
14044
14092
  }
14045
14093
  getStats() {
14046
- return __awaiter(this, void 0, void 0, function* () {
14094
+ return __awaiter$1(this, void 0, void 0, function* () {
14047
14095
  const statsReport = yield this.statsGetter();
14048
14096
  const statsMap = new Map();
14049
14097
  statsReport.forEach((stats, key) => statsMap.set(key, stats));
@@ -14053,7 +14101,7 @@ class StatsManager {
14053
14101
  }
14054
14102
  }
14055
14103
 
14056
- const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __awaiter(void 0, void 0, void 0, function* () {
14104
+ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __awaiter$1(void 0, void 0, void 0, function* () {
14057
14105
  const result = {
14058
14106
  audio: {
14059
14107
  senders: [],
@@ -14072,7 +14120,7 @@ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __await
14072
14120
  receivers: [],
14073
14121
  },
14074
14122
  };
14075
- yield Promise.all([...sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter(void 0, void 0, void 0, function* () {
14123
+ yield Promise.all([...sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter$1(void 0, void 0, void 0, function* () {
14076
14124
  var _a;
14077
14125
  const item = {
14078
14126
  report: yield transceiver.getStats(),
@@ -14094,8 +14142,8 @@ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __await
14094
14142
  result.screenShareVideo.senders.push(item);
14095
14143
  }
14096
14144
  })));
14097
- yield Promise.all([...recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter(void 0, void 0, void 0, function* () {
14098
- return Promise.all(transceivers.map((t) => __awaiter(void 0, void 0, void 0, function* () {
14145
+ yield Promise.all([...recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter$1(void 0, void 0, void 0, function* () {
14146
+ return Promise.all(transceivers.map((t) => __awaiter$1(void 0, void 0, void 0, function* () {
14099
14147
  var _b, _c;
14100
14148
  const item = {
14101
14149
  report: yield t.getStats(),
@@ -14476,9 +14524,9 @@ class MultistreamConnection extends EventEmitter$2 {
14476
14524
  });
14477
14525
  }
14478
14526
  createReceiveSlot(mediaType) {
14479
- return __awaiter(this, void 0, void 0, function* () {
14527
+ return __awaiter$1(this, void 0, void 0, function* () {
14480
14528
  return new Promise((createReceiveSlotResolve) => {
14481
- this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14529
+ this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14482
14530
  const rtcRtpTransceiver = this.pc.addTransceiver(toMediaStreamTrackKind(mediaType), {
14483
14531
  direction: 'recvonly',
14484
14532
  });
@@ -14529,7 +14577,7 @@ class MultistreamConnection extends EventEmitter$2 {
14529
14577
  return targetCodec.pt;
14530
14578
  }
14531
14579
  createOffer() {
14532
- return __awaiter(this, void 0, void 0, function* () {
14580
+ return __awaiter$1(this, void 0, void 0, function* () {
14533
14581
  if (!this.pc.getLocalDescription()) {
14534
14582
  this.midPredictor.allocateMidForDatachannel();
14535
14583
  }
@@ -14540,7 +14588,7 @@ class MultistreamConnection extends EventEmitter$2 {
14540
14588
  }
14541
14589
  const createOfferId = ++this.currentCreateOfferId;
14542
14590
  return new Promise((createOfferResolve, createOfferReject) => {
14543
- this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14591
+ this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14544
14592
  var _a;
14545
14593
  try {
14546
14594
  const offer = yield this.pc.createOffer();
@@ -14568,13 +14616,13 @@ class MultistreamConnection extends EventEmitter$2 {
14568
14616
  });
14569
14617
  }
14570
14618
  setAnswer(answer) {
14571
- return __awaiter(this, void 0, void 0, function* () {
14619
+ return __awaiter$1(this, void 0, void 0, function* () {
14572
14620
  const sdp = this.preProcessRemoteAnswer(answer);
14573
14621
  if (!this.setAnswerResolve) {
14574
14622
  throw new Error(`Call to setAnswer without having previously called createOffer`);
14575
14623
  }
14576
14624
  logger.info('calling this.pc.setRemoteDescription()');
14577
- return this.pc.setRemoteDescription({ type: 'answer', sdp }).then(() => __awaiter(this, void 0, void 0, function* () {
14625
+ return this.pc.setRemoteDescription({ type: 'answer', sdp }).then(() => __awaiter$1(this, void 0, void 0, function* () {
14578
14626
  logger.info('this.pc.setRemoteDescription() resolved');
14579
14627
  if (this.setAnswerResolve) {
14580
14628
  this.setAnswerResolve();
@@ -14588,7 +14636,7 @@ class MultistreamConnection extends EventEmitter$2 {
14588
14636
  }
14589
14637
  doLocalOfferAnswer() {
14590
14638
  var _a;
14591
- return __awaiter(this, void 0, void 0, function* () {
14639
+ return __awaiter$1(this, void 0, void 0, function* () {
14592
14640
  const offer = yield this.pc.createOffer();
14593
14641
  if (!offer.sdp) {
14594
14642
  throw new Error('No SDP offer');
@@ -14600,8 +14648,8 @@ class MultistreamConnection extends EventEmitter$2 {
14600
14648
  });
14601
14649
  }
14602
14650
  queueLocalOfferAnswer() {
14603
- return __awaiter(this, void 0, void 0, function* () {
14604
- return this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14651
+ return __awaiter$1(this, void 0, void 0, function* () {
14652
+ return this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14605
14653
  yield this.doLocalOfferAnswer();
14606
14654
  }));
14607
14655
  });
@@ -14784,13 +14832,13 @@ class MultistreamConnection extends EventEmitter$2 {
14784
14832
  return this.statsManager.getStats();
14785
14833
  }
14786
14834
  getTransceiverStats() {
14787
- return __awaiter(this, void 0, void 0, function* () {
14835
+ return __awaiter$1(this, void 0, void 0, function* () {
14788
14836
  return organizeTransceiverStats(this.sendTransceivers, this.recvTransceivers);
14789
14837
  });
14790
14838
  }
14791
14839
  preProcessStats(stats) {
14792
- return __awaiter(this, void 0, void 0, function* () {
14793
- yield Promise.all([...this.sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter(this, void 0, void 0, function* () {
14840
+ return __awaiter$1(this, void 0, void 0, function* () {
14841
+ yield Promise.all([...this.sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter$1(this, void 0, void 0, function* () {
14794
14842
  (yield transceiver.getStats()).forEach((senderStats) => {
14795
14843
  var _a;
14796
14844
  if (senderStats.type === 'outbound-rtp') {
@@ -14811,8 +14859,8 @@ class MultistreamConnection extends EventEmitter$2 {
14811
14859
  }
14812
14860
  });
14813
14861
  })));
14814
- yield Promise.all([...this.recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter(this, void 0, void 0, function* () {
14815
- yield Promise.all(transceivers.map((transceiver) => __awaiter(this, void 0, void 0, function* () {
14862
+ yield Promise.all([...this.recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter$1(this, void 0, void 0, function* () {
14863
+ yield Promise.all(transceivers.map((transceiver) => __awaiter$1(this, void 0, void 0, function* () {
14816
14864
  (yield transceiver.getStats()).forEach((receiverStats) => {
14817
14865
  var _a;
14818
14866
  if (receiverStats.type === 'inbound-rtp') {
@@ -14829,7 +14877,11 @@ class MultistreamConnection extends EventEmitter$2 {
14829
14877
  });
14830
14878
  }
14831
14879
  attachMetricsObserver() {
14832
- rtcStats_1(this.pc.getUnderlyingRTCPeerConnection(), (data) => this.metricsCallback(data), 5000, (stats) => this.preProcessStats(stats));
14880
+ this.forceStatsReport = rtcStats_1(this.pc.getUnderlyingRTCPeerConnection(), (data) => this.metricsCallback(data), 5000, (stats) => this.preProcessStats(stats)).forceStatsReport;
14881
+ }
14882
+ forceRtcMetricsCallback() {
14883
+ var _a;
14884
+ return (_a = this.forceStatsReport) === null || _a === void 0 ? void 0 : _a.call(this);
14833
14885
  }
14834
14886
  setMetricsCallback(callback) {
14835
14887
  this.metricsCallback = callback;