@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/cjs/index.js CHANGED
@@ -1287,16 +1287,26 @@ class LocalTrack extends EventEmitter$2 {
1287
1287
  }
1288
1288
  return effect;
1289
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
+ }
1290
1298
  /**
1291
1299
  * Cleanup the local microphone track.
1292
1300
  */
1293
1301
  disposeEffects() {
1294
- if (this.effects.size > 0) {
1295
- this.effects.forEach((effect) => effect.dispose());
1296
- this.effects.clear();
1297
- this.underlyingStream = this.originalStream;
1298
- this.emit(exports.LocalTrackEvents.UnderlyingTrackChange);
1299
- }
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
+ });
1300
1310
  }
1301
1311
  /**
1302
1312
  * Apply constraints to the track.
@@ -5240,8 +5250,15 @@ function getFrameHeightByMaxFs(sourceAspectRatio, requestedMaxFs) {
5240
5250
  const minNumberRatiosForHeight = sourceAspectRatio[1] / _gcd;
5241
5251
  return (Math.floor(Math.sqrt((requestedMaxFs * 16 * 16) / (minNumberRatiosForWidth * minNumberRatiosForHeight))) * minNumberRatiosForHeight);
5242
5252
  }
5243
- function getScaleDownRatio(sourceAspectRatio, sourceHeight, requestedMaxFs) {
5244
- 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;
5245
5262
  }
5246
5263
  function getRecommendedMaxBitrateForFrameSize(requestedMaxFs) {
5247
5264
  if (requestedMaxFs < 60) {
@@ -9065,41 +9082,6 @@ class SendOnlyTransceiver extends Transceiver {
9065
9082
  }
9066
9083
  });
9067
9084
  }
9068
- updateSendState(requestedIdEncodingParamsMap) {
9069
- return __awaiter(this, void 0, void 0, function* () {
9070
- const sendParameters = this.sender.getParameters();
9071
- sendParameters.encodings.forEach((encoding, index) => {
9072
- const encodingParams = requestedIdEncodingParamsMap.get(index);
9073
- encoding.active = Boolean(encodingParams);
9074
- if (encodingParams) {
9075
- if (encodingParams.scaleDownRatio) {
9076
- encoding.scaleResolutionDownBy = encodingParams.scaleDownRatio;
9077
- }
9078
- if (encodingParams.maxPayloadBitsPerSecond) {
9079
- encoding.maxBitrate = encodingParams.maxPayloadBitsPerSecond;
9080
- }
9081
- }
9082
- });
9083
- yield this.sender.setParameters(sendParameters);
9084
- });
9085
- }
9086
- getScaleDownRatio(maxFs, maxWidth, maxHeight) {
9087
- var _a;
9088
- if (!this.publishedTrack || !maxFs) {
9089
- return undefined;
9090
- }
9091
- const setting = (_a = this.publishedTrack) === null || _a === void 0 ? void 0 : _a.underlyingTrack.getSettings();
9092
- const sourceHeight = setting === null || setting === void 0 ? void 0 : setting.height;
9093
- const sourceWidth = setting === null || setting === void 0 ? void 0 : setting.width;
9094
- if (!sourceWidth || !sourceHeight) {
9095
- return undefined;
9096
- }
9097
- let scaleDownRatio = getScaleDownRatio([sourceWidth, sourceHeight], sourceHeight, maxFs);
9098
- if (maxWidth && maxHeight) {
9099
- scaleDownRatio = Math.max(sourceWidth / maxWidth, sourceHeight / maxHeight, scaleDownRatio);
9100
- }
9101
- return scaleDownRatio;
9102
- }
9103
9085
  publishTrack(track) {
9104
9086
  return this.replacePublishedTrack(track);
9105
9087
  }
@@ -9114,6 +9096,25 @@ class SendOnlyTransceiver extends Transceiver {
9114
9096
  getStats() {
9115
9097
  return this.sender.getStats();
9116
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
+ }
9117
9118
  }
9118
9119
 
9119
9120
  class StatsManager {
@@ -9960,13 +9961,14 @@ class MultistreamConnection extends EventEmitter {
9960
9961
  updateRequestedStreams(mediaType, requests) {
9961
9962
  const sendTransceiver = this.getSendTransceiverOrThrow(mediaType);
9962
9963
  const signaler = this.streamSignalerManager.getEgressStreamSignalerOrThrow(sendTransceiver.mid);
9964
+ const mediaFamily = getMediaFamily(mediaType);
9963
9965
  const requestedIdEncodingParamsMap = new Map();
9964
9966
  const rsRequests = requests.filter((r) => isValidReceiverSelectedInfo(r.policySpecificInfo));
9965
9967
  if (rsRequests.length !== requests.length) {
9966
9968
  logger.warn('Ignoring non-receiver-selected requests');
9967
9969
  }
9968
9970
  rsRequests.forEach(({ ids, policySpecificInfo, codecInfos, maxPayloadBitsPerSecond }) => {
9969
- var _a, _b, _c;
9971
+ var _a, _b, _c, _d;
9970
9972
  if (ids.length > 1) {
9971
9973
  throw new Error(`More than a single ID being unexpected/invalid ${ids}`);
9972
9974
  }
@@ -9985,10 +9987,14 @@ class MultistreamConnection extends EventEmitter {
9985
9987
  if (streamIdsMatched) {
9986
9988
  const encodingIndex = signaler.getEncodingIndexForStreamId(id);
9987
9989
  if (encodingIndex !== -1) {
9988
- requestedIdEncodingParamsMap.set(encodingIndex, {
9989
- 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),
9990
- maxPayloadBitsPerSecond,
9991
- });
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);
9992
9998
  }
9993
9999
  else {
9994
10000
  logger.warn(`${mediaType}: Unable to get encoding index for stream ID: ${JSON.stringify(id)}`);
@@ -9999,7 +10005,7 @@ class MultistreamConnection extends EventEmitter {
9999
10005
  }
10000
10006
  });
10001
10007
  sendTransceiver.setTrackRequested(requestedIdEncodingParamsMap.size > 0);
10002
- sendTransceiver.updateSendState(requestedIdEncodingParamsMap);
10008
+ sendTransceiver.updateSendParameters(requestedIdEncodingParamsMap);
10003
10009
  }
10004
10010
  createDataChannel() {
10005
10011
  const dataChannel = this.pc.createDataChannel('datachannel', {});