@webex/web-client-media-engine 1.40.7 → 1.41.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
@@ -19,7 +19,7 @@ function _mergeNamespaces$1(n, m) {
19
19
  return Object.freeze(n);
20
20
  }
21
21
 
22
- /*! *****************************************************************************
22
+ /******************************************************************************
23
23
  Copyright (c) Microsoft Corporation.
24
24
 
25
25
  Permission to use, copy, modify, and/or distribute this software for any
@@ -332,8 +332,13 @@ var Logger$2 = logger$1$1.exports;
332
332
 
333
333
  const DEFAULT_LOGGER_NAME$1 = 'webrtc-core';
334
334
  const logger$3 = Logger$2.get(DEFAULT_LOGGER_NAME$1);
335
- // Set log level to debug by default.
336
- logger$3.setLevel(Logger$2.DEBUG);
335
+ Logger$2.useDefaults({
336
+ defaultLevel: Logger$2.DEBUG,
337
+ /* eslint-disable-next-line jsdoc/require-jsdoc */
338
+ formatter: (messages, context) => {
339
+ messages.unshift(`[${context.name}]`);
340
+ },
341
+ });
337
342
 
338
343
  var DeviceKind;
339
344
  (function (DeviceKind) {
@@ -1282,16 +1287,26 @@ class LocalTrack extends EventEmitter$2 {
1282
1287
  }
1283
1288
  return effect;
1284
1289
  }
1290
+ /**
1291
+ * Get a copy of the effects Map.
1292
+ *
1293
+ * @returns A copy of the effects map.
1294
+ */
1295
+ getEffects() {
1296
+ return new Map(this.effects);
1297
+ }
1285
1298
  /**
1286
1299
  * Cleanup the local microphone track.
1287
1300
  */
1288
1301
  disposeEffects() {
1289
- if (this.effects.size > 0) {
1290
- this.effects.forEach((effect) => effect.dispose());
1291
- this.effects.clear();
1292
- this.underlyingStream = this.originalStream;
1293
- this.emit(exports.LocalTrackEvents.UnderlyingTrackChange);
1294
- }
1302
+ return __awaiter$1(this, void 0, void 0, function* () {
1303
+ if (this.effects.size > 0) {
1304
+ yield Promise.all(Array.from(this.effects.values(), (effect) => effect.dispose()));
1305
+ this.effects.clear();
1306
+ this.underlyingStream = this.originalStream;
1307
+ this.emit(exports.LocalTrackEvents.UnderlyingTrackChange);
1308
+ }
1309
+ });
1295
1310
  }
1296
1311
  /**
1297
1312
  * Apply constraints to the track.
@@ -5235,8 +5250,15 @@ function getFrameHeightByMaxFs(sourceAspectRatio, requestedMaxFs) {
5235
5250
  const minNumberRatiosForHeight = sourceAspectRatio[1] / _gcd;
5236
5251
  return (Math.floor(Math.sqrt((requestedMaxFs * 16 * 16) / (minNumberRatiosForWidth * minNumberRatiosForHeight))) * minNumberRatiosForHeight);
5237
5252
  }
5238
- function getScaleDownRatio(sourceAspectRatio, sourceHeight, requestedMaxFs) {
5239
- return Math.max(sourceHeight / getFrameHeightByMaxFs(sourceAspectRatio, requestedMaxFs), 1.0);
5253
+ function getScaleDownRatio(sourceWidth, sourceHeight, maxFs, maxWidth, maxHeight) {
5254
+ if (!sourceWidth || !sourceHeight || !maxFs) {
5255
+ return undefined;
5256
+ }
5257
+ let scaleDownRatio = Math.max(sourceHeight / getFrameHeightByMaxFs([sourceWidth, sourceHeight], maxFs), 1.0);
5258
+ if (maxWidth && maxHeight) {
5259
+ scaleDownRatio = Math.max(sourceWidth / maxWidth, sourceHeight / maxHeight, scaleDownRatio);
5260
+ }
5261
+ return scaleDownRatio;
5240
5262
  }
5241
5263
  function getRecommendedMaxBitrateForFrameSize(requestedMaxFs) {
5242
5264
  if (requestedMaxFs < 60) {
@@ -9060,45 +9082,6 @@ class SendOnlyTransceiver extends Transceiver {
9060
9082
  }
9061
9083
  });
9062
9084
  }
9063
- updateSimulcastStreamStates(requestedIdEncodingParamsMap) {
9064
- return __awaiter(this, void 0, void 0, function* () {
9065
- const sendParameters = this.sender.getParameters();
9066
- sendParameters.encodings.forEach((encoding, index) => {
9067
- const encodingParams = requestedIdEncodingParamsMap.get(index);
9068
- encoding.active = Boolean(encodingParams);
9069
- if (encodingParams) {
9070
- if (encodingParams.scaleDownRatio >= 1 &&
9071
- encoding.scaleResolutionDownBy !== encodingParams.scaleDownRatio) {
9072
- encoding.scaleResolutionDownBy = encodingParams.scaleDownRatio;
9073
- }
9074
- if (encodingParams.maxPayloadBitsPerSecond) {
9075
- encoding.maxBitrate = encodingParams.maxPayloadBitsPerSecond;
9076
- }
9077
- }
9078
- });
9079
- yield this.sender.setParameters(sendParameters);
9080
- });
9081
- }
9082
- getScaleDownRatio(maxFs, maxWidth, maxHeight) {
9083
- var _a;
9084
- if (!maxFs) {
9085
- return -1;
9086
- }
9087
- if (!this.publishedTrack) {
9088
- return -1;
9089
- }
9090
- const setting = (_a = this.publishedTrack) === null || _a === void 0 ? void 0 : _a.underlyingTrack.getSettings();
9091
- const sourceHeight = setting === null || setting === void 0 ? void 0 : setting.height;
9092
- const sourceWidth = setting === null || setting === void 0 ? void 0 : setting.width;
9093
- if (!sourceWidth || !sourceHeight) {
9094
- return -1;
9095
- }
9096
- let scaleDownRatio = getScaleDownRatio([sourceWidth, sourceHeight], sourceHeight, maxFs);
9097
- if (maxWidth && maxHeight) {
9098
- scaleDownRatio = Math.max(sourceWidth / maxWidth, sourceHeight / maxHeight, scaleDownRatio);
9099
- }
9100
- return scaleDownRatio;
9101
- }
9102
9085
  publishTrack(track) {
9103
9086
  return this.replacePublishedTrack(track);
9104
9087
  }
@@ -9113,6 +9096,25 @@ class SendOnlyTransceiver extends Transceiver {
9113
9096
  getStats() {
9114
9097
  return this.sender.getStats();
9115
9098
  }
9099
+ updateSendParameters(requestedIdEncodingParamsMap) {
9100
+ return __awaiter(this, void 0, void 0, function* () {
9101
+ const sendParameters = this.sender.getParameters();
9102
+ sendParameters.encodings.forEach((encoding, index) => {
9103
+ const encodingParams = requestedIdEncodingParamsMap.get(index);
9104
+ encoding.active = !!encodingParams;
9105
+ if (encodingParams) {
9106
+ const { maxPayloadBitsPerSecond, scaleDownRatio } = encodingParams;
9107
+ if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
9108
+ encoding.maxBitrate = maxPayloadBitsPerSecond;
9109
+ }
9110
+ if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
9111
+ encoding.scaleResolutionDownBy = scaleDownRatio;
9112
+ }
9113
+ }
9114
+ });
9115
+ yield this.sender.setParameters(sendParameters);
9116
+ });
9117
+ }
9116
9118
  }
9117
9119
 
9118
9120
  class StatsManager {
@@ -9733,6 +9735,7 @@ logger.setLevel(Logger.DEBUG);
9733
9735
  function setLogLevel(level) {
9734
9736
  logger.setLevel(level);
9735
9737
  Logger$1.setLevel(level);
9738
+ Logger$2.setLevel(level);
9736
9739
  }
9737
9740
  function getLogLevel() {
9738
9741
  return logger.getLevel();
@@ -9740,6 +9743,7 @@ function getLogLevel() {
9740
9743
  function setLogHandler(logHandler) {
9741
9744
  Logger.setHandler(logHandler);
9742
9745
  Logger$1.setHandler(logHandler);
9746
+ Logger$2.setHandler(logHandler);
9743
9747
  }
9744
9748
 
9745
9749
  function toMediaStreamTrackKind(mediaType) {
@@ -9957,13 +9961,14 @@ class MultistreamConnection extends EventEmitter {
9957
9961
  updateRequestedStreams(mediaType, requests) {
9958
9962
  const sendTransceiver = this.getSendTransceiverOrThrow(mediaType);
9959
9963
  const signaler = this.streamSignalerManager.getEgressStreamSignalerOrThrow(sendTransceiver.mid);
9964
+ const mediaFamily = getMediaFamily(mediaType);
9960
9965
  const requestedIdEncodingParamsMap = new Map();
9961
9966
  const rsRequests = requests.filter((r) => isValidReceiverSelectedInfo(r.policySpecificInfo));
9962
9967
  if (rsRequests.length !== requests.length) {
9963
9968
  logger.warn('Ignoring non-receiver-selected requests');
9964
9969
  }
9965
9970
  rsRequests.forEach(({ ids, policySpecificInfo, codecInfos, maxPayloadBitsPerSecond }) => {
9966
- var _a, _b, _c;
9971
+ var _a, _b, _c, _d;
9967
9972
  if (ids.length > 1) {
9968
9973
  throw new Error(`More than a single ID being unexpected/invalid ${ids}`);
9969
9974
  }
@@ -9982,10 +9987,14 @@ class MultistreamConnection extends EventEmitter {
9982
9987
  if (streamIdsMatched) {
9983
9988
  const encodingIndex = signaler.getEncodingIndexForStreamId(id);
9984
9989
  if (encodingIndex !== -1) {
9985
- requestedIdEncodingParamsMap.set(encodingIndex, {
9986
- scaleDownRatio: sendTransceiver.getScaleDownRatio((_a = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _a === void 0 ? void 0 : _a.maxFs, (_b = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _b === void 0 ? void 0 : _b.maxWidth, (_c = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _c === void 0 ? void 0 : _c.maxHeight),
9987
- maxPayloadBitsPerSecond,
9988
- });
9990
+ const encodingParams = { maxPayloadBitsPerSecond };
9991
+ if (mediaFamily === MediaFamily.Video) {
9992
+ const trackSettings = (_a = sendTransceiver.publishedTrack) === null || _a === void 0 ? void 0 : _a.getSettings();
9993
+ if (trackSettings) {
9994
+ encodingParams.scaleDownRatio = getScaleDownRatio(trackSettings.width, trackSettings.height, (_b = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _b === void 0 ? void 0 : _b.maxFs, (_c = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _c === void 0 ? void 0 : _c.maxWidth, (_d = codecInfo === null || codecInfo === void 0 ? void 0 : codecInfo.h264) === null || _d === void 0 ? void 0 : _d.maxHeight);
9995
+ }
9996
+ }
9997
+ requestedIdEncodingParamsMap.set(encodingIndex, encodingParams);
9989
9998
  }
9990
9999
  else {
9991
10000
  logger.warn(`${mediaType}: Unable to get encoding index for stream ID: ${JSON.stringify(id)}`);
@@ -9996,9 +10005,7 @@ class MultistreamConnection extends EventEmitter {
9996
10005
  }
9997
10006
  });
9998
10007
  sendTransceiver.setTrackRequested(requestedIdEncodingParamsMap.size > 0);
9999
- if (getMediaFamily(mediaType) === MediaFamily.Video) {
10000
- sendTransceiver.updateSimulcastStreamStates(requestedIdEncodingParamsMap);
10001
- }
10008
+ sendTransceiver.updateSendParameters(requestedIdEncodingParamsMap);
10002
10009
  }
10003
10010
  createDataChannel() {
10004
10011
  const dataChannel = this.pc.createDataChannel('datachannel', {});