@webex/web-client-media-engine 1.40.8 → 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/esm/index.js CHANGED
@@ -1283,16 +1283,26 @@ class LocalTrack extends EventEmitter$2 {
1283
1283
  }
1284
1284
  return effect;
1285
1285
  }
1286
+ /**
1287
+ * Get a copy of the effects Map.
1288
+ *
1289
+ * @returns A copy of the effects map.
1290
+ */
1291
+ getEffects() {
1292
+ return new Map(this.effects);
1293
+ }
1286
1294
  /**
1287
1295
  * Cleanup the local microphone track.
1288
1296
  */
1289
1297
  disposeEffects() {
1290
- if (this.effects.size > 0) {
1291
- this.effects.forEach((effect) => effect.dispose());
1292
- this.effects.clear();
1293
- this.underlyingStream = this.originalStream;
1294
- this.emit(LocalTrackEvents.UnderlyingTrackChange);
1295
- }
1298
+ return __awaiter$1(this, void 0, void 0, function* () {
1299
+ if (this.effects.size > 0) {
1300
+ yield Promise.all(Array.from(this.effects.values(), (effect) => effect.dispose()));
1301
+ this.effects.clear();
1302
+ this.underlyingStream = this.originalStream;
1303
+ this.emit(LocalTrackEvents.UnderlyingTrackChange);
1304
+ }
1305
+ });
1296
1306
  }
1297
1307
  /**
1298
1308
  * Apply constraints to the track.
@@ -5236,8 +5246,15 @@ function getFrameHeightByMaxFs(sourceAspectRatio, requestedMaxFs) {
5236
5246
  const minNumberRatiosForHeight = sourceAspectRatio[1] / _gcd;
5237
5247
  return (Math.floor(Math.sqrt((requestedMaxFs * 16 * 16) / (minNumberRatiosForWidth * minNumberRatiosForHeight))) * minNumberRatiosForHeight);
5238
5248
  }
5239
- function getScaleDownRatio(sourceAspectRatio, sourceHeight, requestedMaxFs) {
5240
- return Math.max(sourceHeight / getFrameHeightByMaxFs(sourceAspectRatio, requestedMaxFs), 1.0);
5249
+ function getScaleDownRatio(sourceWidth, sourceHeight, maxFs, maxWidth, maxHeight) {
5250
+ if (!sourceWidth || !sourceHeight || !maxFs) {
5251
+ return undefined;
5252
+ }
5253
+ let scaleDownRatio = Math.max(sourceHeight / getFrameHeightByMaxFs([sourceWidth, sourceHeight], maxFs), 1.0);
5254
+ if (maxWidth && maxHeight) {
5255
+ scaleDownRatio = Math.max(sourceWidth / maxWidth, sourceHeight / maxHeight, scaleDownRatio);
5256
+ }
5257
+ return scaleDownRatio;
5241
5258
  }
5242
5259
  function getRecommendedMaxBitrateForFrameSize(requestedMaxFs) {
5243
5260
  if (requestedMaxFs < 60) {
@@ -9061,41 +9078,6 @@ class SendOnlyTransceiver extends Transceiver {
9061
9078
  }
9062
9079
  });
9063
9080
  }
9064
- updateSendState(requestedIdEncodingParamsMap) {
9065
- return __awaiter(this, void 0, void 0, function* () {
9066
- const sendParameters = this.sender.getParameters();
9067
- sendParameters.encodings.forEach((encoding, index) => {
9068
- const encodingParams = requestedIdEncodingParamsMap.get(index);
9069
- encoding.active = Boolean(encodingParams);
9070
- if (encodingParams) {
9071
- if (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 (!this.publishedTrack || !maxFs) {
9085
- return undefined;
9086
- }
9087
- const setting = (_a = this.publishedTrack) === null || _a === void 0 ? void 0 : _a.underlyingTrack.getSettings();
9088
- const sourceHeight = setting === null || setting === void 0 ? void 0 : setting.height;
9089
- const sourceWidth = setting === null || setting === void 0 ? void 0 : setting.width;
9090
- if (!sourceWidth || !sourceHeight) {
9091
- return undefined;
9092
- }
9093
- let scaleDownRatio = getScaleDownRatio([sourceWidth, sourceHeight], sourceHeight, maxFs);
9094
- if (maxWidth && maxHeight) {
9095
- scaleDownRatio = Math.max(sourceWidth / maxWidth, sourceHeight / maxHeight, scaleDownRatio);
9096
- }
9097
- return scaleDownRatio;
9098
- }
9099
9081
  publishTrack(track) {
9100
9082
  return this.replacePublishedTrack(track);
9101
9083
  }
@@ -9110,6 +9092,25 @@ class SendOnlyTransceiver extends Transceiver {
9110
9092
  getStats() {
9111
9093
  return this.sender.getStats();
9112
9094
  }
9095
+ updateSendParameters(requestedIdEncodingParamsMap) {
9096
+ return __awaiter(this, void 0, void 0, function* () {
9097
+ const sendParameters = this.sender.getParameters();
9098
+ sendParameters.encodings.forEach((encoding, index) => {
9099
+ const encodingParams = requestedIdEncodingParamsMap.get(index);
9100
+ encoding.active = !!encodingParams;
9101
+ if (encodingParams) {
9102
+ const { maxPayloadBitsPerSecond, scaleDownRatio } = encodingParams;
9103
+ if (maxPayloadBitsPerSecond !== undefined && maxPayloadBitsPerSecond >= 0) {
9104
+ encoding.maxBitrate = maxPayloadBitsPerSecond;
9105
+ }
9106
+ if (scaleDownRatio !== undefined && scaleDownRatio >= 1.0) {
9107
+ encoding.scaleResolutionDownBy = scaleDownRatio;
9108
+ }
9109
+ }
9110
+ });
9111
+ yield this.sender.setParameters(sendParameters);
9112
+ });
9113
+ }
9113
9114
  }
9114
9115
 
9115
9116
  class StatsManager {
@@ -9956,13 +9957,14 @@ class MultistreamConnection extends EventEmitter {
9956
9957
  updateRequestedStreams(mediaType, requests) {
9957
9958
  const sendTransceiver = this.getSendTransceiverOrThrow(mediaType);
9958
9959
  const signaler = this.streamSignalerManager.getEgressStreamSignalerOrThrow(sendTransceiver.mid);
9960
+ const mediaFamily = getMediaFamily(mediaType);
9959
9961
  const requestedIdEncodingParamsMap = new Map();
9960
9962
  const rsRequests = requests.filter((r) => isValidReceiverSelectedInfo(r.policySpecificInfo));
9961
9963
  if (rsRequests.length !== requests.length) {
9962
9964
  logger.warn('Ignoring non-receiver-selected requests');
9963
9965
  }
9964
9966
  rsRequests.forEach(({ ids, policySpecificInfo, codecInfos, maxPayloadBitsPerSecond }) => {
9965
- var _a, _b, _c;
9967
+ var _a, _b, _c, _d;
9966
9968
  if (ids.length > 1) {
9967
9969
  throw new Error(`More than a single ID being unexpected/invalid ${ids}`);
9968
9970
  }
@@ -9981,10 +9983,14 @@ class MultistreamConnection extends EventEmitter {
9981
9983
  if (streamIdsMatched) {
9982
9984
  const encodingIndex = signaler.getEncodingIndexForStreamId(id);
9983
9985
  if (encodingIndex !== -1) {
9984
- requestedIdEncodingParamsMap.set(encodingIndex, {
9985
- 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),
9986
- maxPayloadBitsPerSecond,
9987
- });
9986
+ const encodingParams = { maxPayloadBitsPerSecond };
9987
+ if (mediaFamily === MediaFamily.Video) {
9988
+ const trackSettings = (_a = sendTransceiver.publishedTrack) === null || _a === void 0 ? void 0 : _a.getSettings();
9989
+ if (trackSettings) {
9990
+ 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);
9991
+ }
9992
+ }
9993
+ requestedIdEncodingParamsMap.set(encodingIndex, encodingParams);
9988
9994
  }
9989
9995
  else {
9990
9996
  logger.warn(`${mediaType}: Unable to get encoding index for stream ID: ${JSON.stringify(id)}`);
@@ -9995,7 +10001,7 @@ class MultistreamConnection extends EventEmitter {
9995
10001
  }
9996
10002
  });
9997
10003
  sendTransceiver.setTrackRequested(requestedIdEncodingParamsMap.size > 0);
9998
- sendTransceiver.updateSendState(requestedIdEncodingParamsMap);
10004
+ sendTransceiver.updateSendParameters(requestedIdEncodingParamsMap);
9999
10005
  }
10000
10006
  createDataChannel() {
10001
10007
  const dataChannel = this.pc.createDataChannel('datachannel', {});