@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/cjs/index.js CHANGED
@@ -34,7 +34,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34
34
  PERFORMANCE OF THIS SOFTWARE.
35
35
  ***************************************************************************** */
36
36
 
37
- function __awaiter$1(thisArg, _arguments, P, generator) {
37
+ function __awaiter$2(thisArg, _arguments, P, generator) {
38
38
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39
39
  return new (P || (P = Promise))(function (resolve, reject) {
40
40
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -356,7 +356,7 @@ var DeviceKind;
356
356
  * media has successfully been obtained.
357
357
  */
358
358
  function getUserMedia(constraints) {
359
- return __awaiter$1(this, void 0, void 0, function* () {
359
+ return __awaiter$2(this, void 0, void 0, function* () {
360
360
  return navigator.mediaDevices.getUserMedia(constraints);
361
361
  });
362
362
  }
@@ -380,7 +380,7 @@ function getDisplayMedia(constraints) {
380
380
  * fulfilled.
381
381
  */
382
382
  function enumerateDevices() {
383
- return __awaiter$1(this, void 0, void 0, function* () {
383
+ return __awaiter$2(this, void 0, void 0, function* () {
384
384
  return navigator.mediaDevices.enumerateDevices();
385
385
  });
386
386
  }
@@ -402,7 +402,7 @@ function setOnDeviceChangeHandler$1(handler) {
402
402
  * @returns Array of Permission Status objects.
403
403
  */
404
404
  function checkNavigatorPermissions(deviceKinds) {
405
- return __awaiter$1(this, void 0, void 0, function* () {
405
+ return __awaiter$2(this, void 0, void 0, function* () {
406
406
  const permissionRequests = [];
407
407
  if (deviceKinds.includes(DeviceKind.VideoInput)) {
408
408
  permissionRequests.push(navigator.permissions.query({ name: 'camera' }));
@@ -420,7 +420,7 @@ function checkNavigatorPermissions(deviceKinds) {
420
420
  * @returns True if device permissions exist, false if otherwise.
421
421
  */
422
422
  function checkDevicePermissions(deviceKinds) {
423
- return __awaiter$1(this, void 0, void 0, function* () {
423
+ return __awaiter$2(this, void 0, void 0, function* () {
424
424
  try {
425
425
  const permissions = yield checkNavigatorPermissions(deviceKinds);
426
426
  if (permissions.every((permission) => permission.state === 'granted')) {
@@ -450,7 +450,7 @@ function checkDevicePermissions(deviceKinds) {
450
450
  * @returns The callback's response.
451
451
  */
452
452
  function ensureDevicePermissions(deviceKinds, callback) {
453
- return __awaiter$1(this, void 0, void 0, function* () {
453
+ return __awaiter$2(this, void 0, void 0, function* () {
454
454
  try {
455
455
  const hasDevicePermissions = yield checkDevicePermissions(deviceKinds);
456
456
  if (!hasDevicePermissions) {
@@ -517,7 +517,7 @@ class WcmeError {
517
517
  * @returns A LocalCameraStream object or an error.
518
518
  */
519
519
  function createCameraStream(constructor, constraints) {
520
- return __awaiter$1(this, void 0, void 0, function* () {
520
+ return __awaiter$2(this, void 0, void 0, function* () {
521
521
  let stream;
522
522
  try {
523
523
  stream = yield getUserMedia({ video: Object.assign({}, constraints) });
@@ -536,7 +536,7 @@ function createCameraStream(constructor, constraints) {
536
536
  * @returns A LocalMicrophoneStream object or an error.
537
537
  */
538
538
  function createMicrophoneStream(constructor, constraints) {
539
- return __awaiter$1(this, void 0, void 0, function* () {
539
+ return __awaiter$2(this, void 0, void 0, function* () {
540
540
  let stream;
541
541
  try {
542
542
  stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
@@ -555,7 +555,7 @@ function createMicrophoneStream(constructor, constraints) {
555
555
  * @returns A Promise that resolves to a LocalDisplayStream or an error.
556
556
  */
557
557
  function createDisplayStream(constructor, videoContentHint) {
558
- return __awaiter$1(this, void 0, void 0, function* () {
558
+ return __awaiter$2(this, void 0, void 0, function* () {
559
559
  let stream;
560
560
  try {
561
561
  stream = yield getDisplayMedia({ video: true });
@@ -581,7 +581,7 @@ function createDisplayStream(constructor, videoContentHint) {
581
581
  * instead.
582
582
  */
583
583
  function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStreamConstructor, videoContentHint) {
584
- return __awaiter$1(this, void 0, void 0, function* () {
584
+ return __awaiter$2(this, void 0, void 0, function* () {
585
585
  let stream;
586
586
  try {
587
587
  stream = yield getDisplayMedia({ video: true, audio: true });
@@ -609,7 +609,7 @@ function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStrea
609
609
  * @returns List of media devices in an array of MediaDeviceInfo objects.
610
610
  */
611
611
  function getDevices(deviceKind) {
612
- return __awaiter$1(this, void 0, void 0, function* () {
612
+ return __awaiter$2(this, void 0, void 0, function* () {
613
613
  let devices;
614
614
  try {
615
615
  devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
@@ -626,7 +626,7 @@ function getDevices(deviceKind) {
626
626
  * @returns List of microphone devices in an array of MediaDeviceInfo objects.
627
627
  */
628
628
  function getAudioInputDevices() {
629
- return __awaiter$1(this, void 0, void 0, function* () {
629
+ return __awaiter$2(this, void 0, void 0, function* () {
630
630
  return getDevices(DeviceKind.AudioInput);
631
631
  });
632
632
  }
@@ -636,7 +636,7 @@ function getAudioInputDevices() {
636
636
  * @returns List of speaker devices in an array of MediaDeviceInfo objects.
637
637
  */
638
638
  function getAudioOutputDevices() {
639
- return __awaiter$1(this, void 0, void 0, function* () {
639
+ return __awaiter$2(this, void 0, void 0, function* () {
640
640
  return getDevices(DeviceKind.AudioOutput);
641
641
  });
642
642
  }
@@ -646,7 +646,7 @@ function getAudioOutputDevices() {
646
646
  * @returns List of camera devices in an array of MediaDeviceInfo objects.
647
647
  */
648
648
  function getVideoInputDevices() {
649
- return __awaiter$1(this, void 0, void 0, function* () {
649
+ return __awaiter$2(this, void 0, void 0, function* () {
650
650
  return getDevices(DeviceKind.VideoInput);
651
651
  });
652
652
  }
@@ -1363,7 +1363,7 @@ class _LocalStream extends Stream {
1363
1363
  * @param effect - The effect to add.
1364
1364
  */
1365
1365
  addEffect(name, effect) {
1366
- return __awaiter$1(this, void 0, void 0, function* () {
1366
+ return __awaiter$2(this, void 0, void 0, function* () {
1367
1367
  // Load the effect
1368
1368
  this.loadingEffects.set(name, effect);
1369
1369
  const outputTrack = yield effect.load(this.outputTrack);
@@ -1414,7 +1414,7 @@ class _LocalStream extends Stream {
1414
1414
  * Cleanup the local effects.
1415
1415
  */
1416
1416
  disposeEffects() {
1417
- return __awaiter$1(this, void 0, void 0, function* () {
1417
+ return __awaiter$2(this, void 0, void 0, function* () {
1418
1418
  this.loadingEffects.clear();
1419
1419
  // Dispose of any effects currently in use
1420
1420
  if (this.effects.length > 0) {
@@ -1439,7 +1439,7 @@ class LocalAudioStream extends LocalStream {
1439
1439
  * @returns A promise which resolves when the constraints have been successfully applied.
1440
1440
  */
1441
1441
  applyConstraints(constraints) {
1442
- return __awaiter$1(this, void 0, void 0, function* () {
1442
+ return __awaiter$2(this, void 0, void 0, function* () {
1443
1443
  logger$3.log(`Applying constraints to local track:`, constraints);
1444
1444
  return this.inputTrack.applyConstraints(constraints).then(() => {
1445
1445
  this[exports.LocalStreamEventNames.ConstraintsChange].emit();
@@ -1459,7 +1459,7 @@ class LocalVideoStream extends LocalStream {
1459
1459
  * @returns A promise which resolves when the constraints have been successfully applied.
1460
1460
  */
1461
1461
  applyConstraints(constraints) {
1462
- return __awaiter$1(this, void 0, void 0, function* () {
1462
+ return __awaiter$2(this, void 0, void 0, function* () {
1463
1463
  logger$3.log(`Applying constraints to local track:`, constraints);
1464
1464
  return this.inputTrack.applyConstraints(constraints).then(() => {
1465
1465
  this[exports.LocalStreamEventNames.ConstraintsChange].emit();
@@ -5714,7 +5714,7 @@ class PeerConnection extends EventEmitter$4 {
5714
5714
  * other peer.
5715
5715
  */
5716
5716
  createAnswer(options) {
5717
- return __awaiter$1(this, void 0, void 0, function* () {
5717
+ return __awaiter$2(this, void 0, void 0, function* () {
5718
5718
  return this.pc.createAnswer(options);
5719
5719
  });
5720
5720
  }
@@ -5729,7 +5729,7 @@ class PeerConnection extends EventEmitter$4 {
5729
5729
  * That received offer should be delivered through the signaling server to a remote peer.
5730
5730
  */
5731
5731
  createOffer(options) {
5732
- return __awaiter$1(this, void 0, void 0, function* () {
5732
+ return __awaiter$2(this, void 0, void 0, function* () {
5733
5733
  return this.pc.createOffer(options);
5734
5734
  });
5735
5735
  }
@@ -5743,7 +5743,7 @@ class PeerConnection extends EventEmitter$4 {
5743
5743
  */
5744
5744
  setLocalDescription(description) {
5745
5745
  var _a;
5746
- return __awaiter$1(this, void 0, void 0, function* () {
5746
+ return __awaiter$2(this, void 0, void 0, function* () {
5747
5747
  // In Firefox, setLocalDescription will not throw an error if an m-line has no codecs, even
5748
5748
  // though it violates https://datatracker.ietf.org/doc/html/rfc8866. See
5749
5749
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1857612. So, we check the media lines here to
@@ -5768,7 +5768,7 @@ class PeerConnection extends EventEmitter$4 {
5768
5768
  * specified description is incompatible with one or both of the peers on the connection).
5769
5769
  */
5770
5770
  setRemoteDescription(description) {
5771
- return __awaiter$1(this, void 0, void 0, function* () {
5771
+ return __awaiter$2(this, void 0, void 0, function* () {
5772
5772
  return this.pc.setRemoteDescription(description);
5773
5773
  });
5774
5774
  }
@@ -5842,7 +5842,7 @@ class PeerConnection extends EventEmitter$4 {
5842
5842
  */
5843
5843
  getCurrentConnectionType() {
5844
5844
  var _a;
5845
- return __awaiter$1(this, void 0, void 0, function* () {
5845
+ return __awaiter$2(this, void 0, void 0, function* () {
5846
5846
  // make sure this method only can be called when the ice connection is established;
5847
5847
  const isIceConnected = this.pc.iceConnectionState === 'connected' || this.pc.iceConnectionState === 'completed';
5848
5848
  if (!isIceConnected) {
@@ -6982,7 +6982,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6982
6982
  PERFORMANCE OF THIS SOFTWARE.
6983
6983
  ***************************************************************************** */
6984
6984
 
6985
- function __awaiter(thisArg, _arguments, P, generator) {
6985
+ function __awaiter$1(thisArg, _arguments, P, generator) {
6986
6986
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6987
6987
  return new (P || (P = Promise))(function (resolve, reject) {
6988
6988
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -6994,6 +6994,42 @@ function __awaiter(thisArg, _arguments, P, generator) {
6994
6994
 
6995
6995
  var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6996
6996
 
6997
+ var __awaiter = (commonjsGlobal$1 && commonjsGlobal$1.__awaiter) || function (thisArg, _arguments, P, generator) {
6998
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6999
+ return new (P || (P = Promise))(function (resolve, reject) {
7000
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7001
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7002
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7003
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
7004
+ });
7005
+ };
7006
+ var __generator = (commonjsGlobal$1 && commonjsGlobal$1.__generator) || function (thisArg, body) {
7007
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
7008
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
7009
+ function verb(n) { return function (v) { return step([n, v]); }; }
7010
+ function step(op) {
7011
+ if (f) throw new TypeError("Generator is already executing.");
7012
+ while (_) try {
7013
+ 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;
7014
+ if (y = 0, t) op = [op[0] & 2, t.value];
7015
+ switch (op[0]) {
7016
+ case 0: case 1: t = op; break;
7017
+ case 4: _.label++; return { value: op[1], done: false };
7018
+ case 5: _.label++; y = op[1]; op = [0]; continue;
7019
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
7020
+ default:
7021
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
7022
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
7023
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
7024
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
7025
+ if (t[2]) _.ops.pop();
7026
+ _.trys.pop(); continue;
7027
+ }
7028
+ op = body.call(thisArg, _);
7029
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
7030
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7031
+ }
7032
+ };
6997
7033
  var rtcStats_1 = void 0;
6998
7034
  /**
6999
7035
  * Copies values of any nested depth.
@@ -7326,24 +7362,36 @@ var rtcStats = function (pc, logger, intervalTime, statsPreProcessor) {
7326
7362
  };
7327
7363
  navigator.mediaDevices.getDisplayMedia = gdm.bind(navigator.mediaDevices);
7328
7364
  }
7365
+ var getStatsReport = function () { return __awaiter(void 0, void 0, void 0, function () {
7366
+ return __generator(this, function (_a) {
7367
+ return [2 /*return*/, pc.getStats(null).then(function (res) {
7368
+ // Convert from stats report to js Map in order to have values set in `statsPreProcessor`
7369
+ var statsMap = new Map();
7370
+ res.forEach(function (stats, key) { return statsMap.set(key, stats); });
7371
+ return statsPreProcessor(statsMap).then(function () {
7372
+ var now = map2obj(statsMap);
7373
+ var base = deepCopy$1(now); // our new prev
7374
+ var compressed = deltaCompression(prev, now);
7375
+ trace('stats-report', formatStatsReport(compressed), compressed.timestamp !== -Infinity ? compressed.timestamp : undefined);
7376
+ prev = base;
7377
+ return Promise.resolve();
7378
+ });
7379
+ })];
7380
+ });
7381
+ }); };
7329
7382
  var interval = window.setInterval(function () {
7330
7383
  if (pc.signalingState === 'closed') {
7331
7384
  window.clearInterval(interval);
7332
7385
  return;
7333
7386
  }
7334
- pc.getStats(null).then(function (res) {
7335
- // Convert from stats report to js Map in order to have values set in `statsPreProcessor`
7336
- var statsMap = new Map();
7337
- res.forEach(function (stats, key) { return statsMap.set(key, stats); });
7338
- statsPreProcessor(statsMap).then(function () {
7339
- var now = map2obj(statsMap);
7340
- var base = deepCopy$1(now); // our new prev
7341
- var compressed = deltaCompression(prev, now);
7342
- trace('stats-report', formatStatsReport(compressed), compressed.timestamp !== -Infinity ? compressed.timestamp : undefined);
7343
- prev = base;
7344
- });
7345
- });
7387
+ getStatsReport();
7346
7388
  }, intervalTime);
7389
+ var forceStatsReport = function () { return __awaiter(void 0, void 0, void 0, function () {
7390
+ return __generator(this, function (_a) {
7391
+ return [2 /*return*/, getStatsReport()];
7392
+ });
7393
+ }); };
7394
+ return { forceStatsReport: forceStatsReport };
7347
7395
  };
7348
7396
  rtcStats_1 = rtcStats;
7349
7397
 
@@ -13795,7 +13843,7 @@ function waterfall (tasks, callback) {
13795
13843
  awaitify(waterfall);
13796
13844
 
13797
13845
  function processTasks(task, finishedCallback) {
13798
- return __awaiter(this, void 0, void 0, function* () {
13846
+ return __awaiter$1(this, void 0, void 0, function* () {
13799
13847
  try {
13800
13848
  yield task();
13801
13849
  finishedCallback();
@@ -13841,27 +13889,29 @@ class SendOnlyTransceiver extends Transceiver {
13841
13889
  this.mediaType = mediaType;
13842
13890
  }
13843
13891
  replaceSenderSource(stream) {
13844
- var _a;
13845
- return __awaiter(this, void 0, void 0, function* () {
13892
+ var _a, _b;
13893
+ return __awaiter$1(this, void 0, void 0, function* () {
13846
13894
  const trackOrNull = (_a = stream === null || stream === void 0 ? void 0 : stream.outputStream.getTracks()[0]) !== null && _a !== void 0 ? _a : null;
13847
- yield this.sender.replaceTrack(trackOrNull);
13848
- if (trackOrNull) {
13849
- logger.log(`Sender source for ${this.mediaType} replaced with track ID ${trackOrNull.id}`);
13850
- }
13851
- else {
13852
- logger.log(`Sender source for ${this.mediaType} set to null, sender stopped`);
13895
+ if (((_b = this.sender.track) === null || _b === void 0 ? void 0 : _b.id) !== (trackOrNull === null || trackOrNull === void 0 ? void 0 : trackOrNull.id)) {
13896
+ yield this.sender.replaceTrack(trackOrNull);
13897
+ if (trackOrNull) {
13898
+ logger.log(`Sender source for ${this.mediaType} replaced with track ID ${trackOrNull.id}`);
13899
+ }
13900
+ else {
13901
+ logger.log(`Sender source for ${this.mediaType} set to null, sender stopped`);
13902
+ }
13853
13903
  }
13854
13904
  });
13855
13905
  }
13856
13906
  handleTrackChange() {
13857
- return __awaiter(this, void 0, void 0, function* () {
13907
+ return __awaiter$1(this, void 0, void 0, function* () {
13858
13908
  if (this.requested) {
13859
13909
  yield this.replaceSenderSource(this.publishedStream);
13860
13910
  }
13861
13911
  });
13862
13912
  }
13863
13913
  handleStreamConstraintsChange() {
13864
- return __awaiter(this, void 0, void 0, function* () {
13914
+ return __awaiter$1(this, void 0, void 0, function* () {
13865
13915
  yield this.updateSendParameters(this.requestedIdEncodingParamsMap);
13866
13916
  });
13867
13917
  }
@@ -13875,7 +13925,7 @@ class SendOnlyTransceiver extends Transceiver {
13875
13925
  const _super = Object.create(null, {
13876
13926
  replaceTransceiver: { get: () => super.replaceTransceiver }
13877
13927
  });
13878
- return __awaiter(this, void 0, void 0, function* () {
13928
+ return __awaiter$1(this, void 0, void 0, function* () {
13879
13929
  _super.replaceTransceiver.call(this, newRtcRtpTransceiver);
13880
13930
  newRtcRtpTransceiver.direction = this.direction;
13881
13931
  if (this.requested) {
@@ -13884,7 +13934,7 @@ class SendOnlyTransceiver extends Transceiver {
13884
13934
  });
13885
13935
  }
13886
13936
  replacePublishedStream(newStream) {
13887
- return __awaiter(this, void 0, void 0, function* () {
13937
+ return __awaiter$1(this, void 0, void 0, function* () {
13888
13938
  const oldStream = this.publishedStream;
13889
13939
  oldStream === null || oldStream === void 0 ? void 0 : oldStream.off(exports.LocalStreamEventNames.OutputTrackChange, this.handleTrackChange);
13890
13940
  oldStream === null || oldStream === void 0 ? void 0 : oldStream.off(exports.LocalStreamEventNames.ConstraintsChange, this.handleStreamConstraintsChange);
@@ -13932,31 +13982,29 @@ class SendOnlyTransceiver extends Transceiver {
13932
13982
  return this.sender.getStats();
13933
13983
  }
13934
13984
  updateSendParameters(requestedIdEncodingParamsMap) {
13935
- return __awaiter(this, void 0, void 0, function* () {
13936
- return this.updateSendParametersQueue.push(() => __awaiter(this, void 0, void 0, function* () {
13937
- if (this.publishedStream) {
13938
- const requested = requestedIdEncodingParamsMap.size > 0;
13939
- if (this.requested !== requested) {
13940
- this.replaceSenderSource(requested ? this.publishedStream : null);
13941
- }
13942
- const sendParameters = this.sender.getParameters();
13943
- sendParameters.encodings.forEach((encoding, index) => {
13944
- var _a, _b;
13945
- const encodingParams = requestedIdEncodingParamsMap.get(index);
13946
- encoding.active = !!encodingParams;
13947
- if (encodingParams) {
13948
- const { maxPayloadBitsPerSecond, maxFs, maxWidth, maxHeight } = encodingParams;
13949
- 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);
13950
- if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
13951
- encoding.maxBitrate = maxPayloadBitsPerSecond;
13952
- }
13953
- if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
13954
- encoding.scaleResolutionDownBy = scaleDownRatio;
13955
- }
13956
- }
13957
- });
13958
- yield this.sender.setParameters(sendParameters);
13985
+ return __awaiter$1(this, void 0, void 0, function* () {
13986
+ return this.updateSendParametersQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
13987
+ const requested = requestedIdEncodingParamsMap.size > 0;
13988
+ if (this.requested !== requested) {
13989
+ yield this.replaceSenderSource(requested ? this.publishedStream : null);
13959
13990
  }
13991
+ const sendParameters = this.sender.getParameters();
13992
+ sendParameters.encodings.forEach((encoding, index) => {
13993
+ var _a, _b;
13994
+ const encodingParams = requestedIdEncodingParamsMap.get(index);
13995
+ encoding.active = !!encodingParams;
13996
+ if (encodingParams) {
13997
+ const { maxPayloadBitsPerSecond, maxFs, maxWidth, maxHeight } = encodingParams;
13998
+ 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);
13999
+ if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
14000
+ encoding.maxBitrate = maxPayloadBitsPerSecond;
14001
+ }
14002
+ if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
14003
+ encoding.scaleResolutionDownBy = scaleDownRatio;
14004
+ }
14005
+ }
14006
+ });
14007
+ yield this.sender.setParameters(sendParameters);
13960
14008
  this.requestedIdEncodingParamsMap = requestedIdEncodingParamsMap;
13961
14009
  }));
13962
14010
  });
@@ -14005,7 +14053,7 @@ class SendSlot {
14005
14053
  this.sendTransceiver = sendTransceiver;
14006
14054
  }
14007
14055
  publishStream(stream) {
14008
- return __awaiter(this, void 0, void 0, function* () {
14056
+ return __awaiter$1(this, void 0, void 0, function* () {
14009
14057
  if (stream === this.sendTransceiver.publishedStream) {
14010
14058
  return Promise.resolve();
14011
14059
  }
@@ -14013,7 +14061,7 @@ class SendSlot {
14013
14061
  });
14014
14062
  }
14015
14063
  unpublishStream() {
14016
- return __awaiter(this, void 0, void 0, function* () {
14064
+ return __awaiter$1(this, void 0, void 0, function* () {
14017
14065
  if (!this.sendTransceiver.publishedStream) {
14018
14066
  return Promise.resolve();
14019
14067
  }
@@ -14030,24 +14078,24 @@ class SendSlot {
14030
14078
  this.sendTransceiver.active = active;
14031
14079
  }
14032
14080
  setCodecParameters(parameters) {
14033
- return __awaiter(this, void 0, void 0, function* () {
14081
+ return __awaiter$1(this, void 0, void 0, function* () {
14034
14082
  this.sendTransceiver.setCodecParameters(parameters);
14035
14083
  });
14036
14084
  }
14037
14085
  deleteCodecParameters(parameters) {
14038
- return __awaiter(this, void 0, void 0, function* () {
14086
+ return __awaiter$1(this, void 0, void 0, function* () {
14039
14087
  this.sendTransceiver.deleteCodecParameters(parameters);
14040
14088
  });
14041
14089
  }
14042
14090
  }
14043
14091
 
14044
14092
  class StatsManager {
14045
- constructor(statsGetter, statsPreprocessor = () => __awaiter(this, void 0, void 0, function* () { })) {
14093
+ constructor(statsGetter, statsPreprocessor = () => __awaiter$1(this, void 0, void 0, function* () { })) {
14046
14094
  this.statsGetter = statsGetter;
14047
14095
  this.statsPreProcessor = statsPreprocessor;
14048
14096
  }
14049
14097
  getStats() {
14050
- return __awaiter(this, void 0, void 0, function* () {
14098
+ return __awaiter$1(this, void 0, void 0, function* () {
14051
14099
  const statsReport = yield this.statsGetter();
14052
14100
  const statsMap = new Map();
14053
14101
  statsReport.forEach((stats, key) => statsMap.set(key, stats));
@@ -14057,7 +14105,7 @@ class StatsManager {
14057
14105
  }
14058
14106
  }
14059
14107
 
14060
- const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __awaiter(void 0, void 0, void 0, function* () {
14108
+ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __awaiter$1(void 0, void 0, void 0, function* () {
14061
14109
  const result = {
14062
14110
  audio: {
14063
14111
  senders: [],
@@ -14076,7 +14124,7 @@ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __await
14076
14124
  receivers: [],
14077
14125
  },
14078
14126
  };
14079
- yield Promise.all([...sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter(void 0, void 0, void 0, function* () {
14127
+ yield Promise.all([...sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter$1(void 0, void 0, void 0, function* () {
14080
14128
  var _a;
14081
14129
  const item = {
14082
14130
  report: yield transceiver.getStats(),
@@ -14098,8 +14146,8 @@ const organizeTransceiverStats = (sendTransceivers, recvTransceivers) => __await
14098
14146
  result.screenShareVideo.senders.push(item);
14099
14147
  }
14100
14148
  })));
14101
- yield Promise.all([...recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter(void 0, void 0, void 0, function* () {
14102
- return Promise.all(transceivers.map((t) => __awaiter(void 0, void 0, void 0, function* () {
14149
+ yield Promise.all([...recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter$1(void 0, void 0, void 0, function* () {
14150
+ return Promise.all(transceivers.map((t) => __awaiter$1(void 0, void 0, void 0, function* () {
14103
14151
  var _b, _c;
14104
14152
  const item = {
14105
14153
  report: yield t.getStats(),
@@ -14480,9 +14528,9 @@ class MultistreamConnection extends EventEmitter$2 {
14480
14528
  });
14481
14529
  }
14482
14530
  createReceiveSlot(mediaType) {
14483
- return __awaiter(this, void 0, void 0, function* () {
14531
+ return __awaiter$1(this, void 0, void 0, function* () {
14484
14532
  return new Promise((createReceiveSlotResolve) => {
14485
- this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14533
+ this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14486
14534
  const rtcRtpTransceiver = this.pc.addTransceiver(toMediaStreamTrackKind(mediaType), {
14487
14535
  direction: 'recvonly',
14488
14536
  });
@@ -14533,7 +14581,7 @@ class MultistreamConnection extends EventEmitter$2 {
14533
14581
  return targetCodec.pt;
14534
14582
  }
14535
14583
  createOffer() {
14536
- return __awaiter(this, void 0, void 0, function* () {
14584
+ return __awaiter$1(this, void 0, void 0, function* () {
14537
14585
  if (!this.pc.getLocalDescription()) {
14538
14586
  this.midPredictor.allocateMidForDatachannel();
14539
14587
  }
@@ -14544,7 +14592,7 @@ class MultistreamConnection extends EventEmitter$2 {
14544
14592
  }
14545
14593
  const createOfferId = ++this.currentCreateOfferId;
14546
14594
  return new Promise((createOfferResolve, createOfferReject) => {
14547
- this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14595
+ this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14548
14596
  var _a;
14549
14597
  try {
14550
14598
  const offer = yield this.pc.createOffer();
@@ -14572,13 +14620,13 @@ class MultistreamConnection extends EventEmitter$2 {
14572
14620
  });
14573
14621
  }
14574
14622
  setAnswer(answer) {
14575
- return __awaiter(this, void 0, void 0, function* () {
14623
+ return __awaiter$1(this, void 0, void 0, function* () {
14576
14624
  const sdp = this.preProcessRemoteAnswer(answer);
14577
14625
  if (!this.setAnswerResolve) {
14578
14626
  throw new Error(`Call to setAnswer without having previously called createOffer`);
14579
14627
  }
14580
14628
  logger.info('calling this.pc.setRemoteDescription()');
14581
- return this.pc.setRemoteDescription({ type: 'answer', sdp }).then(() => __awaiter(this, void 0, void 0, function* () {
14629
+ return this.pc.setRemoteDescription({ type: 'answer', sdp }).then(() => __awaiter$1(this, void 0, void 0, function* () {
14582
14630
  logger.info('this.pc.setRemoteDescription() resolved');
14583
14631
  if (this.setAnswerResolve) {
14584
14632
  this.setAnswerResolve();
@@ -14592,7 +14640,7 @@ class MultistreamConnection extends EventEmitter$2 {
14592
14640
  }
14593
14641
  doLocalOfferAnswer() {
14594
14642
  var _a;
14595
- return __awaiter(this, void 0, void 0, function* () {
14643
+ return __awaiter$1(this, void 0, void 0, function* () {
14596
14644
  const offer = yield this.pc.createOffer();
14597
14645
  if (!offer.sdp) {
14598
14646
  throw new Error('No SDP offer');
@@ -14604,8 +14652,8 @@ class MultistreamConnection extends EventEmitter$2 {
14604
14652
  });
14605
14653
  }
14606
14654
  queueLocalOfferAnswer() {
14607
- return __awaiter(this, void 0, void 0, function* () {
14608
- return this.offerAnswerQueue.push(() => __awaiter(this, void 0, void 0, function* () {
14655
+ return __awaiter$1(this, void 0, void 0, function* () {
14656
+ return this.offerAnswerQueue.push(() => __awaiter$1(this, void 0, void 0, function* () {
14609
14657
  yield this.doLocalOfferAnswer();
14610
14658
  }));
14611
14659
  });
@@ -14788,13 +14836,13 @@ class MultistreamConnection extends EventEmitter$2 {
14788
14836
  return this.statsManager.getStats();
14789
14837
  }
14790
14838
  getTransceiverStats() {
14791
- return __awaiter(this, void 0, void 0, function* () {
14839
+ return __awaiter$1(this, void 0, void 0, function* () {
14792
14840
  return organizeTransceiverStats(this.sendTransceivers, this.recvTransceivers);
14793
14841
  });
14794
14842
  }
14795
14843
  preProcessStats(stats) {
14796
- return __awaiter(this, void 0, void 0, function* () {
14797
- yield Promise.all([...this.sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter(this, void 0, void 0, function* () {
14844
+ return __awaiter$1(this, void 0, void 0, function* () {
14845
+ yield Promise.all([...this.sendTransceivers.entries()].map(([mediaType, transceiver]) => __awaiter$1(this, void 0, void 0, function* () {
14798
14846
  (yield transceiver.getStats()).forEach((senderStats) => {
14799
14847
  var _a;
14800
14848
  if (senderStats.type === 'outbound-rtp') {
@@ -14815,8 +14863,8 @@ class MultistreamConnection extends EventEmitter$2 {
14815
14863
  }
14816
14864
  });
14817
14865
  })));
14818
- yield Promise.all([...this.recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter(this, void 0, void 0, function* () {
14819
- yield Promise.all(transceivers.map((transceiver) => __awaiter(this, void 0, void 0, function* () {
14866
+ yield Promise.all([...this.recvTransceivers.entries()].map(([mediaType, transceivers]) => __awaiter$1(this, void 0, void 0, function* () {
14867
+ yield Promise.all(transceivers.map((transceiver) => __awaiter$1(this, void 0, void 0, function* () {
14820
14868
  (yield transceiver.getStats()).forEach((receiverStats) => {
14821
14869
  var _a;
14822
14870
  if (receiverStats.type === 'inbound-rtp') {
@@ -14833,7 +14881,11 @@ class MultistreamConnection extends EventEmitter$2 {
14833
14881
  });
14834
14882
  }
14835
14883
  attachMetricsObserver() {
14836
- rtcStats_1(this.pc.getUnderlyingRTCPeerConnection(), (data) => this.metricsCallback(data), 5000, (stats) => this.preProcessStats(stats));
14884
+ this.forceStatsReport = rtcStats_1(this.pc.getUnderlyingRTCPeerConnection(), (data) => this.metricsCallback(data), 5000, (stats) => this.preProcessStats(stats)).forceStatsReport;
14885
+ }
14886
+ forceRtcMetricsCallback() {
14887
+ var _a;
14888
+ return (_a = this.forceStatsReport) === null || _a === void 0 ? void 0 : _a.call(this);
14837
14889
  }
14838
14890
  setMetricsCallback(callback) {
14839
14891
  this.metricsCallback = callback;