livekit-client 1.13.0 → 1.13.2

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 (55) 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 +122 -105
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +172 -109
  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/E2eeManager.d.ts +4 -3
  10. package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
  11. package/dist/src/e2ee/KeyProvider.d.ts +7 -6
  12. package/dist/src/e2ee/KeyProvider.d.ts.map +1 -1
  13. package/dist/src/e2ee/events.d.ts +34 -0
  14. package/dist/src/e2ee/events.d.ts.map +1 -0
  15. package/dist/src/e2ee/index.d.ts +1 -0
  16. package/dist/src/e2ee/index.d.ts.map +1 -1
  17. package/dist/src/e2ee/types.d.ts +17 -33
  18. package/dist/src/e2ee/types.d.ts.map +1 -1
  19. package/dist/src/e2ee/worker/FrameCryptor.d.ts +15 -12
  20. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  21. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +6 -8
  22. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
  23. package/dist/src/room/PCTransport.d.ts.map +1 -1
  24. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  25. package/dist/src/room/Room.d.ts.map +1 -1
  26. package/dist/src/room/participant/LocalParticipant.d.ts +1 -0
  27. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  28. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  29. package/dist/src/room/track/processor/types.d.ts +2 -1
  30. package/dist/src/room/track/processor/types.d.ts.map +1 -1
  31. package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +4 -3
  32. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +7 -6
  33. package/dist/ts4.2/src/e2ee/events.d.ts +34 -0
  34. package/dist/ts4.2/src/e2ee/index.d.ts +1 -0
  35. package/dist/ts4.2/src/e2ee/types.d.ts +17 -33
  36. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +15 -12
  37. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +6 -8
  38. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +1 -0
  39. package/dist/ts4.2/src/room/track/processor/types.d.ts +2 -1
  40. package/package.json +1 -1
  41. package/src/e2ee/E2eeManager.ts +105 -77
  42. package/src/e2ee/KeyProvider.ts +23 -13
  43. package/src/e2ee/events.ts +48 -0
  44. package/src/e2ee/index.ts +1 -0
  45. package/src/e2ee/types.ts +19 -41
  46. package/src/e2ee/worker/FrameCryptor.ts +51 -43
  47. package/src/e2ee/worker/ParticipantKeyHandler.ts +25 -27
  48. package/src/e2ee/worker/e2ee.worker.ts +61 -68
  49. package/src/room/PCTransport.ts +12 -2
  50. package/src/room/RTCEngine.ts +0 -1
  51. package/src/room/Room.ts +20 -15
  52. package/src/room/participant/LocalParticipant.ts +5 -1
  53. package/src/room/track/LocalTrack.ts +18 -10
  54. package/src/room/track/facingMode.ts +1 -1
  55. package/src/room/track/processor/types.ts +2 -1
@@ -1,5 +1,6 @@
1
1
  import type TypedEventEmitter from 'typed-emitter';
2
- import type { KeyInfo, KeyProviderCallbacks, KeyProviderOptions } from './types';
2
+ import type { KeyProviderCallbacks } from './events';
3
+ import type { KeyInfo, KeyProviderOptions } from './types';
3
4
  declare const BaseKeyProvider_base: new () => TypedEventEmitter<KeyProviderCallbacks>;
4
5
  /**
5
6
  * @experimental
@@ -11,12 +12,12 @@ export declare class BaseKeyProvider extends BaseKeyProvider_base {
11
12
  /**
12
13
  * callback to invoke once a key has been set for a participant
13
14
  * @param key
14
- * @param participantId
15
+ * @param participantIdentity
15
16
  * @param keyIndex
16
17
  */
17
- protected onSetEncryptionKey(key: CryptoKey, participantId?: string, keyIndex?: number): void;
18
+ protected onSetEncryptionKey(key: CryptoKey, participantIdentity?: string, keyIndex?: number): void;
18
19
  /**
19
- * callback being invoked after a ratchet request has been performed on the local participant
20
+ * callback being invoked after a ratchet request has been performed on a participant
20
21
  * that surfaces the new key material.
21
22
  * @param material
22
23
  * @param keyIndex
@@ -24,7 +25,7 @@ export declare class BaseKeyProvider extends BaseKeyProvider_base {
24
25
  protected onKeyRatcheted: (material: CryptoKey, keyIndex?: number) => void;
25
26
  getKeys(): KeyInfo[];
26
27
  getOptions(): KeyProviderOptions;
27
- ratchetKey(participantId?: string, keyIndex?: number): void;
28
+ ratchetKey(participantIdentity?: string, keyIndex?: number): void;
28
29
  }
29
30
  /**
30
31
  * A basic KeyProvider implementation intended for a single shared
@@ -37,7 +38,7 @@ export declare class ExternalE2EEKeyProvider extends BaseKeyProvider {
37
38
  /**
38
39
  * Accepts a passphrase that's used to create the crypto keys.
39
40
  * When passing in a string, PBKDF2 is used.
40
- * Also accepts an Array buffer of cryptographically random numbers that uses HKDF.
41
+ * When passing in an Array buffer of cryptographically random numbers, HKDF is being used. (recommended)
41
42
  * @param key
42
43
  */
43
44
  setKey(key: string | ArrayBuffer): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import type Participant from '../room/participant/Participant';
2
+ import type { CryptorError } from './errors';
3
+ import type { KeyInfo } from './types';
4
+ export declare enum KeyProviderEvent {
5
+ SetKey = "setKey",
6
+ RatchetRequest = "ratchetRequest",
7
+ KeyRatcheted = "keyRatcheted"
8
+ }
9
+ export type KeyProviderCallbacks = {
10
+ [KeyProviderEvent.SetKey]: (keyInfo: KeyInfo) => void;
11
+ [KeyProviderEvent.RatchetRequest]: (participantIdentity?: string, keyIndex?: number) => void;
12
+ [KeyProviderEvent.KeyRatcheted]: (material: CryptoKey, keyIndex?: number) => void;
13
+ };
14
+ export declare enum KeyHandlerEvent {
15
+ KeyRatcheted = "keyRatcheted"
16
+ }
17
+ export type ParticipantKeyHandlerCallbacks = {
18
+ [KeyHandlerEvent.KeyRatcheted]: (material: CryptoKey, participantIdentity: string, keyIndex?: number) => void;
19
+ };
20
+ export declare enum EncryptionEvent {
21
+ ParticipantEncryptionStatusChanged = "participantEncryptionStatusChanged",
22
+ EncryptionError = "encryptionError"
23
+ }
24
+ export type E2EEManagerCallbacks = {
25
+ [EncryptionEvent.ParticipantEncryptionStatusChanged]: (enabled: boolean, participant: Participant) => void;
26
+ [EncryptionEvent.EncryptionError]: (error: Error) => void;
27
+ };
28
+ export type CryptorCallbacks = {
29
+ [CryptorEvent.Error]: (error: CryptorError) => void;
30
+ };
31
+ export declare enum CryptorEvent {
32
+ Error = "cryptorError"
33
+ }
34
+ //# sourceMappingURL=events.d.ts.map
@@ -1,4 +1,5 @@
1
1
  export * from './KeyProvider';
2
2
  export * from './utils';
3
3
  export * from './types';
4
+ export * from './events';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,5 @@
1
- import type Participant from '../room/participant/Participant';
2
1
  import type { VideoCodec } from '../room/track/options';
3
2
  import type { BaseKeyProvider } from './KeyProvider';
4
- import type { CryptorError } from './errors';
5
3
  export interface BaseMessage {
6
4
  kind: string;
7
5
  data?: unknown;
@@ -15,7 +13,8 @@ export interface InitMessage extends BaseMessage {
15
13
  export interface SetKeyMessage extends BaseMessage {
16
14
  kind: 'setKey';
17
15
  data: {
18
- participantId?: string;
16
+ participantIdentity?: string;
17
+ isPublisher: boolean;
19
18
  key: CryptoKey;
20
19
  keyIndex?: number;
21
20
  };
@@ -24,6 +23,7 @@ export interface RTPVideoMapMessage extends BaseMessage {
24
23
  kind: 'setRTPMap';
25
24
  data: {
26
25
  map: Map<number, VideoCodec>;
26
+ participantIdentity: string;
27
27
  };
28
28
  }
29
29
  export interface SifTrailerMessage extends BaseMessage {
@@ -35,7 +35,7 @@ export interface SifTrailerMessage extends BaseMessage {
35
35
  export interface EncodeMessage extends BaseMessage {
36
36
  kind: 'decode' | 'encode';
37
37
  data: {
38
- participantId: string;
38
+ participantIdentity: string;
39
39
  readableStream: ReadableStream;
40
40
  writableStream: WritableStream;
41
41
  trackId: string;
@@ -45,14 +45,14 @@ export interface EncodeMessage extends BaseMessage {
45
45
  export interface RemoveTransformMessage extends BaseMessage {
46
46
  kind: 'removeTransform';
47
47
  data: {
48
- participantId: string;
48
+ participantIdentity: string;
49
49
  trackId: string;
50
50
  };
51
51
  }
52
52
  export interface UpdateCodecMessage extends BaseMessage {
53
53
  kind: 'updateCodec';
54
54
  data: {
55
- participantId: string;
55
+ participantIdentity: string;
56
56
  trackId: string;
57
57
  codec: VideoCodec;
58
58
  };
@@ -60,13 +60,14 @@ export interface UpdateCodecMessage extends BaseMessage {
60
60
  export interface RatchetRequestMessage extends BaseMessage {
61
61
  kind: 'ratchetRequest';
62
62
  data: {
63
- participantId: string | undefined;
63
+ participantIdentity?: string;
64
64
  keyIndex?: number;
65
65
  };
66
66
  }
67
67
  export interface RatchetMessage extends BaseMessage {
68
68
  kind: 'ratchetKey';
69
69
  data: {
70
+ participantIdentity: string;
70
71
  keyIndex?: number;
71
72
  material: CryptoKey;
72
73
  };
@@ -80,11 +81,17 @@ export interface ErrorMessage extends BaseMessage {
80
81
  export interface EnableMessage extends BaseMessage {
81
82
  kind: 'enable';
82
83
  data: {
83
- participantId?: string;
84
+ participantIdentity: string;
84
85
  enabled: boolean;
85
86
  };
86
87
  }
87
- export type E2EEWorkerMessage = InitMessage | SetKeyMessage | EncodeMessage | ErrorMessage | EnableMessage | RemoveTransformMessage | RTPVideoMapMessage | UpdateCodecMessage | RatchetRequestMessage | RatchetMessage | SifTrailerMessage;
88
+ export interface InitAck extends BaseMessage {
89
+ kind: 'initAck';
90
+ data: {
91
+ enabled: boolean;
92
+ };
93
+ }
94
+ export type E2EEWorkerMessage = InitMessage | SetKeyMessage | EncodeMessage | ErrorMessage | EnableMessage | RemoveTransformMessage | RTPVideoMapMessage | UpdateCodecMessage | RatchetRequestMessage | RatchetMessage | SifTrailerMessage | InitAck;
88
95
  export type KeySet = {
89
96
  material: CryptoKey;
90
97
  encryptionKey: CryptoKey;
@@ -95,32 +102,9 @@ export type KeyProviderOptions = {
95
102
  ratchetWindowSize: number;
96
103
  failureTolerance: number;
97
104
  };
98
- export type KeyProviderCallbacks = {
99
- setKey: (keyInfo: KeyInfo) => void;
100
- ratchetRequest: (participantId?: string, keyIndex?: number) => void;
101
- /** currently only emitted for local participant */
102
- keyRatcheted: (material: CryptoKey, keyIndex?: number) => void;
103
- };
104
- export type ParticipantKeyHandlerCallbacks = {
105
- keyRatcheted: (material: CryptoKey, keyIndex?: number, participantId?: string) => void;
106
- };
107
- export type E2EEManagerCallbacks = {
108
- participantEncryptionStatusChanged: (enabled: boolean, participant?: Participant) => void;
109
- encryptionError: (error: Error) => void;
110
- };
111
- export declare const EncryptionEvent: {
112
- readonly ParticipantEncryptionStatusChanged: "participantEncryptionStatusChanged";
113
- readonly Error: "encryptionError";
114
- };
115
- export type CryptorCallbacks = {
116
- cryptorError: (error: CryptorError) => void;
117
- };
118
- export declare const CryptorEvent: {
119
- readonly Error: "cryptorError";
120
- };
121
105
  export type KeyInfo = {
122
106
  key: CryptoKey;
123
- participantId?: string;
107
+ participantIdentity?: string;
124
108
  keyIndex?: number;
125
109
  };
126
110
  export type E2EEOptions = {
@@ -1,7 +1,9 @@
1
1
  import type TypedEventEmitter from 'typed-emitter';
2
2
  import type { VideoCodec } from '../../room/track/options';
3
- import { CryptorCallbacks, DecodeRatchetOptions, KeyProviderOptions, KeySet } from '../types';
3
+ import { CryptorCallbacks } from '../events';
4
+ import type { KeyProviderOptions } from '../types';
4
5
  import type { ParticipantKeyHandler } from './ParticipantKeyHandler';
6
+ export declare const encryptionEnabledMap: Map<string, boolean>;
5
7
  export interface FrameCryptorConstructor {
6
8
  new (opts?: unknown): BaseFrameCryptor;
7
9
  }
@@ -13,8 +15,8 @@ export interface TransformerInfo {
13
15
  }
14
16
  declare const BaseFrameCryptor_base: new () => TypedEventEmitter<CryptorCallbacks>;
15
17
  export declare class BaseFrameCryptor extends BaseFrameCryptor_base {
16
- encodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<any>;
17
- decodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<any>;
18
+ protected encodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<any>;
19
+ protected decodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<any>;
18
20
  }
19
21
  /**
20
22
  * Cryptor is responsible for en-/decrypting media frames.
@@ -22,7 +24,7 @@ export declare class BaseFrameCryptor extends BaseFrameCryptor_base {
22
24
  */
23
25
  export declare class FrameCryptor extends BaseFrameCryptor {
24
26
  private sendCounts;
25
- private participantId;
27
+ private participantIdentity;
26
28
  private trackId;
27
29
  private keys;
28
30
  private videoCodec?;
@@ -35,7 +37,7 @@ export declare class FrameCryptor extends BaseFrameCryptor {
35
37
  private sifGuard;
36
38
  constructor(opts: {
37
39
  keys: ParticipantKeyHandler;
38
- participantId: string;
40
+ participantIdentity: string;
39
41
  keyProviderOptions: KeyProviderOptions;
40
42
  sifTrailer?: Uint8Array;
41
43
  });
@@ -47,7 +49,8 @@ export declare class FrameCryptor extends BaseFrameCryptor {
47
49
  */
48
50
  setParticipant(id: string, keys: ParticipantKeyHandler): void;
49
51
  unsetParticipant(): void;
50
- getParticipantId(): string | undefined;
52
+ isEnabled(): boolean | undefined;
53
+ getParticipantIdentity(): string | undefined;
51
54
  getTrackId(): string | undefined;
52
55
  /**
53
56
  * Update the video codec used by the mediaStreamTrack
@@ -60,6 +63,7 @@ export declare class FrameCryptor extends BaseFrameCryptor {
60
63
  */
61
64
  setRtpMap(map: Map<number, VideoCodec>): void;
62
65
  setupTransform(operation: 'encode' | 'decode', readable: ReadableStream, writable: WritableStream, trackId: string, codec?: VideoCodec): void;
66
+ setSifTrailer(trailer: Uint8Array): void;
63
67
  /**
64
68
  * Function that will be injected in a stream and will encrypt the given encoded frames.
65
69
  *
@@ -82,19 +86,19 @@ export declare class FrameCryptor extends BaseFrameCryptor {
82
86
  * 8) Append a single byte for the key identifier.
83
87
  * 9) Enqueue the encrypted frame for sending.
84
88
  */
85
- encodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<void>;
89
+ protected encodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<void>;
86
90
  /**
87
91
  * Function that will be injected in a stream and will decrypt the given encoded frames.
88
92
  *
89
93
  * @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame.
90
94
  * @param {TransformStreamDefaultController} controller - TransportStreamController.
91
95
  */
92
- decodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<void>;
96
+ protected decodeFunction(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, controller: TransformStreamDefaultController): Promise<void>;
93
97
  /**
94
98
  * Function that will decrypt the given encoded frame. If the decryption fails, it will
95
99
  * ratchet the key for up to RATCHET_WINDOW_SIZE times.
96
100
  */
97
- decryptFrame(encodedFrame: RTCEncodedVideoFrame | RTCEncodedAudioFrame, keyIndex: number, initialMaterial?: KeySet | undefined, ratchetOpts?: DecodeRatchetOptions): Promise<RTCEncodedVideoFrame | RTCEncodedAudioFrame | undefined>;
101
+ private decryptFrame;
98
102
  /**
99
103
  * Construct the IV used for AES-GCM and sent (in plain) with the packet similar to
100
104
  * https://tools.ietf.org/html/rfc7714#section-8.1
@@ -115,12 +119,11 @@ export declare class FrameCryptor extends BaseFrameCryptor {
115
119
  * See also https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams
116
120
  */
117
121
  private makeIV;
118
- getUnencryptedBytes(frame: RTCEncodedVideoFrame | RTCEncodedAudioFrame): number;
122
+ private getUnencryptedBytes;
119
123
  /**
120
124
  * inspects frame payloadtype if available and maps it to the codec specified in rtpMap
121
125
  */
122
- getVideoCodec(frame: RTCEncodedVideoFrame): VideoCodec | undefined;
123
- setSifTrailer(trailer: Uint8Array): void;
126
+ private getVideoCodec;
124
127
  }
125
128
  /**
126
129
  * Slice the NALUs present in the supplied buffer, assuming it is already byte-aligned
@@ -1,5 +1,6 @@
1
1
  import type TypedEventEmitter from 'typed-emitter';
2
- import type { KeyProviderOptions, KeySet, ParticipantKeyHandlerCallbacks } from '../types';
2
+ import type { ParticipantKeyHandlerCallbacks } from '../events';
3
+ import type { KeyProviderOptions, KeySet } from '../types';
3
4
  declare const ParticipantKeyHandler_base: new () => TypedEventEmitter<ParticipantKeyHandlerCallbacks>;
4
5
  /**
5
6
  * ParticipantKeyHandler is responsible for providing a cryptor instance with the
@@ -12,15 +13,13 @@ declare const ParticipantKeyHandler_base: new () => TypedEventEmitter<Participan
12
13
  export declare class ParticipantKeyHandler extends ParticipantKeyHandler_base {
13
14
  private currentKeyIndex;
14
15
  private cryptoKeyRing;
15
- private enabled;
16
16
  private keyProviderOptions;
17
17
  private ratchetPromiseMap;
18
- private participantId;
18
+ private participantIdentity;
19
19
  private decryptionFailureCount;
20
20
  private _hasValidKey;
21
21
  get hasValidKey(): boolean;
22
- constructor(participantId: string | undefined, isEnabled: boolean, keyProviderOptions: KeyProviderOptions);
23
- setEnabled(enabled: boolean): void;
22
+ constructor(participantIdentity: string, keyProviderOptions: KeyProviderOptions);
24
23
  decryptionFailure(): void;
25
24
  decryptionSuccess(): void;
26
25
  /**
@@ -50,16 +49,15 @@ export declare class ParticipantKeyHandler extends ParticipantKeyHandler_base {
50
49
  * also updates the currentKeyIndex
51
50
  */
52
51
  setKeyFromMaterial(material: CryptoKey, keyIndex?: number, emitRatchetEvent?: boolean): Promise<void>;
53
- setKeySet(keySet: KeySet, keyIndex: number, emitRatchetEvent?: boolean): Promise<void>;
52
+ setKeySet(keySet: KeySet, keyIndex: number, emitRatchetEvent?: boolean): void;
54
53
  setCurrentKeyIndex(index: number): Promise<void>;
55
- isEnabled(): boolean;
56
54
  getCurrentKeyIndex(): number;
57
55
  /**
58
56
  * returns currently used KeySet or the one at `keyIndex` if provided
59
57
  * @param keyIndex
60
58
  * @returns
61
59
  */
62
- getKeySet(keyIndex?: number): KeySet;
60
+ getKeySet(keyIndex?: number): KeySet | undefined;
63
61
  }
64
62
  export {};
65
63
  //# sourceMappingURL=ParticipantKeyHandler.d.ts.map
@@ -32,6 +32,7 @@ export default class LocalParticipant extends Participant {
32
32
  constructor(sid: string, identity: string, engine: RTCEngine, options: InternalRoomOptions);
33
33
  get lastCameraError(): Error | undefined;
34
34
  get lastMicrophoneError(): Error | undefined;
35
+ get isE2EEEnabled(): boolean;
35
36
  getTrack(source: Track.Source): LocalTrackPublication | undefined;
36
37
  getTrackByName(name: string): LocalTrackPublication | undefined;
37
38
  /**
@@ -23,7 +23,8 @@ export interface VideoProcessorOptions extends ProcessorOptions<Track.Kind.Video
23
23
  */
24
24
  export interface TrackProcessor<T extends Track.Kind, U extends ProcessorOptions<T> = ProcessorOptions<T>> {
25
25
  name: string;
26
- init: (opts: U) => void;
26
+ init: (opts: U) => Promise<void>;
27
+ restart: (opts: U) => Promise<void>;
27
28
  destroy: () => Promise<void>;
28
29
  processedTrack?: MediaStreamTrack;
29
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "1.13.0",
3
+ "version": "1.13.2",
4
4
  "description": "JavaScript/TypeScript client SDK for LiveKit",
5
5
  "main": "./dist/livekit-client.umd.js",
6
6
  "unpkg": "./dist/livekit-client.umd.js",