@dtelecom/livekit-client 1.12.1
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/LICENSE +175 -0
- package/README.md +315 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js +2 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js.map +1 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs +1633 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.esm.mjs +22545 -0
- package/dist/@dtelecom/livekit-client.esm.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.umd.js +2 -0
- package/dist/@dtelecom/livekit-client.umd.js.map +1 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts +102 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
- package/dist/@dtelecom/src/index.d.ts +38 -0
- package/dist/@dtelecom/src/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/logger.d.ts +29 -0
- package/dist/@dtelecom/src/logger.d.ts.map +1 -0
- package/dist/@dtelecom/src/options.d.ts +104 -0
- package/dist/@dtelecom/src/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts +41 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/@dtelecom/src/room/Room.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/@dtelecom/src/room/defaults.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/@dtelecom/src/room/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/@dtelecom/src/room/events.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/@dtelecom/src/room/stats.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/@dtelecom/src/room/timers.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/create.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/options.d.ts +272 -0
- package/dist/@dtelecom/src/room/track/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/@dtelecom/src/room/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/@dtelecom/src/room/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/@dtelecom/src/test/mocks.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts.map +1 -0
- package/dist/@dtelecom/src/version.d.ts +3 -0
- package/dist/@dtelecom/src/version.d.ts.map +1 -0
- package/dist/ts4.2/@dtelecom/src/api/SignalClient.d.ts +105 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/ts4.2/@dtelecom/src/index.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/logger.d.ts +29 -0
- package/dist/ts4.2/@dtelecom/src/options.d.ts +104 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/ts4.2/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/ts4.2/@dtelecom/src/room/PCTransport.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/ts4.2/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/ts4.2/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/ts4.2/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/ts4.2/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/ts4.2/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/ts4.2/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/ts4.2/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/ts4.2/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/ts4.2/@dtelecom/src/room/track/options.d.ts +280 -0
- package/dist/ts4.2/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/ts4.2/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/ts4.2/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/ts4.2/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/ts4.2/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/version.d.ts +3 -0
- package/package.json +102 -0
- package/src/api/SignalClient.ts +790 -0
- package/src/connectionHelper/ConnectionCheck.ts +90 -0
- package/src/connectionHelper/checks/Checker.ts +163 -0
- package/src/connectionHelper/checks/publishAudio.ts +33 -0
- package/src/connectionHelper/checks/publishVideo.ts +33 -0
- package/src/connectionHelper/checks/reconnect.ts +45 -0
- package/src/connectionHelper/checks/turn.ts +54 -0
- package/src/connectionHelper/checks/webrtc.ts +82 -0
- package/src/connectionHelper/checks/websocket.ts +27 -0
- package/src/e2ee/E2eeManager.ts +375 -0
- package/src/e2ee/KeyProvider.ts +78 -0
- package/src/e2ee/constants.ts +44 -0
- package/src/e2ee/errors.ts +16 -0
- package/src/e2ee/index.ts +3 -0
- package/src/e2ee/types.ts +161 -0
- package/src/e2ee/utils.ts +127 -0
- package/src/e2ee/worker/FrameCryptor.test.ts +19 -0
- package/src/e2ee/worker/FrameCryptor.ts +612 -0
- package/src/e2ee/worker/ParticipantKeyHandler.ts +175 -0
- package/src/e2ee/worker/e2ee.worker.ts +223 -0
- package/src/e2ee/worker/tsconfig.json +6 -0
- package/src/index.ts +85 -0
- package/src/logger.ts +64 -0
- package/src/options.ts +127 -0
- package/src/proto/livekit_models_pb.ts +2096 -0
- package/src/proto/livekit_rtc_pb.ts +2332 -0
- package/src/room/DefaultReconnectPolicy.ts +35 -0
- package/src/room/DeviceManager.ts +88 -0
- package/src/room/PCTransport.ts +452 -0
- package/src/room/RTCEngine.ts +1421 -0
- package/src/room/ReconnectPolicy.ts +27 -0
- package/src/room/RegionUrlProvider.ts +82 -0
- package/src/room/Room.test.ts +30 -0
- package/src/room/Room.ts +1907 -0
- package/src/room/defaults.ts +49 -0
- package/src/room/errors.ts +90 -0
- package/src/room/events.ts +535 -0
- package/src/room/participant/LocalParticipant.ts +1350 -0
- package/src/room/participant/Participant.ts +299 -0
- package/src/room/participant/ParticipantTrackPermission.ts +42 -0
- package/src/room/participant/RemoteParticipant.ts +359 -0
- package/src/room/participant/publishUtils.test.ts +189 -0
- package/src/room/participant/publishUtils.ts +399 -0
- package/src/room/stats.ts +136 -0
- package/src/room/timers.ts +16 -0
- package/src/room/track/LocalAudioTrack.ts +171 -0
- package/src/room/track/LocalTrack.ts +430 -0
- package/src/room/track/LocalTrackPublication.ts +87 -0
- package/src/room/track/LocalVideoTrack.test.ts +73 -0
- package/src/room/track/LocalVideoTrack.ts +513 -0
- package/src/room/track/RemoteAudioTrack.ts +248 -0
- package/src/room/track/RemoteTrack.ts +62 -0
- package/src/room/track/RemoteTrackPublication.ts +311 -0
- package/src/room/track/RemoteVideoTrack.test.ts +152 -0
- package/src/room/track/RemoteVideoTrack.ts +410 -0
- package/src/room/track/Track.ts +452 -0
- package/src/room/track/TrackPublication.ts +158 -0
- package/src/room/track/create.ts +143 -0
- package/src/room/track/facingMode.test.ts +31 -0
- package/src/room/track/facingMode.ts +103 -0
- package/src/room/track/options.ts +362 -0
- package/src/room/track/processor/types.ts +20 -0
- package/src/room/track/types.ts +25 -0
- package/src/room/track/utils.test.ts +111 -0
- package/src/room/track/utils.ts +183 -0
- package/src/room/types.ts +39 -0
- package/src/room/utils.test.ts +16 -0
- package/src/room/utils.ts +501 -0
- package/src/room/worker.d.ts +4 -0
- package/src/test/MockMediaStreamTrack.ts +84 -0
- package/src/test/mocks.ts +19 -0
- package/src/utils/AsyncQueue.test.ts +100 -0
- package/src/utils/AsyncQueue.ts +57 -0
- package/src/utils/browserParser.test.ts +88 -0
- package/src/utils/browserParser.ts +74 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type TypedEventEmitter from 'typed-emitter';
|
|
3
|
+
import { workerLogger } from '../../logger';
|
|
4
|
+
import { KEYRING_SIZE } from '../constants';
|
|
5
|
+
import type { KeyProviderOptions, KeySet, ParticipantKeyHandlerCallbacks } from '../types';
|
|
6
|
+
import { deriveKeys, importKey, ratchet } from '../utils';
|
|
7
|
+
|
|
8
|
+
// TODO ParticipantKeyHandlers currently don't get destroyed on participant disconnect
|
|
9
|
+
// we could do this by having a separate worker message on participant disconnected.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* ParticipantKeyHandler is responsible for providing a cryptor instance with the
|
|
13
|
+
* en-/decryption key of a participant. It assumes that all tracks of a specific participant
|
|
14
|
+
* are encrypted with the same key.
|
|
15
|
+
* Additionally it exposes a method to ratchet a key which can be used by the cryptor either automatically
|
|
16
|
+
* if decryption fails or can be triggered manually on both sender and receiver side.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export class ParticipantKeyHandler extends (EventEmitter as new () => TypedEventEmitter<ParticipantKeyHandlerCallbacks>) {
|
|
20
|
+
private currentKeyIndex: number;
|
|
21
|
+
|
|
22
|
+
private cryptoKeyRing: Array<KeySet>;
|
|
23
|
+
|
|
24
|
+
private enabled: boolean;
|
|
25
|
+
|
|
26
|
+
private keyProviderOptions: KeyProviderOptions;
|
|
27
|
+
|
|
28
|
+
private ratchetPromiseMap: Map<number, Promise<CryptoKey>>;
|
|
29
|
+
|
|
30
|
+
private participantId: string | undefined;
|
|
31
|
+
|
|
32
|
+
private decryptionFailureCount = 0;
|
|
33
|
+
|
|
34
|
+
private _hasValidKey: boolean = true;
|
|
35
|
+
|
|
36
|
+
get hasValidKey() {
|
|
37
|
+
return this._hasValidKey;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
participantId: string | undefined,
|
|
42
|
+
isEnabled: boolean,
|
|
43
|
+
keyProviderOptions: KeyProviderOptions,
|
|
44
|
+
) {
|
|
45
|
+
super();
|
|
46
|
+
this.currentKeyIndex = 0;
|
|
47
|
+
this.cryptoKeyRing = new Array(KEYRING_SIZE);
|
|
48
|
+
this.enabled = isEnabled;
|
|
49
|
+
this.keyProviderOptions = keyProviderOptions;
|
|
50
|
+
this.ratchetPromiseMap = new Map();
|
|
51
|
+
this.participantId = participantId;
|
|
52
|
+
this.resetKeyStatus();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setEnabled(enabled: boolean) {
|
|
56
|
+
this.enabled = enabled;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
decryptionFailure() {
|
|
60
|
+
if (this.keyProviderOptions.failureTolerance < 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.decryptionFailureCount += 1;
|
|
64
|
+
|
|
65
|
+
if (this.decryptionFailureCount > this.keyProviderOptions.failureTolerance) {
|
|
66
|
+
this._hasValidKey = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
decryptionSuccess() {
|
|
71
|
+
this.resetKeyStatus();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Call this after user initiated ratchet or a new key has been set in order to make sure to mark potentially
|
|
76
|
+
* invalid keys as valid again
|
|
77
|
+
*/
|
|
78
|
+
resetKeyStatus() {
|
|
79
|
+
this.decryptionFailureCount = 0;
|
|
80
|
+
this._hasValidKey = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Ratchets the current key (or the one at keyIndex if provided) and
|
|
85
|
+
* returns the ratcheted material
|
|
86
|
+
* if `setKey` is true (default), it will also set the ratcheted key directly on the crypto key ring
|
|
87
|
+
* @param keyIndex
|
|
88
|
+
* @param setKey
|
|
89
|
+
*/
|
|
90
|
+
ratchetKey(keyIndex?: number, setKey = true): Promise<CryptoKey> {
|
|
91
|
+
const currentKeyIndex = (keyIndex ??= this.getCurrentKeyIndex());
|
|
92
|
+
|
|
93
|
+
const existingPromise = this.ratchetPromiseMap.get(currentKeyIndex);
|
|
94
|
+
if (typeof existingPromise !== 'undefined') {
|
|
95
|
+
return existingPromise;
|
|
96
|
+
}
|
|
97
|
+
const ratchetPromise = new Promise<CryptoKey>(async (resolve, reject) => {
|
|
98
|
+
try {
|
|
99
|
+
const currentMaterial = this.getKeySet(currentKeyIndex).material;
|
|
100
|
+
const newMaterial = await importKey(
|
|
101
|
+
await ratchet(currentMaterial, this.keyProviderOptions.ratchetSalt),
|
|
102
|
+
currentMaterial.algorithm.name,
|
|
103
|
+
'derive',
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (setKey) {
|
|
107
|
+
this.setKeyFromMaterial(newMaterial, currentKeyIndex, true);
|
|
108
|
+
}
|
|
109
|
+
this.emit('keyRatcheted', newMaterial, keyIndex, this.participantId);
|
|
110
|
+
resolve(newMaterial);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
reject(e);
|
|
113
|
+
} finally {
|
|
114
|
+
this.ratchetPromiseMap.delete(currentKeyIndex);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
this.ratchetPromiseMap.set(currentKeyIndex, ratchetPromise);
|
|
118
|
+
return ratchetPromise;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
|
123
|
+
* and derives encryption keys from the material and sets it on the key ring buffer
|
|
124
|
+
* together with the material
|
|
125
|
+
* also resets the valid key property and updates the currentKeyIndex
|
|
126
|
+
*/
|
|
127
|
+
async setKey(material: CryptoKey, keyIndex = 0) {
|
|
128
|
+
await this.setKeyFromMaterial(material, keyIndex);
|
|
129
|
+
this.resetKeyStatus();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
|
134
|
+
* and derives encryption keys from the material and sets it on the key ring buffer
|
|
135
|
+
* together with the material
|
|
136
|
+
* also updates the currentKeyIndex
|
|
137
|
+
*/
|
|
138
|
+
async setKeyFromMaterial(material: CryptoKey, keyIndex = 0, emitRatchetEvent = false) {
|
|
139
|
+
workerLogger.debug('setting new key');
|
|
140
|
+
if (keyIndex >= 0) {
|
|
141
|
+
this.currentKeyIndex = keyIndex % this.cryptoKeyRing.length;
|
|
142
|
+
}
|
|
143
|
+
const keySet = await deriveKeys(material, this.keyProviderOptions.ratchetSalt);
|
|
144
|
+
this.setKeySet(keySet, this.currentKeyIndex, emitRatchetEvent);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async setKeySet(keySet: KeySet, keyIndex: number, emitRatchetEvent = false) {
|
|
148
|
+
this.cryptoKeyRing[keyIndex % this.cryptoKeyRing.length] = keySet;
|
|
149
|
+
if (emitRatchetEvent) {
|
|
150
|
+
this.emit('keyRatcheted', keySet.material, keyIndex, this.participantId);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async setCurrentKeyIndex(index: number) {
|
|
155
|
+
this.currentKeyIndex = index % this.cryptoKeyRing.length;
|
|
156
|
+
this.resetKeyStatus();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
isEnabled() {
|
|
160
|
+
return this.enabled;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getCurrentKeyIndex() {
|
|
164
|
+
return this.currentKeyIndex;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* returns currently used KeySet or the one at `keyIndex` if provided
|
|
169
|
+
* @param keyIndex
|
|
170
|
+
* @returns
|
|
171
|
+
*/
|
|
172
|
+
getKeySet(keyIndex?: number) {
|
|
173
|
+
return this.cryptoKeyRing[keyIndex ?? this.currentKeyIndex];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { workerLogger } from '../../logger';
|
|
2
|
+
import { KEY_PROVIDER_DEFAULTS } from '../constants';
|
|
3
|
+
import { CryptorErrorReason } from '../errors';
|
|
4
|
+
import type {
|
|
5
|
+
E2EEWorkerMessage,
|
|
6
|
+
EnableMessage,
|
|
7
|
+
ErrorMessage,
|
|
8
|
+
KeyProviderOptions,
|
|
9
|
+
RatchetMessage,
|
|
10
|
+
RatchetRequestMessage,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import { FrameCryptor } from './FrameCryptor';
|
|
13
|
+
import { ParticipantKeyHandler } from './ParticipantKeyHandler';
|
|
14
|
+
|
|
15
|
+
const participantCryptors: FrameCryptor[] = [];
|
|
16
|
+
const participantKeys: Map<string, ParticipantKeyHandler> = new Map();
|
|
17
|
+
|
|
18
|
+
let publishCryptors: FrameCryptor[] = [];
|
|
19
|
+
let publisherKeys: ParticipantKeyHandler;
|
|
20
|
+
|
|
21
|
+
let isEncryptionEnabled: boolean = false;
|
|
22
|
+
|
|
23
|
+
let useSharedKey: boolean = false;
|
|
24
|
+
|
|
25
|
+
let sharedKey: CryptoKey | undefined;
|
|
26
|
+
|
|
27
|
+
let keyProviderOptions: KeyProviderOptions = KEY_PROVIDER_DEFAULTS;
|
|
28
|
+
|
|
29
|
+
workerLogger.setDefaultLevel('info');
|
|
30
|
+
|
|
31
|
+
onmessage = (ev) => {
|
|
32
|
+
const { kind, data }: E2EEWorkerMessage = ev.data;
|
|
33
|
+
|
|
34
|
+
switch (kind) {
|
|
35
|
+
case 'init':
|
|
36
|
+
workerLogger.info('worker initialized');
|
|
37
|
+
keyProviderOptions = data.keyProviderOptions;
|
|
38
|
+
useSharedKey = !!data.keyProviderOptions.sharedKey;
|
|
39
|
+
// acknowledge init successful
|
|
40
|
+
const enableMsg: EnableMessage = {
|
|
41
|
+
kind: 'enable',
|
|
42
|
+
data: { enabled: isEncryptionEnabled },
|
|
43
|
+
};
|
|
44
|
+
publisherKeys = new ParticipantKeyHandler(undefined, isEncryptionEnabled, keyProviderOptions);
|
|
45
|
+
publisherKeys.on('keyRatcheted', emitRatchetedKeys);
|
|
46
|
+
postMessage(enableMsg);
|
|
47
|
+
break;
|
|
48
|
+
case 'enable':
|
|
49
|
+
setEncryptionEnabled(data.enabled, data.participantId);
|
|
50
|
+
workerLogger.info('updated e2ee enabled status');
|
|
51
|
+
// acknowledge enable call successful
|
|
52
|
+
postMessage(ev.data);
|
|
53
|
+
break;
|
|
54
|
+
case 'decode':
|
|
55
|
+
let cryptor = getTrackCryptor(data.participantId, data.trackId);
|
|
56
|
+
cryptor.setupTransform(
|
|
57
|
+
kind,
|
|
58
|
+
data.readableStream,
|
|
59
|
+
data.writableStream,
|
|
60
|
+
data.trackId,
|
|
61
|
+
data.codec,
|
|
62
|
+
);
|
|
63
|
+
break;
|
|
64
|
+
case 'encode':
|
|
65
|
+
let pubCryptor = getPublisherCryptor(data.trackId);
|
|
66
|
+
pubCryptor.setupTransform(
|
|
67
|
+
kind,
|
|
68
|
+
data.readableStream,
|
|
69
|
+
data.writableStream,
|
|
70
|
+
data.trackId,
|
|
71
|
+
data.codec,
|
|
72
|
+
);
|
|
73
|
+
break;
|
|
74
|
+
case 'setKey':
|
|
75
|
+
if (useSharedKey) {
|
|
76
|
+
workerLogger.debug('set shared key');
|
|
77
|
+
setSharedKey(data.key, data.keyIndex);
|
|
78
|
+
} else if (data.participantId) {
|
|
79
|
+
getParticipantKeyHandler(data.participantId).setKey(data.key, data.keyIndex);
|
|
80
|
+
} else {
|
|
81
|
+
workerLogger.error('no participant Id was provided and shared key usage is disabled');
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case 'removeTransform':
|
|
85
|
+
unsetCryptorParticipant(data.trackId);
|
|
86
|
+
break;
|
|
87
|
+
case 'updateCodec':
|
|
88
|
+
getTrackCryptor(data.participantId, data.trackId).setVideoCodec(data.codec);
|
|
89
|
+
break;
|
|
90
|
+
case 'setRTPMap':
|
|
91
|
+
publishCryptors.forEach((cr) => {
|
|
92
|
+
cr.setRtpMap(data.map);
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
case 'ratchetRequest':
|
|
96
|
+
handleRatchetRequest(data);
|
|
97
|
+
default:
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
async function handleRatchetRequest(data: RatchetRequestMessage['data']) {
|
|
103
|
+
const keyHandler = getParticipantKeyHandler(data.participantId);
|
|
104
|
+
await keyHandler.ratchetKey(data.keyIndex);
|
|
105
|
+
keyHandler.resetKeyStatus();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getTrackCryptor(participantId: string, trackId: string) {
|
|
109
|
+
let cryptor = participantCryptors.find((c) => c.getTrackId() === trackId);
|
|
110
|
+
if (!cryptor) {
|
|
111
|
+
workerLogger.info('creating new cryptor for', { participantId });
|
|
112
|
+
if (!keyProviderOptions) {
|
|
113
|
+
throw Error('Missing keyProvider options');
|
|
114
|
+
}
|
|
115
|
+
cryptor = new FrameCryptor({
|
|
116
|
+
participantId,
|
|
117
|
+
keys: getParticipantKeyHandler(participantId),
|
|
118
|
+
keyProviderOptions,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
setupCryptorErrorEvents(cryptor);
|
|
122
|
+
participantCryptors.push(cryptor);
|
|
123
|
+
} else if (participantId !== cryptor.getParticipantId()) {
|
|
124
|
+
// assign new participant id to track cryptor and pass in correct key handler
|
|
125
|
+
cryptor.setParticipant(participantId, getParticipantKeyHandler(participantId));
|
|
126
|
+
}
|
|
127
|
+
if (sharedKey) {
|
|
128
|
+
}
|
|
129
|
+
return cryptor;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getParticipantKeyHandler(participantId?: string) {
|
|
133
|
+
if (!participantId) {
|
|
134
|
+
return publisherKeys!;
|
|
135
|
+
}
|
|
136
|
+
let keys = participantKeys.get(participantId);
|
|
137
|
+
if (!keys) {
|
|
138
|
+
keys = new ParticipantKeyHandler(participantId, true, keyProviderOptions);
|
|
139
|
+
if (sharedKey) {
|
|
140
|
+
keys.setKey(sharedKey);
|
|
141
|
+
}
|
|
142
|
+
participantKeys.set(participantId, keys);
|
|
143
|
+
}
|
|
144
|
+
return keys;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function unsetCryptorParticipant(trackId: string) {
|
|
148
|
+
participantCryptors.find((c) => c.getTrackId() === trackId)?.unsetParticipant();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getPublisherCryptor(trackId: string) {
|
|
152
|
+
let publishCryptor = publishCryptors.find((cryptor) => cryptor.getTrackId() === trackId);
|
|
153
|
+
if (!publishCryptor) {
|
|
154
|
+
if (!keyProviderOptions) {
|
|
155
|
+
throw new TypeError('Missing keyProvider options');
|
|
156
|
+
}
|
|
157
|
+
publishCryptor = new FrameCryptor({
|
|
158
|
+
keys: publisherKeys!,
|
|
159
|
+
participantId: 'publisher',
|
|
160
|
+
keyProviderOptions,
|
|
161
|
+
});
|
|
162
|
+
setupCryptorErrorEvents(publishCryptor);
|
|
163
|
+
publishCryptors.push(publishCryptor);
|
|
164
|
+
}
|
|
165
|
+
return publishCryptor;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function setEncryptionEnabled(enable: boolean, participantId?: string) {
|
|
169
|
+
if (!participantId) {
|
|
170
|
+
isEncryptionEnabled = enable;
|
|
171
|
+
publisherKeys.setEnabled(enable);
|
|
172
|
+
} else {
|
|
173
|
+
getParticipantKeyHandler(participantId).setEnabled(enable);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function setSharedKey(key: CryptoKey, index?: number) {
|
|
178
|
+
workerLogger.debug('setting shared key');
|
|
179
|
+
sharedKey = key;
|
|
180
|
+
publisherKeys?.setKey(key, index);
|
|
181
|
+
for (const [, keyHandler] of participantKeys) {
|
|
182
|
+
keyHandler.setKey(key, index);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function setupCryptorErrorEvents(cryptor: FrameCryptor) {
|
|
187
|
+
cryptor.on('cryptorError', (error) => {
|
|
188
|
+
const msg: ErrorMessage = {
|
|
189
|
+
kind: 'error',
|
|
190
|
+
data: { error: new Error(`${CryptorErrorReason[error.reason]}: ${error.message}`) },
|
|
191
|
+
};
|
|
192
|
+
postMessage(msg);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function emitRatchetedKeys(material: CryptoKey, keyIndex?: number) {
|
|
197
|
+
const msg: RatchetMessage = {
|
|
198
|
+
kind: `ratchetKey`,
|
|
199
|
+
data: {
|
|
200
|
+
// participantId,
|
|
201
|
+
keyIndex,
|
|
202
|
+
material,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
postMessage(msg);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Operations using RTCRtpScriptTransform.
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
if (self.RTCTransformEvent) {
|
|
211
|
+
workerLogger.debug('setup transform event');
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
self.onrtctransform = (event) => {
|
|
214
|
+
const transformer = event.transformer;
|
|
215
|
+
workerLogger.debug('transformer', transformer);
|
|
216
|
+
transformer.handled = true;
|
|
217
|
+
const { kind, participantId, trackId, codec } = transformer.options;
|
|
218
|
+
const cryptor =
|
|
219
|
+
kind === 'encode' ? getPublisherCryptor(trackId) : getTrackCryptor(participantId, trackId);
|
|
220
|
+
workerLogger.debug('transform', { codec });
|
|
221
|
+
cryptor.setupTransform(kind, transformer.readable, transformer.writable, trackId, codec);
|
|
222
|
+
};
|
|
223
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LogLevel, setLogExtension, setLogLevel } from './logger';
|
|
2
|
+
import { DataPacket_Kind, DisconnectReason, VideoQuality } from './proto/livekit_models_pb';
|
|
3
|
+
import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
|
|
4
|
+
import Room, { ConnectionState, RoomState } from './room/Room';
|
|
5
|
+
import LocalParticipant from './room/participant/LocalParticipant';
|
|
6
|
+
import Participant, { ConnectionQuality } from './room/participant/Participant';
|
|
7
|
+
import type { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
|
|
8
|
+
import RemoteParticipant from './room/participant/RemoteParticipant';
|
|
9
|
+
import CriticalTimers from './room/timers';
|
|
10
|
+
import LocalAudioTrack from './room/track/LocalAudioTrack';
|
|
11
|
+
import LocalTrack from './room/track/LocalTrack';
|
|
12
|
+
import LocalTrackPublication from './room/track/LocalTrackPublication';
|
|
13
|
+
import LocalVideoTrack from './room/track/LocalVideoTrack';
|
|
14
|
+
import RemoteAudioTrack from './room/track/RemoteAudioTrack';
|
|
15
|
+
import RemoteTrack from './room/track/RemoteTrack';
|
|
16
|
+
import RemoteTrackPublication from './room/track/RemoteTrackPublication';
|
|
17
|
+
import type { ElementInfo } from './room/track/RemoteVideoTrack';
|
|
18
|
+
import RemoteVideoTrack from './room/track/RemoteVideoTrack';
|
|
19
|
+
import { TrackPublication } from './room/track/TrackPublication';
|
|
20
|
+
import type { LiveKitReactNativeInfo } from './room/types';
|
|
21
|
+
import type { AudioAnalyserOptions } from './room/utils';
|
|
22
|
+
import {
|
|
23
|
+
createAudioAnalyser,
|
|
24
|
+
getEmptyAudioStreamTrack,
|
|
25
|
+
getEmptyVideoStreamTrack,
|
|
26
|
+
isBrowserSupported,
|
|
27
|
+
supportsAV1,
|
|
28
|
+
supportsAdaptiveStream,
|
|
29
|
+
supportsDynacast,
|
|
30
|
+
supportsVP9,
|
|
31
|
+
} from './room/utils';
|
|
32
|
+
|
|
33
|
+
export * from './connectionHelper/ConnectionCheck';
|
|
34
|
+
export * from './options';
|
|
35
|
+
export * from './room/errors';
|
|
36
|
+
export * from './room/events';
|
|
37
|
+
export * from './room/track/Track';
|
|
38
|
+
export * from './room/track/create';
|
|
39
|
+
export * from './room/track/options';
|
|
40
|
+
export { facingModeFromDeviceLabel, facingModeFromLocalTrack } from './room/track/facingMode';
|
|
41
|
+
export * from './room/track/types';
|
|
42
|
+
export type { DataPublishOptions, SimulationScenario } from './room/types';
|
|
43
|
+
export * from './version';
|
|
44
|
+
export * from './e2ee';
|
|
45
|
+
export * from './room/track/processor/types';
|
|
46
|
+
export {
|
|
47
|
+
setLogLevel,
|
|
48
|
+
setLogExtension,
|
|
49
|
+
getEmptyAudioStreamTrack,
|
|
50
|
+
getEmptyVideoStreamTrack,
|
|
51
|
+
isBrowserSupported,
|
|
52
|
+
supportsAdaptiveStream,
|
|
53
|
+
supportsDynacast,
|
|
54
|
+
supportsAV1,
|
|
55
|
+
supportsVP9,
|
|
56
|
+
createAudioAnalyser,
|
|
57
|
+
LogLevel,
|
|
58
|
+
Room,
|
|
59
|
+
ConnectionState,
|
|
60
|
+
RoomState,
|
|
61
|
+
DataPacket_Kind,
|
|
62
|
+
DisconnectReason,
|
|
63
|
+
Participant,
|
|
64
|
+
RemoteParticipant,
|
|
65
|
+
LocalParticipant,
|
|
66
|
+
LocalAudioTrack,
|
|
67
|
+
LocalVideoTrack,
|
|
68
|
+
LocalTrack,
|
|
69
|
+
LocalTrackPublication,
|
|
70
|
+
RemoteTrack,
|
|
71
|
+
RemoteAudioTrack,
|
|
72
|
+
RemoteVideoTrack,
|
|
73
|
+
RemoteTrackPublication,
|
|
74
|
+
TrackPublication,
|
|
75
|
+
VideoQuality,
|
|
76
|
+
ConnectionQuality,
|
|
77
|
+
DefaultReconnectPolicy,
|
|
78
|
+
CriticalTimers,
|
|
79
|
+
};
|
|
80
|
+
export type {
|
|
81
|
+
ElementInfo,
|
|
82
|
+
ParticipantTrackPermission,
|
|
83
|
+
AudioAnalyserOptions,
|
|
84
|
+
LiveKitReactNativeInfo,
|
|
85
|
+
};
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as log from 'loglevel';
|
|
2
|
+
|
|
3
|
+
export enum LogLevel {
|
|
4
|
+
trace = 0,
|
|
5
|
+
debug = 1,
|
|
6
|
+
info = 2,
|
|
7
|
+
warn = 3,
|
|
8
|
+
error = 4,
|
|
9
|
+
silent = 5,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type LogLevelString = keyof typeof LogLevel;
|
|
13
|
+
|
|
14
|
+
type StructuredLogger = {
|
|
15
|
+
trace: (msg: string, context?: object) => void;
|
|
16
|
+
debug: (msg: string, context?: object) => void;
|
|
17
|
+
info: (msg: string, context?: object) => void;
|
|
18
|
+
warn: (msg: string, context?: object) => void;
|
|
19
|
+
error: (msg: string, context?: object) => void;
|
|
20
|
+
setDefaultLevel: (level: log.LogLevelDesc) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const livekitLogger = log.getLogger('livekit');
|
|
24
|
+
|
|
25
|
+
livekitLogger.setDefaultLevel(LogLevel.info);
|
|
26
|
+
|
|
27
|
+
export default livekitLogger as StructuredLogger;
|
|
28
|
+
|
|
29
|
+
export function setLogLevel(level: LogLevel | LogLevelString, loggerName?: 'livekit' | 'lk-e2ee') {
|
|
30
|
+
if (loggerName) {
|
|
31
|
+
log.getLogger(loggerName).setLevel(level);
|
|
32
|
+
}
|
|
33
|
+
for (const logger of Object.values(log.getLoggers())) {
|
|
34
|
+
logger.setLevel(level);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type LogExtension = (level: LogLevel, msg: string, context?: object) => void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* use this to hook into the logging function to allow sending internal livekit logs to third party services
|
|
42
|
+
* if set, the browser logs will lose their stacktrace information (see https://github.com/pimterry/loglevel#writing-plugins)
|
|
43
|
+
*/
|
|
44
|
+
export function setLogExtension(extension: LogExtension) {
|
|
45
|
+
const originalFactory = livekitLogger.methodFactory;
|
|
46
|
+
|
|
47
|
+
livekitLogger.methodFactory = (methodName, configLevel, loggerName) => {
|
|
48
|
+
const rawMethod = originalFactory(methodName, configLevel, loggerName);
|
|
49
|
+
|
|
50
|
+
const logLevel = LogLevel[methodName as LogLevelString];
|
|
51
|
+
const needLog = logLevel >= configLevel && logLevel < LogLevel.silent;
|
|
52
|
+
|
|
53
|
+
return (msg, context?: [msg: string, context: object]) => {
|
|
54
|
+
if (context) rawMethod(msg, context);
|
|
55
|
+
else rawMethod(msg);
|
|
56
|
+
if (needLog) {
|
|
57
|
+
extension(logLevel, msg, context);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
livekitLogger.setLevel(livekitLogger.getLevel()); // Be sure to call setLevel method in order to apply plugin
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const workerLogger = log.getLogger('lk-e2ee') as StructuredLogger;
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { E2EEOptions } from './e2ee/types';
|
|
2
|
+
import type { ReconnectPolicy } from './room/ReconnectPolicy';
|
|
3
|
+
import type {
|
|
4
|
+
AudioCaptureOptions,
|
|
5
|
+
AudioOutputOptions,
|
|
6
|
+
TrackPublishDefaults,
|
|
7
|
+
VideoCaptureOptions,
|
|
8
|
+
} from './room/track/options';
|
|
9
|
+
import type { AdaptiveStreamSettings } from './room/track/types';
|
|
10
|
+
|
|
11
|
+
export interface WebAudioSettings {
|
|
12
|
+
audioContext: AudioContext;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export interface InternalRoomOptions {
|
|
19
|
+
/**
|
|
20
|
+
* AdaptiveStream lets LiveKit automatically manage quality of subscribed
|
|
21
|
+
* video tracks to optimize for bandwidth and CPU.
|
|
22
|
+
* When attached video elements are visible, it'll choose an appropriate
|
|
23
|
+
* resolution based on the size of largest video element it's attached to.
|
|
24
|
+
*
|
|
25
|
+
* When none of the video elements are visible, it'll temporarily pause
|
|
26
|
+
* the data flow until they are visible again.
|
|
27
|
+
*/
|
|
28
|
+
adaptiveStream: AdaptiveStreamSettings | boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* enable Dynacast, off by default. With Dynacast dynamically pauses
|
|
32
|
+
* video layers that are not being consumed by any subscribers, significantly
|
|
33
|
+
* reducing publishing CPU and bandwidth usage.
|
|
34
|
+
*/
|
|
35
|
+
dynacast: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* default options to use when capturing user's audio
|
|
39
|
+
*/
|
|
40
|
+
audioCaptureDefaults?: AudioCaptureOptions;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* default options to use when capturing user's video
|
|
44
|
+
*/
|
|
45
|
+
videoCaptureDefaults?: VideoCaptureOptions;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* default options to use when publishing tracks
|
|
49
|
+
*/
|
|
50
|
+
publishDefaults?: TrackPublishDefaults;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* audio output for the room
|
|
54
|
+
*/
|
|
55
|
+
audioOutput?: AudioOutputOptions;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* should local tracks be stopped when they are unpublished. defaults to true
|
|
59
|
+
* set this to false if you would prefer to clean up unpublished local tracks manually.
|
|
60
|
+
*/
|
|
61
|
+
stopLocalTrackOnUnpublish: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* policy to use when attempting to reconnect
|
|
65
|
+
*/
|
|
66
|
+
reconnectPolicy: ReconnectPolicy;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* specifies whether the sdk should automatically disconnect the room
|
|
70
|
+
* on 'pagehide' and 'beforeunload' events
|
|
71
|
+
*/
|
|
72
|
+
disconnectOnPageLeave: boolean;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
* experimental flag, introduce a delay before sending signaling messages
|
|
77
|
+
*/
|
|
78
|
+
expSignalLatency?: number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
* @experimental
|
|
83
|
+
* experimental flag, mix all audio tracks in web audio
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
expWebAudioMix: boolean | WebAudioSettings;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @experimental
|
|
90
|
+
*/
|
|
91
|
+
e2ee?: E2EEOptions;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Options for when creating a new room
|
|
96
|
+
*/
|
|
97
|
+
export interface RoomOptions extends Partial<InternalRoomOptions> {}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
export interface InternalRoomConnectOptions {
|
|
103
|
+
/** autosubscribe to room tracks after joining, defaults to true */
|
|
104
|
+
autoSubscribe: boolean;
|
|
105
|
+
|
|
106
|
+
/** amount of time for PeerConnection to be established, defaults to 15s */
|
|
107
|
+
peerConnectionTimeout: number;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* use to override any RTCConfiguration options.
|
|
111
|
+
*/
|
|
112
|
+
rtcConfig?: RTCConfiguration;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated
|
|
116
|
+
* publish only mode
|
|
117
|
+
*/
|
|
118
|
+
publishOnly?: string;
|
|
119
|
+
|
|
120
|
+
/** specifies how often an initial join connection is allowed to retry (only applicable if server is not reachable) */
|
|
121
|
+
maxRetries: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Options for Room.connect()
|
|
126
|
+
*/
|
|
127
|
+
export interface RoomConnectOptions extends Partial<InternalRoomConnectOptions> {}
|