livekit-client 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/dist/livekit-client.e2ee.worker.js +1 -1
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs +33 -9
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +70 -41
  6. package/dist/livekit-client.esm.mjs.map +1 -1
  7. package/dist/livekit-client.umd.js +1 -1
  8. package/dist/livekit-client.umd.js.map +1 -1
  9. package/dist/src/e2ee/constants.d.ts +0 -1
  10. package/dist/src/e2ee/constants.d.ts.map +1 -1
  11. package/dist/src/e2ee/types.d.ts +1 -0
  12. package/dist/src/e2ee/types.d.ts.map +1 -1
  13. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  14. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
  15. package/dist/src/index.d.ts +7 -6
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/room/PCTransport.d.ts.map +1 -1
  18. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  19. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  20. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  21. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  22. package/dist/ts4.2/src/e2ee/constants.d.ts +0 -1
  23. package/dist/ts4.2/src/e2ee/types.d.ts +1 -0
  24. package/dist/ts4.2/src/index.d.ts +7 -6
  25. package/package.json +1 -1
  26. package/src/e2ee/constants.ts +1 -5
  27. package/src/e2ee/types.ts +1 -0
  28. package/src/e2ee/worker/FrameCryptor.ts +12 -0
  29. package/src/e2ee/worker/ParticipantKeyHandler.ts +4 -2
  30. package/src/e2ee/worker/e2ee.worker.ts +24 -3
  31. package/src/index.ts +32 -29
  32. package/src/room/PCTransport.ts +6 -18
  33. package/src/room/RTCEngine.ts +4 -3
  34. package/src/room/participant/LocalParticipant.ts +21 -6
  35. package/src/room/participant/publishUtils.ts +38 -11
  36. package/src/room/track/LocalTrack.ts +11 -9
@@ -12538,7 +12538,8 @@ const KEY_PROVIDER_DEFAULTS = {
12538
12538
  sharedKey: false,
12539
12539
  ratchetSalt: SALT,
12540
12540
  ratchetWindowSize: 8,
12541
- failureTolerance: DECRYPTION_FAILURE_TOLERANCE
12541
+ failureTolerance: DECRYPTION_FAILURE_TOLERANCE,
12542
+ keyringSize: 16
12542
12543
  };
12543
12544
 
12544
12545
  var KeyProviderEvent;
@@ -13473,7 +13474,7 @@ function getMatch(exp, ua) {
13473
13474
  return match && match.length >= id && match[id] || '';
13474
13475
  }
13475
13476
 
13476
- var version$1 = "2.0.7";
13477
+ var version$1 = "2.0.9";
13477
13478
 
13478
13479
  const version = version$1;
13479
13480
  const protocolVersion = 12;
@@ -15037,6 +15038,13 @@ class LocalTrack extends Track {
15037
15038
  const unlock = yield this.processorLock.lock();
15038
15039
  try {
15039
15040
  this.log.debug('setting up processor', this.logContext);
15041
+ const processorOptions = {
15042
+ kind: this.kind,
15043
+ track: this._mediaStreamTrack,
15044
+ element: this.processorElement,
15045
+ audioContext: this.audioContext
15046
+ };
15047
+ yield processor.init(processorOptions);
15040
15048
  if (this.processor) {
15041
15049
  yield this.stopProcessor();
15042
15050
  }
@@ -15049,13 +15057,6 @@ class LocalTrack extends Track {
15049
15057
  this.processorElement.play().catch(error => this.log.error('failed to play processor element', Object.assign(Object.assign({}, this.logContext), {
15050
15058
  error
15051
15059
  })));
15052
- const processorOptions = {
15053
- kind: this.kind,
15054
- track: this._mediaStreamTrack,
15055
- element: this.processorElement,
15056
- audioContext: this.audioContext
15057
- };
15058
- yield processor.init(processorOptions);
15059
15060
  this.processor = processor;
15060
15061
  if (this.processor.processedTrack) {
15061
15062
  for (const el of this.attachedElements) {
@@ -15092,7 +15093,10 @@ class LocalTrack extends Track {
15092
15093
  this.processor = undefined;
15093
15094
  (_b = this.processorElement) === null || _b === void 0 ? void 0 : _b.remove();
15094
15095
  this.processorElement = undefined;
15095
- yield this.restart();
15096
+ // apply original track constraints in case the processor changed them
15097
+ yield this._mediaStreamTrack.applyConstraints(this._constraints);
15098
+ // force re-setting of the mediaStreamTrack on the sender
15099
+ yield this.setMediaStreamTrack(this._mediaStreamTrack, true);
15096
15100
  this.emit(TrackEvent.TrackProcessorUpdate);
15097
15101
  });
15098
15102
  }
@@ -17032,25 +17036,18 @@ class PCTransport extends eventsExports.EventEmitter {
17032
17036
  if (codecPayload === 0) {
17033
17037
  return true;
17034
17038
  }
17035
- let fmtpFound = false;
17039
+ const startBitrate = Math.round(trackbr.maxbr * startBitrateForSVC);
17036
17040
  for (const fmtp of media.fmtp) {
17037
17041
  if (fmtp.payload === codecPayload) {
17042
+ // if another track's fmtp already is set, we cannot override the bitrate
17043
+ // this has the unfortunate consequence of being forced to use the
17044
+ // initial track's bitrate for all tracks
17038
17045
  if (!fmtp.config.includes('x-google-start-bitrate')) {
17039
- fmtp.config += ";x-google-start-bitrate=".concat(Math.round(trackbr.maxbr * startBitrateForSVC));
17046
+ fmtp.config += ";x-google-start-bitrate=".concat(startBitrate);
17040
17047
  }
17041
- if (!fmtp.config.includes('x-google-max-bitrate')) {
17042
- fmtp.config += ";x-google-max-bitrate=".concat(trackbr.maxbr);
17043
- }
17044
- fmtpFound = true;
17045
17048
  break;
17046
17049
  }
17047
17050
  }
17048
- if (!fmtpFound) {
17049
- media.fmtp.push({
17050
- payload: codecPayload,
17051
- config: "x-google-start-bitrate=".concat(Math.round(trackbr.maxbr * startBitrateForSVC), ";x-google-max-bitrate=").concat(trackbr.maxbr)
17052
- });
17053
- }
17054
17051
  return true;
17055
17052
  });
17056
17053
  }
@@ -18179,12 +18176,13 @@ class RTCEngine extends eventsExports.EventEmitter {
18179
18176
  this.reliableDC.onbufferedamountlow = this.handleBufferedAmountLow;
18180
18177
  }
18181
18178
  setPreferredCodec(transceiver, kind, videoCodec) {
18182
- if (!('getCapabilities' in RTCRtpSender)) {
18179
+ if (!('getCapabilities' in RTCRtpReceiver)) {
18183
18180
  return;
18184
18181
  }
18185
- const cap = RTCRtpSender.getCapabilities(kind);
18182
+ // when setting codec preferences, the capabilites need to be read from the RTCRtpReceiver
18183
+ const cap = RTCRtpReceiver.getCapabilities(kind);
18186
18184
  if (!cap) return;
18187
- this.log.debug('get sender capabilities', Object.assign(Object.assign({}, this.logContext), {
18185
+ this.log.debug('get receiver capabilities', Object.assign(Object.assign({}, this.logContext), {
18188
18186
  cap
18189
18187
  }));
18190
18188
  const matched = [];
@@ -19086,23 +19084,40 @@ function computeVideoEncodings(isScreenShare, width, height, options) {
19086
19084
  }
19087
19085
  const original = new VideoPreset(width, height, videoEncoding.maxBitrate, videoEncoding.maxFramerate, videoEncoding.priority);
19088
19086
  if (scalabilityMode && isSVCCodec(videoCodec)) {
19089
- livekitLogger.debug("using svc with scalabilityMode ".concat(scalabilityMode));
19090
19087
  const sm = new ScalabilityMode(scalabilityMode);
19091
19088
  const encodings = [];
19092
19089
  if (sm.spatial > 3) {
19093
19090
  throw new Error("unsupported scalabilityMode: ".concat(scalabilityMode));
19094
19091
  }
19095
- for (let i = 0; i < sm.spatial; i += 1) {
19092
+ // Before M113 in Chrome, defining multiple encodings with an SVC codec indicated
19093
+ // that SVC mode should be used. Safari still works this way.
19094
+ // This is a bit confusing but is due to how libwebrtc interpreted the encodings field
19095
+ // before M113.
19096
+ // Announced here: https://groups.google.com/g/discuss-webrtc/c/-QQ3pxrl-fw?pli=1
19097
+ const browser = getBrowser();
19098
+ if (isSafari() || (browser === null || browser === void 0 ? void 0 : browser.name) === 'Chrome' && compareVersions(browser === null || browser === void 0 ? void 0 : browser.version, '113') < 0) {
19099
+ for (let i = 0; i < sm.spatial; i += 1) {
19100
+ // in legacy SVC, scaleResolutionDownBy cannot be set
19101
+ encodings.push({
19102
+ rid: videoRids[2 - i],
19103
+ maxBitrate: videoEncoding.maxBitrate / Math.pow(3, i),
19104
+ maxFramerate: original.encoding.maxFramerate
19105
+ });
19106
+ }
19107
+ // legacy SVC, scalabilityMode is set only on the first encoding
19108
+ /* @ts-ignore */
19109
+ encodings[0].scalabilityMode = scalabilityMode;
19110
+ } else {
19096
19111
  encodings.push({
19097
- rid: videoRids[2 - i],
19098
- maxBitrate: videoEncoding.maxBitrate / Math.pow(3, i),
19112
+ maxBitrate: videoEncoding.maxBitrate,
19113
+ maxFramerate: original.encoding.maxFramerate,
19099
19114
  /* @ts-ignore */
19100
- maxFramerate: original.encoding.maxFramerate
19115
+ scalabilityMode: scalabilityMode
19101
19116
  });
19102
19117
  }
19103
- /* @ts-ignore */
19104
- encodings[0].scalabilityMode = scalabilityMode;
19105
- livekitLogger.debug('encodings', encodings);
19118
+ livekitLogger.debug("using svc encoding", {
19119
+ encodings
19120
+ });
19106
19121
  return encodings;
19107
19122
  }
19108
19123
  if (!useSimulcast) {
@@ -19126,7 +19141,7 @@ function computeVideoEncodings(isScreenShare, width, height, options) {
19126
19141
  // to disable when CPU constrained.
19127
19142
  // So encodings should be ordered in increasing spatial
19128
19143
  // resolution order.
19129
- // 2. ion-sfu translates rids into layers. So, all encodings
19144
+ // 2. livekit-server translates rids into layers. So, all encodings
19130
19145
  // should have the base layer `q` and then more added
19131
19146
  // based on other conditions.
19132
19147
  const size = Math.max(width, height);
@@ -21521,8 +21536,10 @@ class LocalParticipant extends Participant {
21521
21536
  // for svc codecs, disable simulcast and use vp8 for backup codec
21522
21537
  if (track instanceof LocalVideoTrack) {
21523
21538
  if (isSVCCodec(videoCodec)) {
21524
- // vp9 svc with screenshare has problem to encode, always use L1T3 here
21525
- if (track.source === Track.Source.ScreenShare && videoCodec === 'vp9') {
21539
+ if (track.source === Track.Source.ScreenShare) {
21540
+ // vp9 svc with screenshare cannot encode multiple spatial layers
21541
+ // doing so reduces publish resolution to minimal resolution
21542
+ opts.scalabilityMode = 'L1T3';
21526
21543
  // Chrome does not allow more than 5 fps with L1T3, and it has encoding bugs with L3T3
21527
21544
  // It has a different path for screenshare handling and it seems to be untested/buggy
21528
21545
  // As a workaround, we are setting contentHint to force it to go through the same
@@ -21530,9 +21547,7 @@ class LocalParticipant extends Participant {
21530
21547
  // that we need
21531
21548
  if ('contentHint' in track.mediaStreamTrack) {
21532
21549
  track.mediaStreamTrack.contentHint = 'motion';
21533
- this.log.info('forcing contentHint to motion for screenshare with VP9', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
21534
- } else {
21535
- opts.scalabilityMode = 'L1T3';
21550
+ this.log.info('forcing contentHint to motion for screenshare with SVC codecs', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
21536
21551
  }
21537
21552
  }
21538
21553
  // set scalabilityMode to 'L3T3_KEY' by default
@@ -21632,7 +21647,8 @@ class LocalParticipant extends Participant {
21632
21647
  maxbr: ((_l = encodings[0]) === null || _l === void 0 ? void 0 : _l.maxBitrate) ? encodings[0].maxBitrate / 1000 : 0
21633
21648
  });
21634
21649
  }
21635
- } else if (track.codec && isSVCCodec(track.codec) && ((_m = encodings[0]) === null || _m === void 0 ? void 0 : _m.maxBitrate)) {
21650
+ } else if (track.codec && track.codec == 'av1' && ((_m = encodings[0]) === null || _m === void 0 ? void 0 : _m.maxBitrate)) {
21651
+ // AV1 requires setting x-start-bitrate in SDP
21636
21652
  this.engine.pcManager.publisher.setTrackCodecBitrate({
21637
21653
  cid: req.cid,
21638
21654
  codec: track.codec,
@@ -21640,6 +21656,19 @@ class LocalParticipant extends Participant {
21640
21656
  });
21641
21657
  }
21642
21658
  }
21659
+ if (track.kind === Track.Kind.Video && track.source === Track.Source.ScreenShare) {
21660
+ // a few of reasons we are forcing this setting without allowing overrides:
21661
+ // 1. without this, Chrome seems to aggressively resize the SVC video stating `quality-limitation: bandwidth` even when BW isn't an issue
21662
+ // 2. since we are overriding contentHint to motion (to workaround L1T3 publishing), it overrides the default degradationPreference to `balanced`
21663
+ try {
21664
+ this.log.debug("setting degradationPreference to maintain-resolution");
21665
+ const params = track.sender.getParameters();
21666
+ params.degradationPreference = 'maintain-resolution';
21667
+ yield track.sender.setParameters(params);
21668
+ } catch (e) {
21669
+ this.log.warn("failed to set degradationPreference: ".concat(e));
21670
+ }
21671
+ }
21643
21672
  yield this.engine.negotiate();
21644
21673
  if (track instanceof LocalVideoTrack) {
21645
21674
  track.startMonitor(this.engine.client);
@@ -24612,5 +24641,5 @@ function isFacingModeValue(item) {
24612
24641
  return item === undefined || allowedValues.includes(item);
24613
24642
  }
24614
24643
 
24615
- export { AudioPresets, BaseKeyProvider, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, LoggerNames, MediaDeviceFailure, NegotiationError, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, getLogger, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
24644
+ export { AudioPresets, BaseKeyProvider, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, LoggerNames, MediaDeviceFailure, NegotiationError, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, ScreenSharePresets, SubscriptionError, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getBrowser, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, getLogger, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
24616
24645
  //# sourceMappingURL=livekit-client.esm.mjs.map