livekit-client 1.2.0 → 1.2.1

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.
@@ -10265,7 +10265,7 @@ function computeBitrate(currentStats, prevStats) {
10265
10265
  return (bytesNow - bytesPrev) * 8 * 1000 / (currentStats.timestamp - prevStats.timestamp);
10266
10266
  }
10267
10267
 
10268
- var version$1 = "1.2.0";
10268
+ var version$1 = "1.2.1";
10269
10269
 
10270
10270
  const version = version$1;
10271
10271
  const protocolVersion = 8;
@@ -13455,7 +13455,7 @@ function computeVideoEncodings(isScreenShare, width, height, options) {
13455
13455
  encodings.push({
13456
13456
  rid: videoRids[2 - i],
13457
13457
  scaleResolutionDownBy: 2 ** i,
13458
- maxBitrate: videoEncoding ? videoEncoding.maxBitrate / 2 ** i : 0,
13458
+ maxBitrate: videoEncoding ? videoEncoding.maxBitrate / 3 ** i : 0,
13459
13459
 
13460
13460
  /* @ts-ignore */
13461
13461
  maxFramerate: original.encoding.maxFramerate,
@@ -14314,8 +14314,8 @@ class LocalParticipant extends Participant {
14314
14314
  */
14315
14315
 
14316
14316
 
14317
- setCameraEnabled(enabled, options) {
14318
- return this.setTrackEnabled(Track.Source.Camera, enabled, options);
14317
+ setCameraEnabled(enabled, options, publishOptions) {
14318
+ return this.setTrackEnabled(Track.Source.Camera, enabled, options, publishOptions);
14319
14319
  }
14320
14320
  /**
14321
14321
  * Enable or disable a participant's microphone track.
@@ -14325,8 +14325,8 @@ class LocalParticipant extends Participant {
14325
14325
  */
14326
14326
 
14327
14327
 
14328
- setMicrophoneEnabled(enabled, options) {
14329
- return this.setTrackEnabled(Track.Source.Microphone, enabled, options);
14328
+ setMicrophoneEnabled(enabled, options, publishOptions) {
14329
+ return this.setTrackEnabled(Track.Source.Microphone, enabled, options, publishOptions);
14330
14330
  }
14331
14331
  /**
14332
14332
  * Start or stop sharing a participant's screen
@@ -14334,8 +14334,8 @@ class LocalParticipant extends Participant {
14334
14334
  */
14335
14335
 
14336
14336
 
14337
- setScreenShareEnabled(enabled, options) {
14338
- return this.setTrackEnabled(Track.Source.ScreenShare, enabled, options);
14337
+ setScreenShareEnabled(enabled, options, publishOptions) {
14338
+ return this.setTrackEnabled(Track.Source.ScreenShare, enabled, options, publishOptions);
14339
14339
  }
14340
14340
  /** @internal */
14341
14341
 
@@ -14351,7 +14351,7 @@ class LocalParticipant extends Participant {
14351
14351
  return changed;
14352
14352
  }
14353
14353
 
14354
- async setTrackEnabled(source, enabled, options) {
14354
+ async setTrackEnabled(source, enabled, options, publishOptions) {
14355
14355
  var _a, _b;
14356
14356
 
14357
14357
  livekitLogger.debug('setTrackEnabled', {
@@ -14401,7 +14401,7 @@ class LocalParticipant extends Participant {
14401
14401
  const publishPromises = [];
14402
14402
 
14403
14403
  for (const localTrack of localTracks) {
14404
- publishPromises.push(this.publishTrack(localTrack));
14404
+ publishPromises.push(this.publishTrack(localTrack, publishOptions));
14405
14405
  }
14406
14406
 
14407
14407
  const publishedTracks = await Promise.all(publishPromises); // for screen share publications including audio, this will only return the screen share publication, not the screen share audio one
@@ -14581,7 +14581,7 @@ class LocalParticipant extends Participant {
14581
14581
 
14582
14582
 
14583
14583
  async publishTrack(track, options) {
14584
- var _a, _b, _c, _d, _e, _f, _g;
14584
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14585
14585
 
14586
14586
  const opts = _objectSpread2(_objectSpread2({}, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.publishDefaults), options); // convert raw media track into audio or video track
14587
14587
 
@@ -14725,6 +14725,10 @@ class LocalParticipant extends Participant {
14725
14725
  track.codec = opts.videoCodec;
14726
14726
  }
14727
14727
 
14728
+ if (track.codec === 'av1' && encodings && ((_h = encodings[0]) === null || _h === void 0 ? void 0 : _h.maxBitrate)) {
14729
+ this.engine.publisher.setTrackCodecBitrate(req.cid, track.codec, encodings[0].maxBitrate / 1000);
14730
+ }
14731
+
14728
14732
  this.engine.negotiate(); // store RTPSender
14729
14733
 
14730
14734
  track.sender = transceiver.sender;
@@ -14746,7 +14750,7 @@ class LocalParticipant extends Participant {
14746
14750
 
14747
14751
 
14748
14752
  async publishAdditionalCodecForTrack(track, videoCodec, options) {
14749
- var _a, _b, _c, _d, _e;
14753
+ var _a, _b, _c, _d, _e, _f;
14750
14754
 
14751
14755
  const opts = _objectSpread2(_objectSpread2({}, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.publishDefaults), options); // clear scalabilityMode setting for backup codec
14752
14756
 
@@ -14814,6 +14818,11 @@ class LocalParticipant extends Participant {
14814
14818
  const transceiver = await this.engine.publisher.pc.addTransceiver(simulcastTrack.mediaStreamTrack, transceiverInit);
14815
14819
  this.setPreferredCodec(transceiver, track.kind, opts.videoCodec);
14816
14820
  track.setSimulcastTrackSender(opts.videoCodec, transceiver.sender);
14821
+
14822
+ if (videoCodec === 'av1' && ((_f = encodings[0]) === null || _f === void 0 ? void 0 : _f.maxBitrate)) {
14823
+ this.engine.publisher.setTrackCodecBitrate(req.cid, videoCodec, encodings[0].maxBitrate / 1000);
14824
+ }
14825
+
14817
14826
  this.engine.negotiate();
14818
14827
  livekitLogger.debug("published ".concat(opts.videoCodec, " for track ").concat(track.sid), {
14819
14828
  encodings,
@@ -19047,7 +19056,8 @@ class PCTransport {
19047
19056
  constructor(config) {
19048
19057
  this.pendingCandidates = [];
19049
19058
  this.restartingIce = false;
19050
- this.renegotiate = false; // debounced negotiate interface
19059
+ this.renegotiate = false;
19060
+ this.trackBitrates = []; // debounced negotiate interface
19051
19061
 
19052
19062
  this.negotiate = r(() => {
19053
19063
  this.createAndSendOffer();
@@ -19111,11 +19121,38 @@ class PCTransport {
19111
19121
 
19112
19122
 
19113
19123
  livekitLogger.debug('starting to negotiate');
19114
- const offer = await this.pc.createOffer(options);
19124
+ const offer = await this.pc.createOffer(options); // mung sdp for codec bitrate setting that can't apply by sendEncoding
19125
+
19126
+ this.trackBitrates.forEach(trackbr => {
19127
+ var _a;
19128
+
19129
+ let sdp = (_a = offer.sdp) !== null && _a !== void 0 ? _a : '';
19130
+ const sidIndex = sdp.search(new RegExp("msid.* ".concat(trackbr.sid)));
19131
+
19132
+ if (sidIndex < 0) {
19133
+ return;
19134
+ }
19135
+
19136
+ const mlineStart = sdp.substring(0, sidIndex).lastIndexOf('m=');
19137
+ const mlineEnd = sdp.indexOf('m=', sidIndex);
19138
+ const mediaSection = sdp.substring(mlineStart, mlineEnd);
19139
+ const mungedMediaSection = mediaSection.replace(new RegExp("a=rtpmap:(\\d+) ".concat(trackbr.codec, "/\\d+"), 'i'), "$&\r\na=fmtp:$1 x-google-max-bitrate=".concat(trackbr.maxbr));
19140
+ sdp = sdp.substring(0, mlineStart) + mungedMediaSection + sdp.substring(mlineEnd);
19141
+ offer.sdp = sdp;
19142
+ });
19143
+ this.trackBitrates = [];
19115
19144
  await this.pc.setLocalDescription(offer);
19116
19145
  this.onOffer(offer);
19117
19146
  }
19118
19147
 
19148
+ setTrackCodecBitrate(sid, codec, maxbr) {
19149
+ this.trackBitrates.push({
19150
+ sid,
19151
+ codec,
19152
+ maxbr
19153
+ });
19154
+ }
19155
+
19119
19156
  close() {
19120
19157
  this.pc.close();
19121
19158
  }