livekit-client 2.0.7 → 2.0.9

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.
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
@@ -327,10 +327,6 @@ livekitLogger.setDefaultLevel(LogLevel.info);
327
327
  const workerLogger = loglevelExports.getLogger('lk-e2ee');
328
328
 
329
329
  const ENCRYPTION_ALGORITHM = 'AES-GCM';
330
- // We use a ringbuffer of keys so we can change them and still decode packets that were
331
- // encrypted with an old key. We use a size of 16 which corresponds to the four bits
332
- // in the frame trailer.
333
- const KEYRING_SIZE = 16;
334
330
  // How many consecutive frames can fail decrypting before a particular key gets marked as invalid
335
331
  const DECRYPTION_FAILURE_TOLERANCE = 10;
336
332
  // We copy the first bytes of the VP8 payload unencrypted.
@@ -358,7 +354,8 @@ const KEY_PROVIDER_DEFAULTS = {
358
354
  sharedKey: false,
359
355
  ratchetSalt: SALT,
360
356
  ratchetWindowSize: 8,
361
- failureTolerance: DECRYPTION_FAILURE_TOLERANCE
357
+ failureTolerance: DECRYPTION_FAILURE_TOLERANCE,
358
+ keyringSize: 16
362
359
  };
363
360
  const MAX_SIF_COUNT = 100;
364
361
  const MAX_SIF_DURATION = 2000;
@@ -1002,6 +999,12 @@ class FrameCryptor extends BaseFrameCryptor {
1002
999
  * @param keys
1003
1000
  */
1004
1001
  setParticipant(id, keys) {
1002
+ workerLogger.debug('setting new participant on cryptor', Object.assign(Object.assign({}, this.logContext), {
1003
+ participant: id
1004
+ }));
1005
+ if (this.participantIdentity) {
1006
+ workerLogger.error('cryptor has already a participant set, participant should have been unset before', Object.assign({}, this.logContext));
1007
+ }
1005
1008
  this.participantIdentity = id;
1006
1009
  this.keys = keys;
1007
1010
  this.sifGuard.reset();
@@ -1497,7 +1500,10 @@ class ParticipantKeyHandler extends eventsExports.EventEmitter {
1497
1500
  this.decryptionFailureCount = 0;
1498
1501
  this._hasValidKey = true;
1499
1502
  this.currentKeyIndex = 0;
1500
- this.cryptoKeyRing = new Array(KEYRING_SIZE).fill(undefined);
1503
+ if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 255) {
1504
+ throw new TypeError('Keyring size needs to be between 1 and 256');
1505
+ }
1506
+ this.cryptoKeyRing = new Array(keyProviderOptions.keyringSize).fill(undefined);
1501
1507
  this.keyProviderOptions = keyProviderOptions;
1502
1508
  this.ratchetPromiseMap = new Map();
1503
1509
  this.participantIdentity = participantIdentity;
@@ -1649,7 +1655,7 @@ onmessage = ev => {
1649
1655
  break;
1650
1656
  case 'enable':
1651
1657
  setEncryptionEnabled(data.enabled, data.participantIdentity);
1652
- workerLogger.info('updated e2ee enabled status');
1658
+ workerLogger.info("updated e2ee enabled status for ".concat(data.participantIdentity, " to ").concat(data.enabled));
1653
1659
  // acknowledge enable call successful
1654
1660
  postMessage(ev.data);
1655
1661
  break;
@@ -1709,7 +1715,18 @@ function handleRatchetRequest(data) {
1709
1715
  });
1710
1716
  }
1711
1717
  function getTrackCryptor(participantIdentity, trackId) {
1712
- let cryptor = participantCryptors.find(c => c.getTrackId() === trackId);
1718
+ let cryptors = participantCryptors.filter(c => c.getTrackId() === trackId);
1719
+ if (cryptors.length > 1) {
1720
+ const debugInfo = cryptors.map(c => {
1721
+ return {
1722
+ participant: c.getParticipantIdentity()
1723
+ };
1724
+ }).join(',');
1725
+ workerLogger.error("Found multiple cryptors for the same trackID ".concat(trackId, ". target participant: ").concat(participantIdentity, " "), {
1726
+ participants: debugInfo
1727
+ });
1728
+ }
1729
+ let cryptor = cryptors[0];
1713
1730
  if (!cryptor) {
1714
1731
  workerLogger.info('creating new cryptor for', {
1715
1732
  participantIdentity
@@ -1751,7 +1768,14 @@ function getSharedKeyHandler() {
1751
1768
  return sharedKeyHandler;
1752
1769
  }
1753
1770
  function unsetCryptorParticipant(trackId, participantIdentity) {
1754
- const cryptor = participantCryptors.find(c => c.getParticipantIdentity() === participantIdentity && c.getTrackId() === trackId);
1771
+ const cryptors = participantCryptors.filter(c => c.getParticipantIdentity() === participantIdentity && c.getTrackId() === trackId);
1772
+ if (cryptors.length > 1) {
1773
+ workerLogger.error('Found multiple cryptors for the same participant and trackID combination', {
1774
+ trackId,
1775
+ participantIdentity
1776
+ });
1777
+ }
1778
+ const cryptor = cryptors[0];
1755
1779
  if (!cryptor) {
1756
1780
  workerLogger.warn('Could not unset participant on cryptor', {
1757
1781
  trackId,