@stream-io/video-client 1.11.3 → 1.11.4

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/index.cjs.js CHANGED
@@ -3356,7 +3356,7 @@ const retryable = async (rpc, signal) => {
3356
3356
  return result;
3357
3357
  };
3358
3358
 
3359
- const version = "1.11.3";
3359
+ const version = "1.11.4";
3360
3360
  const [major, minor, patch] = version.split('.');
3361
3361
  let sdkInfo = {
3362
3362
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -3491,7 +3491,7 @@ const getPreferredCodecs = (kind, preferredCodec, codecToRemove) => {
3491
3491
  continue;
3492
3492
  }
3493
3493
  const sdpFmtpLine = codec.sdpFmtpLine;
3494
- if (!sdpFmtpLine || !sdpFmtpLine.includes('profile-level-id=42e01f')) {
3494
+ if (!sdpFmtpLine || !sdpFmtpLine.includes('profile-level-id=42')) {
3495
3495
  // this is not the baseline h264 codec, prioritize it lower
3496
3496
  partiallyPreferred.push(codec);
3497
3497
  continue;
@@ -5518,6 +5518,50 @@ const toggleDtx = (sdp, enable) => {
5518
5518
  : `${opusFmtp.original};${requiredDtxConfig}`;
5519
5519
  return sdp.replace(opusFmtp.original, newFmtp);
5520
5520
  };
5521
+ /**
5522
+ * Returns and SDP with all the codecs except the given codec removed.
5523
+ */
5524
+ const preserveCodec = (sdp, mid, codec) => {
5525
+ const [kind, codecName] = codec.mimeType.toLowerCase().split('/');
5526
+ const toSet = (fmtpLine) => new Set(fmtpLine.split(';').map((f) => f.trim().toLowerCase()));
5527
+ const equal = (a, b) => {
5528
+ if (a.size !== b.size)
5529
+ return false;
5530
+ for (const item of a)
5531
+ if (!b.has(item))
5532
+ return false;
5533
+ return true;
5534
+ };
5535
+ const codecFmtp = toSet(codec.sdpFmtpLine || '');
5536
+ const parsedSdp = SDP__namespace.parse(sdp);
5537
+ for (const media of parsedSdp.media) {
5538
+ if (media.type !== kind || String(media.mid) !== mid)
5539
+ continue;
5540
+ // find the payload id of the desired codec
5541
+ const payloads = new Set();
5542
+ for (const rtp of media.rtp) {
5543
+ if (rtp.codec.toLowerCase() === codecName &&
5544
+ media.fmtp.some((f) => f.payload === rtp.payload && equal(toSet(f.config), codecFmtp))) {
5545
+ payloads.add(rtp.payload);
5546
+ }
5547
+ }
5548
+ // find the corresponding rtx codec by matching apt=<preserved-codec-payload>
5549
+ for (const fmtp of media.fmtp) {
5550
+ const match = fmtp.config.match(/(apt)=(\d+)/);
5551
+ if (!match)
5552
+ continue;
5553
+ const [, , preservedCodecPayload] = match;
5554
+ if (payloads.has(Number(preservedCodecPayload))) {
5555
+ payloads.add(fmtp.payload);
5556
+ }
5557
+ }
5558
+ media.rtp = media.rtp.filter((r) => payloads.has(r.payload));
5559
+ media.fmtp = media.fmtp.filter((f) => payloads.has(f.payload));
5560
+ media.rtcpFb = media.rtcpFb?.filter((f) => payloads.has(f.payload));
5561
+ media.payloads = Array.from(payloads).join(' ');
5562
+ }
5563
+ return SDP__namespace.write(parsedSdp);
5564
+ };
5521
5565
  /**
5522
5566
  * Enables high-quality audio through SDP munging for the given trackMid.
5523
5567
  *
@@ -5921,6 +5965,12 @@ class Publisher {
5921
5965
  if (this.isPublishing(TrackType.SCREEN_SHARE_AUDIO)) {
5922
5966
  offer.sdp = this.enableHighQualityAudio(offer.sdp);
5923
5967
  }
5968
+ if (this.isPublishing(TrackType.VIDEO)) {
5969
+ // Hotfix for platforms that don't respect the ordered codec list
5970
+ // (Firefox, Android, Linux, etc...).
5971
+ // We remove all the codecs from the SDP except the one we want to use.
5972
+ offer.sdp = this.removeUnpreferredCodecs(offer.sdp, TrackType.VIDEO);
5973
+ }
5924
5974
  }
5925
5975
  const trackInfos = this.getAnnouncedTracks(offer.sdp);
5926
5976
  if (trackInfos.length === 0) {
@@ -6082,6 +6132,22 @@ class Publisher {
6082
6132
  });
6083
6133
  });
6084
6134
  }
6135
+ removeUnpreferredCodecs(sdp, trackType) {
6136
+ const opts = this.publishOptsForTrack.get(trackType);
6137
+ if (!opts || !opts.forceSingleCodec)
6138
+ return sdp;
6139
+ const codec = opts.forceCodec || opts.preferredCodec;
6140
+ const orderedCodecs = this.getCodecPreferences(trackType, codec);
6141
+ if (!orderedCodecs || orderedCodecs.length === 0)
6142
+ return sdp;
6143
+ const transceiver = this.transceiverCache.get(trackType);
6144
+ if (!transceiver)
6145
+ return sdp;
6146
+ const index = this.transceiverInitOrder.indexOf(trackType);
6147
+ const mid = extractMid(transceiver, index, sdp);
6148
+ const [codecToPreserve] = orderedCodecs;
6149
+ return preserveCodec(sdp, mid, codecToPreserve);
6150
+ }
6085
6151
  }
6086
6152
 
6087
6153
  /**
@@ -12997,7 +13063,7 @@ class StreamClient {
12997
13063
  });
12998
13064
  };
12999
13065
  this.getUserAgent = () => {
13000
- const version = "1.11.3";
13066
+ const version = "1.11.4";
13001
13067
  return (this.userAgent ||
13002
13068
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
13003
13069
  };