livekit-client 1.11.3 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. package/README.md +1 -3
  2. package/dist/livekit-client.e2ee.worker.js +2 -0
  3. package/dist/livekit-client.e2ee.worker.js.map +1 -0
  4. package/dist/livekit-client.e2ee.worker.mjs +1525 -0
  5. package/dist/livekit-client.e2ee.worker.mjs.map +1 -0
  6. package/dist/livekit-client.esm.mjs +1462 -660
  7. package/dist/livekit-client.esm.mjs.map +1 -1
  8. package/dist/livekit-client.umd.js +1 -1
  9. package/dist/livekit-client.umd.js.map +1 -1
  10. package/dist/src/api/SignalClient.d.ts +4 -1
  11. package/dist/src/api/SignalClient.d.ts.map +1 -1
  12. package/dist/src/connectionHelper/checks/turn.d.ts.map +1 -1
  13. package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
  14. package/dist/src/e2ee/E2eeManager.d.ts +45 -0
  15. package/dist/src/e2ee/E2eeManager.d.ts.map +1 -0
  16. package/dist/src/e2ee/KeyProvider.d.ts +42 -0
  17. package/dist/src/e2ee/KeyProvider.d.ts.map +1 -0
  18. package/dist/src/e2ee/constants.d.ts +14 -0
  19. package/dist/src/e2ee/constants.d.ts.map +1 -0
  20. package/dist/src/e2ee/errors.d.ts +11 -0
  21. package/dist/src/e2ee/errors.d.ts.map +1 -0
  22. package/dist/src/e2ee/index.d.ts +4 -0
  23. package/dist/src/e2ee/index.d.ts.map +1 -0
  24. package/dist/src/e2ee/types.d.ts +129 -0
  25. package/dist/src/e2ee/types.d.ts.map +1 -0
  26. package/dist/src/e2ee/utils.d.ts +24 -0
  27. package/dist/src/e2ee/utils.d.ts.map +1 -0
  28. package/dist/src/e2ee/worker/FrameCryptor.d.ts +175 -0
  29. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
  30. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
  31. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
  32. package/dist/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  33. package/dist/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
  34. package/dist/src/index.d.ts +2 -0
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/logger.d.ts +4 -1
  37. package/dist/src/logger.d.ts.map +1 -1
  38. package/dist/src/options.d.ts +5 -0
  39. package/dist/src/options.d.ts.map +1 -1
  40. package/dist/src/proto/livekit_models.d.ts +2 -2
  41. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  42. package/dist/src/room/PCTransport.d.ts +3 -1
  43. package/dist/src/room/PCTransport.d.ts.map +1 -1
  44. package/dist/src/room/RTCEngine.d.ts +17 -3
  45. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  46. package/dist/src/room/Room.d.ts +10 -1
  47. package/dist/src/room/Room.d.ts.map +1 -1
  48. package/dist/src/room/events.d.ts +14 -2
  49. package/dist/src/room/events.d.ts.map +1 -1
  50. package/dist/src/room/participant/LocalParticipant.d.ts +9 -2
  51. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  52. package/dist/src/room/participant/Participant.d.ts +1 -0
  53. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  54. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  55. package/dist/src/room/track/LocalTrack.d.ts +3 -2
  56. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  57. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  58. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  59. package/dist/src/room/track/TrackPublication.d.ts +3 -0
  60. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  61. package/dist/src/room/track/facingMode.d.ts +41 -0
  62. package/dist/src/room/track/facingMode.d.ts.map +1 -0
  63. package/dist/src/room/track/options.d.ts +2 -2
  64. package/dist/src/room/track/options.d.ts.map +1 -1
  65. package/dist/src/room/track/utils.d.ts +5 -35
  66. package/dist/src/room/track/utils.d.ts.map +1 -1
  67. package/dist/src/room/utils.d.ts +2 -0
  68. package/dist/src/room/utils.d.ts.map +1 -1
  69. package/dist/src/test/MockMediaStreamTrack.d.ts.map +1 -1
  70. package/dist/ts4.2/src/api/SignalClient.d.ts +4 -1
  71. package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +45 -0
  72. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +42 -0
  73. package/dist/ts4.2/src/e2ee/constants.d.ts +14 -0
  74. package/dist/ts4.2/src/e2ee/errors.d.ts +11 -0
  75. package/dist/ts4.2/src/e2ee/index.d.ts +4 -0
  76. package/dist/ts4.2/src/e2ee/types.d.ts +129 -0
  77. package/dist/ts4.2/src/e2ee/utils.d.ts +24 -0
  78. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +175 -0
  79. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
  80. package/dist/ts4.2/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  81. package/dist/ts4.2/src/index.d.ts +2 -0
  82. package/dist/ts4.2/src/logger.d.ts +4 -1
  83. package/dist/ts4.2/src/options.d.ts +5 -0
  84. package/dist/ts4.2/src/proto/livekit_models.d.ts +2 -2
  85. package/dist/ts4.2/src/room/PCTransport.d.ts +3 -1
  86. package/dist/ts4.2/src/room/RTCEngine.d.ts +17 -3
  87. package/dist/ts4.2/src/room/Room.d.ts +10 -1
  88. package/dist/ts4.2/src/room/events.d.ts +14 -2
  89. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +9 -2
  90. package/dist/ts4.2/src/room/participant/Participant.d.ts +1 -0
  91. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +3 -2
  92. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +3 -0
  93. package/dist/ts4.2/src/room/track/facingMode.d.ts +41 -0
  94. package/dist/ts4.2/src/room/track/options.d.ts +6 -6
  95. package/dist/ts4.2/src/room/track/utils.d.ts +5 -35
  96. package/dist/ts4.2/src/room/utils.d.ts +2 -0
  97. package/package.json +17 -7
  98. package/src/api/SignalClient.ts +28 -9
  99. package/src/connectionHelper/checks/turn.ts +1 -0
  100. package/src/connectionHelper/checks/websocket.ts +1 -0
  101. package/src/e2ee/E2eeManager.ts +374 -0
  102. package/src/e2ee/KeyProvider.ts +77 -0
  103. package/src/e2ee/constants.ts +40 -0
  104. package/src/e2ee/errors.ts +16 -0
  105. package/src/e2ee/index.ts +3 -0
  106. package/src/e2ee/types.ts +160 -0
  107. package/src/e2ee/utils.ts +127 -0
  108. package/src/e2ee/worker/FrameCryptor.test.ts +21 -0
  109. package/src/e2ee/worker/FrameCryptor.ts +614 -0
  110. package/src/e2ee/worker/ParticipantKeyHandler.ts +129 -0
  111. package/src/e2ee/worker/e2ee.worker.ts +217 -0
  112. package/src/e2ee/worker/tsconfig.json +6 -0
  113. package/src/index.ts +2 -0
  114. package/src/logger.ts +10 -2
  115. package/src/options.ts +6 -0
  116. package/src/proto/livekit_models.ts +12 -12
  117. package/src/room/PCTransport.ts +39 -9
  118. package/src/room/RTCEngine.ts +127 -34
  119. package/src/room/Room.ts +83 -30
  120. package/src/room/defaults.ts +1 -1
  121. package/src/room/events.ts +14 -0
  122. package/src/room/participant/LocalParticipant.ts +82 -10
  123. package/src/room/participant/Participant.ts +4 -0
  124. package/src/room/track/LocalAudioTrack.ts +11 -4
  125. package/src/room/track/LocalTrack.ts +50 -43
  126. package/src/room/track/LocalVideoTrack.ts +5 -3
  127. package/src/room/track/RemoteVideoTrack.ts +2 -2
  128. package/src/room/track/TrackPublication.ts +9 -1
  129. package/src/room/track/facingMode.test.ts +30 -0
  130. package/src/room/track/facingMode.ts +103 -0
  131. package/src/room/track/options.ts +3 -2
  132. package/src/room/track/utils.test.ts +1 -30
  133. package/src/room/track/utils.ts +16 -91
  134. package/src/room/utils.ts +5 -0
  135. package/src/room/worker.d.ts +4 -0
  136. package/src/test/MockMediaStreamTrack.ts +1 -0
@@ -0,0 +1,127 @@
1
+ import { videoCodecs } from '../room/track/options';
2
+ import type { VideoCodec } from '../room/track/options';
3
+ import { ENCRYPTION_ALGORITHM } from './constants';
4
+
5
+ export function isE2EESupported() {
6
+ return isInsertableStreamSupported() || isScriptTransformSupported();
7
+ }
8
+
9
+ export function isScriptTransformSupported() {
10
+ // @ts-ignore
11
+ return typeof window.RTCRtpScriptTransform !== 'undefined';
12
+ }
13
+
14
+ export function isInsertableStreamSupported() {
15
+ return (
16
+ typeof window.RTCRtpSender !== 'undefined' &&
17
+ // @ts-ignore
18
+ typeof window.RTCRtpSender.prototype.createEncodedStreams !== 'undefined'
19
+ );
20
+ }
21
+
22
+ export function isVideoFrame(
23
+ frame: RTCEncodedAudioFrame | RTCEncodedVideoFrame,
24
+ ): frame is RTCEncodedVideoFrame {
25
+ return 'type' in frame;
26
+ }
27
+
28
+ export async function importKey(
29
+ keyBytes: Uint8Array | ArrayBuffer,
30
+ algorithm: string | { name: string } = { name: ENCRYPTION_ALGORITHM },
31
+ usage: 'derive' | 'encrypt' = 'encrypt',
32
+ ) {
33
+ // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
34
+ return crypto.subtle.importKey(
35
+ 'raw',
36
+ keyBytes,
37
+ algorithm,
38
+ false,
39
+ usage === 'derive' ? ['deriveBits', 'deriveKey'] : ['encrypt', 'decrypt'],
40
+ );
41
+ }
42
+
43
+ export async function createKeyMaterialFromString(password: string) {
44
+ let enc = new TextEncoder();
45
+
46
+ const keyMaterial = await crypto.subtle.importKey(
47
+ 'raw',
48
+ enc.encode(password),
49
+ {
50
+ name: 'PBKDF2',
51
+ },
52
+ false,
53
+ ['deriveBits', 'deriveKey'],
54
+ );
55
+
56
+ return keyMaterial;
57
+ }
58
+
59
+ function getAlgoOptions(algorithmName: string, salt: string) {
60
+ const textEncoder = new TextEncoder();
61
+ const encodedSalt = textEncoder.encode(salt);
62
+ switch (algorithmName) {
63
+ case 'HKDF':
64
+ return {
65
+ name: 'HKDF',
66
+ salt: encodedSalt,
67
+ hash: 'SHA-256',
68
+ info: new ArrayBuffer(128),
69
+ };
70
+ case 'PBKDF2': {
71
+ return {
72
+ name: 'PBKDF2',
73
+ salt: encodedSalt,
74
+ hash: 'SHA-256',
75
+ iterations: 100000,
76
+ };
77
+ }
78
+ default:
79
+ throw new Error(`algorithm ${algorithmName} is currently unsupported`);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Derives a set of keys from the master key.
85
+ * See https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.1
86
+ */
87
+ export async function deriveKeys(material: CryptoKey, salt: string) {
88
+ const algorithmOptions = getAlgoOptions(material.algorithm.name, salt);
89
+
90
+ // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey#HKDF
91
+ // https://developer.mozilla.org/en-US/docs/Web/API/HkdfParams
92
+ const encryptionKey = await crypto.subtle.deriveKey(
93
+ algorithmOptions,
94
+ material,
95
+ {
96
+ name: ENCRYPTION_ALGORITHM,
97
+ length: 128,
98
+ },
99
+ false,
100
+ ['encrypt', 'decrypt'],
101
+ );
102
+
103
+ return { material, encryptionKey };
104
+ }
105
+
106
+ export function createE2EEKey(): Uint8Array {
107
+ return window.crypto.getRandomValues(new Uint8Array(32));
108
+ }
109
+
110
+ export function mimeTypeToVideoCodecString(mimeType: string) {
111
+ const codec = mimeType.split('/')[1].toLowerCase() as VideoCodec;
112
+ if (!videoCodecs.includes(codec)) {
113
+ throw Error(`Video codec not supported: ${codec}`);
114
+ }
115
+ return codec;
116
+ }
117
+
118
+ /**
119
+ * Ratchets a key. See
120
+ * https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.5.1
121
+ */
122
+ export async function ratchet(material: CryptoKey, salt: string): Promise<ArrayBuffer> {
123
+ const algorithmOptions = getAlgoOptions(material.algorithm.name, salt);
124
+
125
+ // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveBits
126
+ return crypto.subtle.deriveBits(algorithmOptions, material, 256);
127
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { isFrameServerInjected } from './FrameCryptor';
5
+
6
+ describe('FrameCryptor', () => {
7
+ it('identifies server injected frame correctly', () => {
8
+ const frameTrailer = new TextEncoder().encode('LKROCKS');
9
+ const frameData = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, ...frameTrailer]).buffer;
10
+
11
+ expect(isFrameServerInjected(frameData, frameTrailer)).toBe(true);
12
+ });
13
+ it('identifies server non server injected frame correctly', () => {
14
+ const frameTrailer = new TextEncoder().encode('LKROCKS');
15
+ const frameData = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, ...frameTrailer, 10]);
16
+
17
+ expect(isFrameServerInjected(frameData.buffer, frameTrailer)).toBe(false);
18
+ frameData.fill(0);
19
+ expect(isFrameServerInjected(frameData.buffer, frameTrailer)).toBe(false);
20
+ });
21
+ });