livekit-client 1.11.4 → 1.12.0
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.
- package/README.md +1 -3
- package/dist/livekit-client.e2ee.worker.js +2 -0
- package/dist/livekit-client.e2ee.worker.js.map +1 -0
- package/dist/livekit-client.e2ee.worker.mjs +1525 -0
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -0
- package/dist/livekit-client.esm.mjs +4749 -4055
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts +4 -1
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/turn.d.ts.map +1 -1
- package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
- package/dist/src/e2ee/E2eeManager.d.ts +45 -0
- package/dist/src/e2ee/E2eeManager.d.ts.map +1 -0
- package/dist/src/e2ee/KeyProvider.d.ts +42 -0
- package/dist/src/e2ee/KeyProvider.d.ts.map +1 -0
- package/dist/src/e2ee/constants.d.ts +14 -0
- package/dist/src/e2ee/constants.d.ts.map +1 -0
- package/dist/src/e2ee/errors.d.ts +11 -0
- package/dist/src/e2ee/errors.d.ts.map +1 -0
- package/dist/src/e2ee/index.d.ts +4 -0
- package/dist/src/e2ee/index.d.ts.map +1 -0
- package/dist/src/e2ee/types.d.ts +129 -0
- package/dist/src/e2ee/types.d.ts.map +1 -0
- package/dist/src/e2ee/utils.d.ts +24 -0
- package/dist/src/e2ee/utils.d.ts.map +1 -0
- package/dist/src/e2ee/worker/FrameCryptor.d.ts +175 -0
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
- package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
- package/dist/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/logger.d.ts +4 -1
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/options.d.ts +5 -0
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/proto/livekit_models.d.ts +2 -2
- package/dist/src/proto/livekit_models.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +3 -1
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +17 -3
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +10 -0
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/events.d.ts +14 -2
- package/dist/src/room/events.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +7 -2
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/Participant.d.ts +1 -0
- package/dist/src/room/participant/Participant.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/TrackPublication.d.ts +3 -0
- package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/options.d.ts +2 -2
- package/dist/src/room/track/options.d.ts.map +1 -1
- package/dist/src/room/track/utils.d.ts +9 -0
- package/dist/src/room/track/utils.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +2 -0
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/src/test/MockMediaStreamTrack.d.ts.map +1 -1
- package/dist/ts4.2/src/api/SignalClient.d.ts +4 -1
- package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +45 -0
- package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +42 -0
- package/dist/ts4.2/src/e2ee/constants.d.ts +14 -0
- package/dist/ts4.2/src/e2ee/errors.d.ts +11 -0
- package/dist/ts4.2/src/e2ee/index.d.ts +4 -0
- package/dist/ts4.2/src/e2ee/types.d.ts +129 -0
- package/dist/ts4.2/src/e2ee/utils.d.ts +24 -0
- package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +175 -0
- package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
- package/dist/ts4.2/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/ts4.2/src/index.d.ts +1 -0
- package/dist/ts4.2/src/logger.d.ts +4 -1
- package/dist/ts4.2/src/options.d.ts +5 -0
- package/dist/ts4.2/src/proto/livekit_models.d.ts +2 -2
- package/dist/ts4.2/src/room/PCTransport.d.ts +3 -1
- package/dist/ts4.2/src/room/RTCEngine.d.ts +17 -3
- package/dist/ts4.2/src/room/Room.d.ts +10 -0
- package/dist/ts4.2/src/room/events.d.ts +14 -2
- package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +7 -2
- package/dist/ts4.2/src/room/participant/Participant.d.ts +1 -0
- package/dist/ts4.2/src/room/track/TrackPublication.d.ts +3 -0
- package/dist/ts4.2/src/room/track/options.d.ts +6 -6
- package/dist/ts4.2/src/room/track/utils.d.ts +9 -0
- package/dist/ts4.2/src/room/utils.d.ts +2 -0
- package/package.json +17 -7
- package/src/api/SignalClient.ts +28 -9
- package/src/connectionHelper/checks/turn.ts +1 -0
- package/src/connectionHelper/checks/websocket.ts +1 -0
- package/src/e2ee/E2eeManager.ts +374 -0
- package/src/e2ee/KeyProvider.ts +77 -0
- package/src/e2ee/constants.ts +40 -0
- package/src/e2ee/errors.ts +16 -0
- package/src/e2ee/index.ts +3 -0
- package/src/e2ee/types.ts +160 -0
- package/src/e2ee/utils.ts +127 -0
- package/src/e2ee/worker/FrameCryptor.test.ts +21 -0
- package/src/e2ee/worker/FrameCryptor.ts +614 -0
- package/src/e2ee/worker/ParticipantKeyHandler.ts +129 -0
- package/src/e2ee/worker/e2ee.worker.ts +217 -0
- package/src/e2ee/worker/tsconfig.json +6 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +10 -2
- package/src/options.ts +6 -0
- package/src/proto/livekit_models.ts +12 -12
- package/src/room/PCTransport.ts +39 -9
- package/src/room/RTCEngine.ts +127 -34
- package/src/room/Room.ts +77 -22
- package/src/room/defaults.ts +1 -1
- package/src/room/events.ts +14 -0
- package/src/room/participant/LocalParticipant.ts +52 -8
- package/src/room/participant/Participant.ts +4 -0
- package/src/room/track/LocalTrack.ts +5 -4
- package/src/room/track/RemoteVideoTrack.ts +2 -2
- package/src/room/track/TrackPublication.ts +9 -1
- package/src/room/track/options.ts +3 -2
- package/src/room/track/utils.ts +27 -0
- package/src/room/utils.ts +5 -0
- package/src/room/worker.d.ts +4 -0
- 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
|
+
});
|