@webex/web-client-media-engine 1.37.1 → 1.37.3

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
@@ -8773,17 +8773,25 @@ function setMaxBandwidth(parsedSdp, maxBandwidth) {
8773
8773
  mline.bandwidth = new BandwidthLine('TIAS', maxBandwidth);
8774
8774
  });
8775
8775
  }
8776
- function setupBundle(parsedSdp, bundlePolicy) {
8776
+ function setupBundle(parsedSdp, bundlePolicy, midMap) {
8777
8777
  if (bundlePolicy === 'max-compat') {
8778
- const audioMids = parsedSdp.avMedia
8779
- .filter((m) => m.type === 'audio')
8780
- .map((m) => m.mid);
8781
- const videoMids = parsedSdp.avMedia
8782
- .filter((m) => m.type === 'video')
8783
- .map((m) => m.mid);
8778
+ const audioMainMids = midMap.get(MediaType.AudioMain);
8779
+ const videoMainMids = midMap.get(MediaType.VideoMain);
8780
+ const audioContentMids = midMap.get(MediaType.AudioSlides);
8781
+ const videoContentMids = midMap.get(MediaType.VideoSlides);
8784
8782
  parsedSdp.session.groups.splice(0, parsedSdp.session.groups.length);
8785
- parsedSdp.session.groups.push(new BundleGroupLine(audioMids));
8786
- parsedSdp.session.groups.push(new BundleGroupLine(videoMids));
8783
+ if (audioMainMids) {
8784
+ parsedSdp.session.groups.push(new BundleGroupLine(audioMainMids));
8785
+ }
8786
+ if (videoMainMids) {
8787
+ parsedSdp.session.groups.push(new BundleGroupLine(videoMainMids));
8788
+ }
8789
+ if (audioContentMids) {
8790
+ parsedSdp.session.groups.push(new BundleGroupLine(audioContentMids));
8791
+ }
8792
+ if (videoContentMids) {
8793
+ parsedSdp.session.groups.push(new BundleGroupLine(videoContentMids));
8794
+ }
8787
8795
  }
8788
8796
  }
8789
8797
  function filterRecvOnlyMlines(parsedSdp) {
@@ -8883,6 +8891,18 @@ class SendOnlyTransceiver extends Transceiver {
8883
8891
  }
8884
8892
  });
8885
8893
  }
8894
+ replaceTransceiver(newRtcRtpTransceiver) {
8895
+ const _super = Object.create(null, {
8896
+ replaceTransceiver: { get: () => super.replaceTransceiver }
8897
+ });
8898
+ var _a;
8899
+ return __awaiter(this, void 0, void 0, function* () {
8900
+ _super.replaceTransceiver.call(this, newRtcRtpTransceiver);
8901
+ if (this.requested) {
8902
+ yield this.sender.replaceTrack(((_a = this.publishedTrack) === null || _a === void 0 ? void 0 : _a.underlyingTrack) || null);
8903
+ }
8904
+ });
8905
+ }
8886
8906
  replacePublishedTrack(newTrack) {
8887
8907
  var _a, _b;
8888
8908
  return __awaiter(this, void 0, void 0, function* () {
@@ -9575,6 +9595,8 @@ class MultistreamConnection extends EventEmitter {
9575
9595
  this.pendingJmpTasks = [];
9576
9596
  this.metricsCallback = () => { };
9577
9597
  this.overuseUpdateCallback = () => { };
9598
+ this.midMap = new Map();
9599
+ this.currentMid = 0;
9578
9600
  this.options = Object.assign(Object.assign({}, defaultMultistreamConnectionOptions), userOptions);
9579
9601
  logger.info(`Creating multistream connection with options ${JSON.stringify(this.options)}`);
9580
9602
  this.initializePeerConnection();
@@ -9593,6 +9615,16 @@ class MultistreamConnection extends EventEmitter {
9593
9615
  this.createSendTransceiver(MediaType.AudioSlides, contentSceneId);
9594
9616
  }
9595
9617
  }
9618
+ addMid(mediaType) {
9619
+ const mid = this.currentMid++;
9620
+ const mids = this.midMap.get(mediaType) || [];
9621
+ mids.push(`${mid}`);
9622
+ this.midMap.set(mediaType, mids);
9623
+ }
9624
+ clearMids() {
9625
+ this.midMap = new Map();
9626
+ this.currentMid = 0;
9627
+ }
9596
9628
  initializePeerConnection() {
9597
9629
  var _a;
9598
9630
  (_a = this.pc) === null || _a === void 0 ? void 0 : _a.close();
@@ -9621,6 +9653,7 @@ class MultistreamConnection extends EventEmitter {
9621
9653
  direction: 'sendrecv',
9622
9654
  sendEncodings: sendEncodingsOptions,
9623
9655
  });
9656
+ this.addMid(mediaType);
9624
9657
  const csi = generateCsi(getMediaFamily(mediaType), sceneId);
9625
9658
  this.sendTransceivers.set(mediaType, new SendOnlyTransceiver(rtcTransceiver, csi));
9626
9659
  this.createJmpSession(mediaType);
@@ -9825,29 +9858,39 @@ class MultistreamConnection extends EventEmitter {
9825
9858
  }
9826
9859
  }
9827
9860
  publishTrack(track) {
9828
- let mediaContent;
9829
- if (track instanceof LocalDisplayTrack && this.options.floorControlledPresentation) {
9830
- mediaContent = MediaContent.Slides;
9831
- }
9832
- else {
9833
- mediaContent = MediaContent.Main;
9834
- }
9835
- const mediaFamily = toMediaFamily(track.kind);
9836
- const mediaType = getMediaType(mediaFamily, mediaContent);
9837
- this.addTrackListeners(mediaType, track);
9838
- return this.getSendTransceiverOrThrow(mediaType).publishTrack(track);
9861
+ return __awaiter(this, void 0, void 0, function* () {
9862
+ let mediaContent;
9863
+ if (track instanceof LocalDisplayTrack && this.options.floorControlledPresentation) {
9864
+ mediaContent = MediaContent.Slides;
9865
+ }
9866
+ else {
9867
+ mediaContent = MediaContent.Main;
9868
+ }
9869
+ const mediaFamily = toMediaFamily(track.kind);
9870
+ const mediaType = getMediaType(mediaFamily, mediaContent);
9871
+ const sendTransceiver = this.getSendTransceiverOrThrow(mediaType);
9872
+ if (track === sendTransceiver.publishedTrack) {
9873
+ logger.warn(`This track has already been published on the transceiver.`);
9874
+ return Promise.resolve();
9875
+ }
9876
+ this.addTrackListeners(mediaType, track);
9877
+ return sendTransceiver.publishTrack(track);
9878
+ });
9839
9879
  }
9840
9880
  unpublishTrack(track) {
9841
- let mediaContent;
9842
- if (track instanceof LocalDisplayTrack && this.options.floorControlledPresentation) {
9843
- mediaContent = MediaContent.Slides;
9844
- }
9845
- else {
9846
- mediaContent = MediaContent.Main;
9847
- }
9848
- const mediaFamily = toMediaFamily(track.kind);
9849
- const mediaType = getMediaType(mediaFamily, mediaContent);
9850
- return this.getSendTransceiverOrThrow(mediaType).unpublishTrack();
9881
+ return __awaiter(this, void 0, void 0, function* () {
9882
+ let mediaContent;
9883
+ if (track instanceof LocalDisplayTrack && this.options.floorControlledPresentation) {
9884
+ mediaContent = MediaContent.Slides;
9885
+ }
9886
+ else {
9887
+ mediaContent = MediaContent.Main;
9888
+ }
9889
+ const mediaFamily = toMediaFamily(track.kind);
9890
+ const mediaType = getMediaType(mediaFamily, mediaContent);
9891
+ const sendTransceiver = this.getSendTransceiverOrThrow(mediaType);
9892
+ return sendTransceiver.unpublishTrack();
9893
+ });
9851
9894
  }
9852
9895
  addTrackListeners(mediaType, track) {
9853
9896
  const onTrackMute = (event) => {
@@ -9900,6 +9943,7 @@ class MultistreamConnection extends EventEmitter {
9900
9943
  const rtcRtpTransceiver = this.pc.addTransceiver(toMediaStreamTrackKind(mediaType), {
9901
9944
  direction: 'recvonly',
9902
9945
  });
9946
+ this.addMid(mediaType);
9903
9947
  const recvOnlyTransceiver = new ReceiveOnlyTransceiver(rtcRtpTransceiver, (mid) => {
9904
9948
  const ingressSignaler = this.streamSignalerManager.getIngressStreamSignaler(mid);
9905
9949
  if (!ingressSignaler) {
@@ -9963,6 +10007,9 @@ class MultistreamConnection extends EventEmitter {
9963
10007
  }
9964
10008
  createOffer() {
9965
10009
  return __awaiter(this, void 0, void 0, function* () {
10010
+ if (!this.pc.getLocalDescription()) {
10011
+ this.currentMid++;
10012
+ }
9966
10013
  return (this.pc
9967
10014
  .createOffer()
9968
10015
  .then((offer) => {
@@ -10022,7 +10069,7 @@ class MultistreamConnection extends EventEmitter {
10022
10069
  }
10023
10070
  });
10024
10071
  if (getBrowserDetails().name !== 'Firefox') {
10025
- setupBundle(parsed, this.options.bundlePolicy);
10072
+ setupBundle(parsed, this.options.bundlePolicy, this.midMap);
10026
10073
  }
10027
10074
  return parsed.toString();
10028
10075
  }
@@ -10057,7 +10104,7 @@ class MultistreamConnection extends EventEmitter {
10057
10104
  const parsedOffer = parse((_a = this.pc.getLocalDescription()) === null || _a === void 0 ? void 0 : _a.sdp);
10058
10105
  matchMlinesInAnswer(parsedOffer, parsedAnswer, this.streamSignalerManager);
10059
10106
  if (getBrowserDetails().name === 'Firefox') {
10060
- setupBundle(parsedAnswer, this.options.bundlePolicy);
10107
+ setupBundle(parsedAnswer, this.options.bundlePolicy, this.midMap);
10061
10108
  }
10062
10109
  return parsedAnswer.toString();
10063
10110
  }
@@ -10099,26 +10146,26 @@ class MultistreamConnection extends EventEmitter {
10099
10146
  this.options = Object.assign(Object.assign({}, defaultMultistreamConnectionOptions), userOptions);
10100
10147
  }
10101
10148
  logger.info(`Renewing multistream connection with options ${JSON.stringify(this.options)}`);
10149
+ this.clearMids();
10102
10150
  this.initializePeerConnection();
10103
10151
  this.streamSignalerManager = new StreamSignalerManager(this.options.streamSignalingMode);
10104
10152
  const mainSceneId = generateSceneId();
10105
10153
  this.sendTransceivers.forEach((transceiver, mediaType) => {
10106
10154
  var _a;
10155
+ this.addMid(mediaType);
10107
10156
  transceiver.replaceTransceiver(this.pc.addTransceiver(toMediaStreamTrackKind(mediaType), {
10108
10157
  direction: 'sendrecv',
10109
10158
  sendEncodings: getMediaFamily(mediaType) === MediaFamily.Video
10110
10159
  ? this.getVideoEncodingOptions()
10111
10160
  : undefined,
10112
10161
  }));
10113
- if (transceiver.publishedTrack) {
10114
- transceiver.publishTrack(transceiver.publishedTrack);
10115
- }
10116
10162
  transceiver.csi = generateCsi(getMediaFamily(mediaType), mainSceneId);
10117
10163
  (_a = this.jmpSessions.get(mediaType)) === null || _a === void 0 ? void 0 : _a.close();
10118
10164
  this.createJmpSession(mediaType);
10119
10165
  });
10120
10166
  this.recvTransceivers.forEach((transceivers, mediaType) => {
10121
10167
  transceivers.forEach((t) => {
10168
+ this.addMid(mediaType);
10122
10169
  t.replaceTransceiver(this.pc.addTransceiver(toMediaStreamTrackKind(mediaType), {
10123
10170
  direction: 'recvonly',
10124
10171
  }));