@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,1633 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
29
|
+
|
|
30
|
+
var loglevel = {exports: {}};
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* loglevel - https://github.com/pimterry/loglevel
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) 2013 Tim Perry
|
|
36
|
+
* Licensed under the MIT license.
|
|
37
|
+
*/
|
|
38
|
+
(function (module) {
|
|
39
|
+
(function (root, definition) {
|
|
40
|
+
|
|
41
|
+
if (module.exports) {
|
|
42
|
+
module.exports = definition();
|
|
43
|
+
} else {
|
|
44
|
+
root.log = definition();
|
|
45
|
+
}
|
|
46
|
+
})(commonjsGlobal, function () {
|
|
47
|
+
|
|
48
|
+
// Slightly dubious tricks to cut down minimized file size
|
|
49
|
+
var noop = function () {};
|
|
50
|
+
var undefinedType = "undefined";
|
|
51
|
+
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
52
|
+
var logMethods = ["trace", "debug", "info", "warn", "error"];
|
|
53
|
+
|
|
54
|
+
// Cross-browser bind equivalent that works at least back to IE6
|
|
55
|
+
function bindMethod(obj, methodName) {
|
|
56
|
+
var method = obj[methodName];
|
|
57
|
+
if (typeof method.bind === 'function') {
|
|
58
|
+
return method.bind(obj);
|
|
59
|
+
} else {
|
|
60
|
+
try {
|
|
61
|
+
return Function.prototype.bind.call(method, obj);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
// Missing bind shim or IE8 + Modernizr, fallback to wrapping
|
|
64
|
+
return function () {
|
|
65
|
+
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Trace() doesn't print the message in IE, so for that case we need to wrap it
|
|
72
|
+
function traceForIE() {
|
|
73
|
+
if (console.log) {
|
|
74
|
+
if (console.log.apply) {
|
|
75
|
+
console.log.apply(console, arguments);
|
|
76
|
+
} else {
|
|
77
|
+
// In old IE, native console methods themselves don't have apply().
|
|
78
|
+
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (console.trace) console.trace();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Build the best logging method possible for this env
|
|
85
|
+
// Wherever possible we want to bind, not wrap, to preserve stack traces
|
|
86
|
+
function realMethod(methodName) {
|
|
87
|
+
if (methodName === 'debug') {
|
|
88
|
+
methodName = 'log';
|
|
89
|
+
}
|
|
90
|
+
if (typeof console === undefinedType) {
|
|
91
|
+
return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
|
|
92
|
+
} else if (methodName === 'trace' && isIE) {
|
|
93
|
+
return traceForIE;
|
|
94
|
+
} else if (console[methodName] !== undefined) {
|
|
95
|
+
return bindMethod(console, methodName);
|
|
96
|
+
} else if (console.log !== undefined) {
|
|
97
|
+
return bindMethod(console, 'log');
|
|
98
|
+
} else {
|
|
99
|
+
return noop;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// These private functions always need `this` to be set properly
|
|
104
|
+
|
|
105
|
+
function replaceLoggingMethods(level, loggerName) {
|
|
106
|
+
/*jshint validthis:true */
|
|
107
|
+
for (var i = 0; i < logMethods.length; i++) {
|
|
108
|
+
var methodName = logMethods[i];
|
|
109
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Define log.log as an alias for log.debug
|
|
113
|
+
this.log = this.debug;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// In old IE versions, the console isn't present until you first open it.
|
|
117
|
+
// We build realMethod() replacements here that regenerate logging methods
|
|
118
|
+
function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
|
|
119
|
+
return function () {
|
|
120
|
+
if (typeof console !== undefinedType) {
|
|
121
|
+
replaceLoggingMethods.call(this, level, loggerName);
|
|
122
|
+
this[methodName].apply(this, arguments);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// By default, we use closely bound real methods wherever possible, and
|
|
128
|
+
// otherwise we wait for a console to appear, and then try again.
|
|
129
|
+
function defaultMethodFactory(methodName, level, loggerName) {
|
|
130
|
+
/*jshint validthis:true */
|
|
131
|
+
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
132
|
+
}
|
|
133
|
+
function Logger(name, defaultLevel, factory) {
|
|
134
|
+
var self = this;
|
|
135
|
+
var currentLevel;
|
|
136
|
+
defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
|
|
137
|
+
var storageKey = "loglevel";
|
|
138
|
+
if (typeof name === "string") {
|
|
139
|
+
storageKey += ":" + name;
|
|
140
|
+
} else if (typeof name === "symbol") {
|
|
141
|
+
storageKey = undefined;
|
|
142
|
+
}
|
|
143
|
+
function persistLevelIfPossible(levelNum) {
|
|
144
|
+
var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
|
|
145
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
146
|
+
|
|
147
|
+
// Use localStorage if available
|
|
148
|
+
try {
|
|
149
|
+
window.localStorage[storageKey] = levelName;
|
|
150
|
+
return;
|
|
151
|
+
} catch (ignore) {}
|
|
152
|
+
|
|
153
|
+
// Use session cookie as fallback
|
|
154
|
+
try {
|
|
155
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
156
|
+
} catch (ignore) {}
|
|
157
|
+
}
|
|
158
|
+
function getPersistedLevel() {
|
|
159
|
+
var storedLevel;
|
|
160
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
161
|
+
try {
|
|
162
|
+
storedLevel = window.localStorage[storageKey];
|
|
163
|
+
} catch (ignore) {}
|
|
164
|
+
|
|
165
|
+
// Fallback to cookies if local storage gives us nothing
|
|
166
|
+
if (typeof storedLevel === undefinedType) {
|
|
167
|
+
try {
|
|
168
|
+
var cookie = window.document.cookie;
|
|
169
|
+
var location = cookie.indexOf(encodeURIComponent(storageKey) + "=");
|
|
170
|
+
if (location !== -1) {
|
|
171
|
+
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
|
|
172
|
+
}
|
|
173
|
+
} catch (ignore) {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// If the stored level is not valid, treat it as if nothing was stored.
|
|
177
|
+
if (self.levels[storedLevel] === undefined) {
|
|
178
|
+
storedLevel = undefined;
|
|
179
|
+
}
|
|
180
|
+
return storedLevel;
|
|
181
|
+
}
|
|
182
|
+
function clearPersistedLevel() {
|
|
183
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
184
|
+
|
|
185
|
+
// Use localStorage if available
|
|
186
|
+
try {
|
|
187
|
+
window.localStorage.removeItem(storageKey);
|
|
188
|
+
return;
|
|
189
|
+
} catch (ignore) {}
|
|
190
|
+
|
|
191
|
+
// Use session cookie as fallback
|
|
192
|
+
try {
|
|
193
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
194
|
+
} catch (ignore) {}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
*
|
|
199
|
+
* Public logger API - see https://github.com/pimterry/loglevel for details
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
self.name = name;
|
|
204
|
+
self.levels = {
|
|
205
|
+
"TRACE": 0,
|
|
206
|
+
"DEBUG": 1,
|
|
207
|
+
"INFO": 2,
|
|
208
|
+
"WARN": 3,
|
|
209
|
+
"ERROR": 4,
|
|
210
|
+
"SILENT": 5
|
|
211
|
+
};
|
|
212
|
+
self.methodFactory = factory || defaultMethodFactory;
|
|
213
|
+
self.getLevel = function () {
|
|
214
|
+
return currentLevel;
|
|
215
|
+
};
|
|
216
|
+
self.setLevel = function (level, persist) {
|
|
217
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
|
|
218
|
+
level = self.levels[level.toUpperCase()];
|
|
219
|
+
}
|
|
220
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
221
|
+
currentLevel = level;
|
|
222
|
+
if (persist !== false) {
|
|
223
|
+
// defaults to true
|
|
224
|
+
persistLevelIfPossible(level);
|
|
225
|
+
}
|
|
226
|
+
replaceLoggingMethods.call(self, level, name);
|
|
227
|
+
if (typeof console === undefinedType && level < self.levels.SILENT) {
|
|
228
|
+
return "No console available for logging";
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
throw "log.setLevel() called with invalid level: " + level;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
self.setDefaultLevel = function (level) {
|
|
235
|
+
defaultLevel = level;
|
|
236
|
+
if (!getPersistedLevel()) {
|
|
237
|
+
self.setLevel(level, false);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
self.resetLevel = function () {
|
|
241
|
+
self.setLevel(defaultLevel, false);
|
|
242
|
+
clearPersistedLevel();
|
|
243
|
+
};
|
|
244
|
+
self.enableAll = function (persist) {
|
|
245
|
+
self.setLevel(self.levels.TRACE, persist);
|
|
246
|
+
};
|
|
247
|
+
self.disableAll = function (persist) {
|
|
248
|
+
self.setLevel(self.levels.SILENT, persist);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Initialize with the right level
|
|
252
|
+
var initialLevel = getPersistedLevel();
|
|
253
|
+
if (initialLevel == null) {
|
|
254
|
+
initialLevel = defaultLevel;
|
|
255
|
+
}
|
|
256
|
+
self.setLevel(initialLevel, false);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
*
|
|
261
|
+
* Top-level API
|
|
262
|
+
*
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
var defaultLogger = new Logger();
|
|
266
|
+
var _loggersByName = {};
|
|
267
|
+
defaultLogger.getLogger = function getLogger(name) {
|
|
268
|
+
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
269
|
+
throw new TypeError("You must supply a name when creating a logger.");
|
|
270
|
+
}
|
|
271
|
+
var logger = _loggersByName[name];
|
|
272
|
+
if (!logger) {
|
|
273
|
+
logger = _loggersByName[name] = new Logger(name, defaultLogger.getLevel(), defaultLogger.methodFactory);
|
|
274
|
+
}
|
|
275
|
+
return logger;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// Grab the current global log variable in case of overwrite
|
|
279
|
+
var _log = typeof window !== undefinedType ? window.log : undefined;
|
|
280
|
+
defaultLogger.noConflict = function () {
|
|
281
|
+
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
282
|
+
window.log = _log;
|
|
283
|
+
}
|
|
284
|
+
return defaultLogger;
|
|
285
|
+
};
|
|
286
|
+
defaultLogger.getLoggers = function getLoggers() {
|
|
287
|
+
return _loggersByName;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// ES6 default export, for compatibility
|
|
291
|
+
defaultLogger['default'] = defaultLogger;
|
|
292
|
+
return defaultLogger;
|
|
293
|
+
});
|
|
294
|
+
})(loglevel);
|
|
295
|
+
var loglevelExports = loglevel.exports;
|
|
296
|
+
|
|
297
|
+
var LogLevel;
|
|
298
|
+
(function (LogLevel) {
|
|
299
|
+
LogLevel[LogLevel["trace"] = 0] = "trace";
|
|
300
|
+
LogLevel[LogLevel["debug"] = 1] = "debug";
|
|
301
|
+
LogLevel[LogLevel["info"] = 2] = "info";
|
|
302
|
+
LogLevel[LogLevel["warn"] = 3] = "warn";
|
|
303
|
+
LogLevel[LogLevel["error"] = 4] = "error";
|
|
304
|
+
LogLevel[LogLevel["silent"] = 5] = "silent";
|
|
305
|
+
})(LogLevel || (LogLevel = {}));
|
|
306
|
+
const livekitLogger = loglevelExports.getLogger('livekit');
|
|
307
|
+
livekitLogger.setDefaultLevel(LogLevel.info);
|
|
308
|
+
|
|
309
|
+
const workerLogger = loglevelExports.getLogger('lk-e2ee');
|
|
310
|
+
|
|
311
|
+
const ENCRYPTION_ALGORITHM = 'AES-GCM';
|
|
312
|
+
// We use a ringbuffer of keys so we can change them and still decode packets that were
|
|
313
|
+
// encrypted with an old key. We use a size of 16 which corresponds to the four bits
|
|
314
|
+
// in the frame trailer.
|
|
315
|
+
const KEYRING_SIZE = 16;
|
|
316
|
+
// How many consecutive frames can fail decrypting before a particular key gets marked as invalid
|
|
317
|
+
const DECRYPTION_FAILURE_TOLERANCE = 10;
|
|
318
|
+
// We copy the first bytes of the VP8 payload unencrypted.
|
|
319
|
+
// For keyframes this is 10 bytes, for non-keyframes (delta) 3. See
|
|
320
|
+
// https://tools.ietf.org/html/rfc6386#section-9.1
|
|
321
|
+
// This allows the bridge to continue detecting keyframes (only one byte needed in the JVB)
|
|
322
|
+
// and is also a bit easier for the VP8 decoder (i.e. it generates funny garbage pictures
|
|
323
|
+
// instead of being unable to decode).
|
|
324
|
+
// This is a bit for show and we might want to reduce to 1 unconditionally in the final version.
|
|
325
|
+
//
|
|
326
|
+
// For audio (where frame.type is not set) we do not encrypt the opus TOC byte:
|
|
327
|
+
// https://tools.ietf.org/html/rfc6716#section-3.1
|
|
328
|
+
const UNENCRYPTED_BYTES = {
|
|
329
|
+
key: 10,
|
|
330
|
+
delta: 3,
|
|
331
|
+
audio: 1,
|
|
332
|
+
empty: 0
|
|
333
|
+
};
|
|
334
|
+
/* We use a 12 byte bit IV. This is signalled in plain together with the
|
|
335
|
+
packet. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#parameters */
|
|
336
|
+
const IV_LENGTH = 12;
|
|
337
|
+
const SALT = 'LKFrameEncryptionKey';
|
|
338
|
+
const KEY_PROVIDER_DEFAULTS = {
|
|
339
|
+
sharedKey: false,
|
|
340
|
+
ratchetSalt: SALT,
|
|
341
|
+
ratchetWindowSize: 8,
|
|
342
|
+
failureTolerance: DECRYPTION_FAILURE_TOLERANCE
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
class LivekitError extends Error {
|
|
346
|
+
constructor(code, message) {
|
|
347
|
+
super(message || 'an error has occured');
|
|
348
|
+
this.code = code;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
var MediaDeviceFailure;
|
|
352
|
+
(function (MediaDeviceFailure) {
|
|
353
|
+
// user rejected permissions
|
|
354
|
+
MediaDeviceFailure["PermissionDenied"] = "PermissionDenied";
|
|
355
|
+
// device is not available
|
|
356
|
+
MediaDeviceFailure["NotFound"] = "NotFound";
|
|
357
|
+
// device is in use. On Windows, only a single tab may get access to a device at a time.
|
|
358
|
+
MediaDeviceFailure["DeviceInUse"] = "DeviceInUse";
|
|
359
|
+
MediaDeviceFailure["Other"] = "Other";
|
|
360
|
+
})(MediaDeviceFailure || (MediaDeviceFailure = {}));
|
|
361
|
+
(function (MediaDeviceFailure) {
|
|
362
|
+
function getFailure(error) {
|
|
363
|
+
if (error && 'name' in error) {
|
|
364
|
+
if (error.name === 'NotFoundError' || error.name === 'DevicesNotFoundError') {
|
|
365
|
+
return MediaDeviceFailure.NotFound;
|
|
366
|
+
}
|
|
367
|
+
if (error.name === 'NotAllowedError' || error.name === 'PermissionDeniedError') {
|
|
368
|
+
return MediaDeviceFailure.PermissionDenied;
|
|
369
|
+
}
|
|
370
|
+
if (error.name === 'NotReadableError' || error.name === 'TrackStartError') {
|
|
371
|
+
return MediaDeviceFailure.DeviceInUse;
|
|
372
|
+
}
|
|
373
|
+
return MediaDeviceFailure.Other;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
MediaDeviceFailure.getFailure = getFailure;
|
|
377
|
+
})(MediaDeviceFailure || (MediaDeviceFailure = {}));
|
|
378
|
+
|
|
379
|
+
var CryptorErrorReason;
|
|
380
|
+
(function (CryptorErrorReason) {
|
|
381
|
+
CryptorErrorReason[CryptorErrorReason["InvalidKey"] = 0] = "InvalidKey";
|
|
382
|
+
CryptorErrorReason[CryptorErrorReason["MissingKey"] = 1] = "MissingKey";
|
|
383
|
+
CryptorErrorReason[CryptorErrorReason["InternalError"] = 2] = "InternalError";
|
|
384
|
+
})(CryptorErrorReason || (CryptorErrorReason = {}));
|
|
385
|
+
class CryptorError extends LivekitError {
|
|
386
|
+
constructor(message) {
|
|
387
|
+
let reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CryptorErrorReason.InternalError;
|
|
388
|
+
super(40, message);
|
|
389
|
+
this.reason = reason;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
var events = {exports: {}};
|
|
394
|
+
|
|
395
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
396
|
+
var ReflectApply = R && typeof R.apply === 'function' ? R.apply : function ReflectApply(target, receiver, args) {
|
|
397
|
+
return Function.prototype.apply.call(target, receiver, args);
|
|
398
|
+
};
|
|
399
|
+
var ReflectOwnKeys;
|
|
400
|
+
if (R && typeof R.ownKeys === 'function') {
|
|
401
|
+
ReflectOwnKeys = R.ownKeys;
|
|
402
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
403
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
404
|
+
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
|
|
405
|
+
};
|
|
406
|
+
} else {
|
|
407
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
408
|
+
return Object.getOwnPropertyNames(target);
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function ProcessEmitWarning(warning) {
|
|
412
|
+
if (console && console.warn) console.warn(warning);
|
|
413
|
+
}
|
|
414
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
|
415
|
+
return value !== value;
|
|
416
|
+
};
|
|
417
|
+
function EventEmitter() {
|
|
418
|
+
EventEmitter.init.call(this);
|
|
419
|
+
}
|
|
420
|
+
events.exports = EventEmitter;
|
|
421
|
+
events.exports.once = once;
|
|
422
|
+
|
|
423
|
+
// Backwards-compat with node 0.10.x
|
|
424
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
425
|
+
EventEmitter.prototype._events = undefined;
|
|
426
|
+
EventEmitter.prototype._eventsCount = 0;
|
|
427
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
428
|
+
|
|
429
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
430
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
431
|
+
var defaultMaxListeners = 10;
|
|
432
|
+
function checkListener(listener) {
|
|
433
|
+
if (typeof listener !== 'function') {
|
|
434
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
|
438
|
+
enumerable: true,
|
|
439
|
+
get: function () {
|
|
440
|
+
return defaultMaxListeners;
|
|
441
|
+
},
|
|
442
|
+
set: function (arg) {
|
|
443
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
444
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
445
|
+
}
|
|
446
|
+
defaultMaxListeners = arg;
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
EventEmitter.init = function () {
|
|
450
|
+
if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
|
|
451
|
+
this._events = Object.create(null);
|
|
452
|
+
this._eventsCount = 0;
|
|
453
|
+
}
|
|
454
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
458
|
+
// that to be increased. Set to zero for unlimited.
|
|
459
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
460
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
461
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
462
|
+
}
|
|
463
|
+
this._maxListeners = n;
|
|
464
|
+
return this;
|
|
465
|
+
};
|
|
466
|
+
function _getMaxListeners(that) {
|
|
467
|
+
if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
|
|
468
|
+
return that._maxListeners;
|
|
469
|
+
}
|
|
470
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
471
|
+
return _getMaxListeners(this);
|
|
472
|
+
};
|
|
473
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
474
|
+
var args = [];
|
|
475
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
476
|
+
var doError = type === 'error';
|
|
477
|
+
var events = this._events;
|
|
478
|
+
if (events !== undefined) doError = doError && events.error === undefined;else if (!doError) return false;
|
|
479
|
+
|
|
480
|
+
// If there is no 'error' event listener then throw.
|
|
481
|
+
if (doError) {
|
|
482
|
+
var er;
|
|
483
|
+
if (args.length > 0) er = args[0];
|
|
484
|
+
if (er instanceof Error) {
|
|
485
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
486
|
+
// up in Node's output if this results in an unhandled exception.
|
|
487
|
+
throw er; // Unhandled 'error' event
|
|
488
|
+
}
|
|
489
|
+
// At least give some kind of context to the user
|
|
490
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
491
|
+
err.context = er;
|
|
492
|
+
throw err; // Unhandled 'error' event
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
var handler = events[type];
|
|
496
|
+
if (handler === undefined) return false;
|
|
497
|
+
if (typeof handler === 'function') {
|
|
498
|
+
ReflectApply(handler, this, args);
|
|
499
|
+
} else {
|
|
500
|
+
var len = handler.length;
|
|
501
|
+
var listeners = arrayClone(handler, len);
|
|
502
|
+
for (var i = 0; i < len; ++i) ReflectApply(listeners[i], this, args);
|
|
503
|
+
}
|
|
504
|
+
return true;
|
|
505
|
+
};
|
|
506
|
+
function _addListener(target, type, listener, prepend) {
|
|
507
|
+
var m;
|
|
508
|
+
var events;
|
|
509
|
+
var existing;
|
|
510
|
+
checkListener(listener);
|
|
511
|
+
events = target._events;
|
|
512
|
+
if (events === undefined) {
|
|
513
|
+
events = target._events = Object.create(null);
|
|
514
|
+
target._eventsCount = 0;
|
|
515
|
+
} else {
|
|
516
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
517
|
+
// adding it to the listeners, first emit "newListener".
|
|
518
|
+
if (events.newListener !== undefined) {
|
|
519
|
+
target.emit('newListener', type, listener.listener ? listener.listener : listener);
|
|
520
|
+
|
|
521
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
522
|
+
// this._events to be assigned to a new object
|
|
523
|
+
events = target._events;
|
|
524
|
+
}
|
|
525
|
+
existing = events[type];
|
|
526
|
+
}
|
|
527
|
+
if (existing === undefined) {
|
|
528
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
529
|
+
existing = events[type] = listener;
|
|
530
|
+
++target._eventsCount;
|
|
531
|
+
} else {
|
|
532
|
+
if (typeof existing === 'function') {
|
|
533
|
+
// Adding the second element, need to change to array.
|
|
534
|
+
existing = events[type] = prepend ? [listener, existing] : [existing, listener];
|
|
535
|
+
// If we've already got an array, just append.
|
|
536
|
+
} else if (prepend) {
|
|
537
|
+
existing.unshift(listener);
|
|
538
|
+
} else {
|
|
539
|
+
existing.push(listener);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// Check for listener leak
|
|
543
|
+
m = _getMaxListeners(target);
|
|
544
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
545
|
+
existing.warned = true;
|
|
546
|
+
// No error code for this since it is a Warning
|
|
547
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
548
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' ' + String(type) + ' listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit');
|
|
549
|
+
w.name = 'MaxListenersExceededWarning';
|
|
550
|
+
w.emitter = target;
|
|
551
|
+
w.type = type;
|
|
552
|
+
w.count = existing.length;
|
|
553
|
+
ProcessEmitWarning(w);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return target;
|
|
557
|
+
}
|
|
558
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
559
|
+
return _addListener(this, type, listener, false);
|
|
560
|
+
};
|
|
561
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
562
|
+
EventEmitter.prototype.prependListener = function prependListener(type, listener) {
|
|
563
|
+
return _addListener(this, type, listener, true);
|
|
564
|
+
};
|
|
565
|
+
function onceWrapper() {
|
|
566
|
+
if (!this.fired) {
|
|
567
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
568
|
+
this.fired = true;
|
|
569
|
+
if (arguments.length === 0) return this.listener.call(this.target);
|
|
570
|
+
return this.listener.apply(this.target, arguments);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function _onceWrap(target, type, listener) {
|
|
574
|
+
var state = {
|
|
575
|
+
fired: false,
|
|
576
|
+
wrapFn: undefined,
|
|
577
|
+
target: target,
|
|
578
|
+
type: type,
|
|
579
|
+
listener: listener
|
|
580
|
+
};
|
|
581
|
+
var wrapped = onceWrapper.bind(state);
|
|
582
|
+
wrapped.listener = listener;
|
|
583
|
+
state.wrapFn = wrapped;
|
|
584
|
+
return wrapped;
|
|
585
|
+
}
|
|
586
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
587
|
+
checkListener(listener);
|
|
588
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
589
|
+
return this;
|
|
590
|
+
};
|
|
591
|
+
EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
|
|
592
|
+
checkListener(listener);
|
|
593
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
594
|
+
return this;
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
|
598
|
+
EventEmitter.prototype.removeListener = function removeListener(type, listener) {
|
|
599
|
+
var list, events, position, i, originalListener;
|
|
600
|
+
checkListener(listener);
|
|
601
|
+
events = this._events;
|
|
602
|
+
if (events === undefined) return this;
|
|
603
|
+
list = events[type];
|
|
604
|
+
if (list === undefined) return this;
|
|
605
|
+
if (list === listener || list.listener === listener) {
|
|
606
|
+
if (--this._eventsCount === 0) this._events = Object.create(null);else {
|
|
607
|
+
delete events[type];
|
|
608
|
+
if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
|
|
609
|
+
}
|
|
610
|
+
} else if (typeof list !== 'function') {
|
|
611
|
+
position = -1;
|
|
612
|
+
for (i = list.length - 1; i >= 0; i--) {
|
|
613
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
614
|
+
originalListener = list[i].listener;
|
|
615
|
+
position = i;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (position < 0) return this;
|
|
620
|
+
if (position === 0) list.shift();else {
|
|
621
|
+
spliceOne(list, position);
|
|
622
|
+
}
|
|
623
|
+
if (list.length === 1) events[type] = list[0];
|
|
624
|
+
if (events.removeListener !== undefined) this.emit('removeListener', type, originalListener || listener);
|
|
625
|
+
}
|
|
626
|
+
return this;
|
|
627
|
+
};
|
|
628
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
629
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
|
|
630
|
+
var listeners, events, i;
|
|
631
|
+
events = this._events;
|
|
632
|
+
if (events === undefined) return this;
|
|
633
|
+
|
|
634
|
+
// not listening for removeListener, no need to emit
|
|
635
|
+
if (events.removeListener === undefined) {
|
|
636
|
+
if (arguments.length === 0) {
|
|
637
|
+
this._events = Object.create(null);
|
|
638
|
+
this._eventsCount = 0;
|
|
639
|
+
} else if (events[type] !== undefined) {
|
|
640
|
+
if (--this._eventsCount === 0) this._events = Object.create(null);else delete events[type];
|
|
641
|
+
}
|
|
642
|
+
return this;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// emit removeListener for all listeners on all events
|
|
646
|
+
if (arguments.length === 0) {
|
|
647
|
+
var keys = Object.keys(events);
|
|
648
|
+
var key;
|
|
649
|
+
for (i = 0; i < keys.length; ++i) {
|
|
650
|
+
key = keys[i];
|
|
651
|
+
if (key === 'removeListener') continue;
|
|
652
|
+
this.removeAllListeners(key);
|
|
653
|
+
}
|
|
654
|
+
this.removeAllListeners('removeListener');
|
|
655
|
+
this._events = Object.create(null);
|
|
656
|
+
this._eventsCount = 0;
|
|
657
|
+
return this;
|
|
658
|
+
}
|
|
659
|
+
listeners = events[type];
|
|
660
|
+
if (typeof listeners === 'function') {
|
|
661
|
+
this.removeListener(type, listeners);
|
|
662
|
+
} else if (listeners !== undefined) {
|
|
663
|
+
// LIFO order
|
|
664
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
|
665
|
+
this.removeListener(type, listeners[i]);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return this;
|
|
669
|
+
};
|
|
670
|
+
function _listeners(target, type, unwrap) {
|
|
671
|
+
var events = target._events;
|
|
672
|
+
if (events === undefined) return [];
|
|
673
|
+
var evlistener = events[type];
|
|
674
|
+
if (evlistener === undefined) return [];
|
|
675
|
+
if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
676
|
+
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
677
|
+
}
|
|
678
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
679
|
+
return _listeners(this, type, true);
|
|
680
|
+
};
|
|
681
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
682
|
+
return _listeners(this, type, false);
|
|
683
|
+
};
|
|
684
|
+
EventEmitter.listenerCount = function (emitter, type) {
|
|
685
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
686
|
+
return emitter.listenerCount(type);
|
|
687
|
+
} else {
|
|
688
|
+
return listenerCount.call(emitter, type);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
692
|
+
function listenerCount(type) {
|
|
693
|
+
var events = this._events;
|
|
694
|
+
if (events !== undefined) {
|
|
695
|
+
var evlistener = events[type];
|
|
696
|
+
if (typeof evlistener === 'function') {
|
|
697
|
+
return 1;
|
|
698
|
+
} else if (evlistener !== undefined) {
|
|
699
|
+
return evlistener.length;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return 0;
|
|
703
|
+
}
|
|
704
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
705
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
706
|
+
};
|
|
707
|
+
function arrayClone(arr, n) {
|
|
708
|
+
var copy = new Array(n);
|
|
709
|
+
for (var i = 0; i < n; ++i) copy[i] = arr[i];
|
|
710
|
+
return copy;
|
|
711
|
+
}
|
|
712
|
+
function spliceOne(list, index) {
|
|
713
|
+
for (; index + 1 < list.length; index++) list[index] = list[index + 1];
|
|
714
|
+
list.pop();
|
|
715
|
+
}
|
|
716
|
+
function unwrapListeners(arr) {
|
|
717
|
+
var ret = new Array(arr.length);
|
|
718
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
719
|
+
ret[i] = arr[i].listener || arr[i];
|
|
720
|
+
}
|
|
721
|
+
return ret;
|
|
722
|
+
}
|
|
723
|
+
function once(emitter, name) {
|
|
724
|
+
return new Promise(function (resolve, reject) {
|
|
725
|
+
function errorListener(err) {
|
|
726
|
+
emitter.removeListener(name, resolver);
|
|
727
|
+
reject(err);
|
|
728
|
+
}
|
|
729
|
+
function resolver() {
|
|
730
|
+
if (typeof emitter.removeListener === 'function') {
|
|
731
|
+
emitter.removeListener('error', errorListener);
|
|
732
|
+
}
|
|
733
|
+
resolve([].slice.call(arguments));
|
|
734
|
+
}
|
|
735
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, {
|
|
736
|
+
once: true
|
|
737
|
+
});
|
|
738
|
+
if (name !== 'error') {
|
|
739
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, {
|
|
740
|
+
once: true
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
746
|
+
if (typeof emitter.on === 'function') {
|
|
747
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
751
|
+
if (typeof emitter.on === 'function') {
|
|
752
|
+
if (flags.once) {
|
|
753
|
+
emitter.once(name, listener);
|
|
754
|
+
} else {
|
|
755
|
+
emitter.on(name, listener);
|
|
756
|
+
}
|
|
757
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
758
|
+
// EventTarget does not have `error` event semantics like Node
|
|
759
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
760
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
761
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
762
|
+
// have to do it manually.
|
|
763
|
+
if (flags.once) {
|
|
764
|
+
emitter.removeEventListener(name, wrapListener);
|
|
765
|
+
}
|
|
766
|
+
listener(arg);
|
|
767
|
+
});
|
|
768
|
+
} else {
|
|
769
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
var eventsExports = events.exports;
|
|
773
|
+
|
|
774
|
+
const CryptorEvent = {
|
|
775
|
+
Error: 'cryptorError'
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
var AudioPresets;
|
|
779
|
+
(function (AudioPresets) {
|
|
780
|
+
AudioPresets.telephone = {
|
|
781
|
+
maxBitrate: 12000
|
|
782
|
+
};
|
|
783
|
+
AudioPresets.speech = {
|
|
784
|
+
maxBitrate: 20000
|
|
785
|
+
};
|
|
786
|
+
AudioPresets.music = {
|
|
787
|
+
maxBitrate: 32000
|
|
788
|
+
};
|
|
789
|
+
AudioPresets.musicStereo = {
|
|
790
|
+
maxBitrate: 48000
|
|
791
|
+
};
|
|
792
|
+
AudioPresets.musicHighQuality = {
|
|
793
|
+
maxBitrate: 64000
|
|
794
|
+
};
|
|
795
|
+
AudioPresets.musicHighQualityStereo = {
|
|
796
|
+
maxBitrate: 96000
|
|
797
|
+
};
|
|
798
|
+
})(AudioPresets || (AudioPresets = {}));
|
|
799
|
+
|
|
800
|
+
function isVideoFrame(frame) {
|
|
801
|
+
return 'type' in frame;
|
|
802
|
+
}
|
|
803
|
+
function importKey(keyBytes) {
|
|
804
|
+
let algorithm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
805
|
+
name: ENCRYPTION_ALGORITHM
|
|
806
|
+
};
|
|
807
|
+
let usage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'encrypt';
|
|
808
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
809
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
|
|
810
|
+
return crypto.subtle.importKey('raw', keyBytes, algorithm, false, usage === 'derive' ? ['deriveBits', 'deriveKey'] : ['encrypt', 'decrypt']);
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
function getAlgoOptions(algorithmName, salt) {
|
|
814
|
+
const textEncoder = new TextEncoder();
|
|
815
|
+
const encodedSalt = textEncoder.encode(salt);
|
|
816
|
+
switch (algorithmName) {
|
|
817
|
+
case 'HKDF':
|
|
818
|
+
return {
|
|
819
|
+
name: 'HKDF',
|
|
820
|
+
salt: encodedSalt,
|
|
821
|
+
hash: 'SHA-256',
|
|
822
|
+
info: new ArrayBuffer(128)
|
|
823
|
+
};
|
|
824
|
+
case 'PBKDF2':
|
|
825
|
+
{
|
|
826
|
+
return {
|
|
827
|
+
name: 'PBKDF2',
|
|
828
|
+
salt: encodedSalt,
|
|
829
|
+
hash: 'SHA-256',
|
|
830
|
+
iterations: 100000
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
default:
|
|
834
|
+
throw new Error("algorithm ".concat(algorithmName, " is currently unsupported"));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Derives a set of keys from the master key.
|
|
839
|
+
* See https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.1
|
|
840
|
+
*/
|
|
841
|
+
function deriveKeys(material, salt) {
|
|
842
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
843
|
+
const algorithmOptions = getAlgoOptions(material.algorithm.name, salt);
|
|
844
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey#HKDF
|
|
845
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HkdfParams
|
|
846
|
+
const encryptionKey = yield crypto.subtle.deriveKey(algorithmOptions, material, {
|
|
847
|
+
name: ENCRYPTION_ALGORITHM,
|
|
848
|
+
length: 128
|
|
849
|
+
}, false, ['encrypt', 'decrypt']);
|
|
850
|
+
return {
|
|
851
|
+
material,
|
|
852
|
+
encryptionKey
|
|
853
|
+
};
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Ratchets a key. See
|
|
858
|
+
* https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.5.1
|
|
859
|
+
*/
|
|
860
|
+
function ratchet(material, salt) {
|
|
861
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
862
|
+
const algorithmOptions = getAlgoOptions(material.algorithm.name, salt);
|
|
863
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveBits
|
|
864
|
+
return crypto.subtle.deriveBits(algorithmOptions, material, 256);
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
class BaseFrameCryptor extends eventsExports.EventEmitter {
|
|
869
|
+
encodeFunction(encodedFrame, controller) {
|
|
870
|
+
throw Error('not implemented for subclass');
|
|
871
|
+
}
|
|
872
|
+
decodeFunction(encodedFrame, controller) {
|
|
873
|
+
throw Error('not implemented for subclass');
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Cryptor is responsible for en-/decrypting media frames.
|
|
878
|
+
* Each Cryptor instance is responsible for en-/decrypting a single mediaStreamTrack.
|
|
879
|
+
*/
|
|
880
|
+
class FrameCryptor extends BaseFrameCryptor {
|
|
881
|
+
constructor(opts) {
|
|
882
|
+
var _a;
|
|
883
|
+
super();
|
|
884
|
+
this.sendCounts = new Map();
|
|
885
|
+
this.keys = opts.keys;
|
|
886
|
+
this.participantId = opts.participantId;
|
|
887
|
+
this.rtpMap = new Map();
|
|
888
|
+
this.keyProviderOptions = opts.keyProviderOptions;
|
|
889
|
+
this.unencryptedFrameByteTrailer = (_a = opts.unencryptedFrameBytes) !== null && _a !== void 0 ? _a : new TextEncoder().encode('LKROCKS');
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Assign a different participant to the cryptor.
|
|
893
|
+
* useful for transceiver re-use
|
|
894
|
+
* @param id
|
|
895
|
+
* @param keys
|
|
896
|
+
*/
|
|
897
|
+
setParticipant(id, keys) {
|
|
898
|
+
this.participantId = id;
|
|
899
|
+
this.keys = keys;
|
|
900
|
+
}
|
|
901
|
+
unsetParticipant() {
|
|
902
|
+
this.participantId = undefined;
|
|
903
|
+
}
|
|
904
|
+
getParticipantId() {
|
|
905
|
+
return this.participantId;
|
|
906
|
+
}
|
|
907
|
+
getTrackId() {
|
|
908
|
+
return this.trackId;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Update the video codec used by the mediaStreamTrack
|
|
912
|
+
* @param codec
|
|
913
|
+
*/
|
|
914
|
+
setVideoCodec(codec) {
|
|
915
|
+
this.videoCodec = codec;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* rtp payload type map used for figuring out codec of payload type when encoding
|
|
919
|
+
* @param map
|
|
920
|
+
*/
|
|
921
|
+
setRtpMap(map) {
|
|
922
|
+
this.rtpMap = map;
|
|
923
|
+
}
|
|
924
|
+
setupTransform(operation, readable, writable, trackId, codec) {
|
|
925
|
+
if (codec) {
|
|
926
|
+
console.info('setting codec on cryptor to', codec);
|
|
927
|
+
this.videoCodec = codec;
|
|
928
|
+
}
|
|
929
|
+
const transformFn = operation === 'encode' ? this.encodeFunction : this.decodeFunction;
|
|
930
|
+
const transformStream = new TransformStream({
|
|
931
|
+
transform: transformFn.bind(this)
|
|
932
|
+
});
|
|
933
|
+
readable.pipeThrough(transformStream).pipeTo(writable).catch(e => {
|
|
934
|
+
console.error(e);
|
|
935
|
+
this.emit('cryptorError', e instanceof CryptorError ? e : new CryptorError(e.message));
|
|
936
|
+
});
|
|
937
|
+
this.trackId = trackId;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Function that will be injected in a stream and will encrypt the given encoded frames.
|
|
941
|
+
*
|
|
942
|
+
* @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame.
|
|
943
|
+
* @param {TransformStreamDefaultController} controller - TransportStreamController.
|
|
944
|
+
*
|
|
945
|
+
* The VP8 payload descriptor described in
|
|
946
|
+
* https://tools.ietf.org/html/rfc7741#section-4.2
|
|
947
|
+
* is part of the RTP packet and not part of the frame and is not controllable by us.
|
|
948
|
+
* This is fine as the SFU keeps having access to it for routing.
|
|
949
|
+
*
|
|
950
|
+
* The encrypted frame is formed as follows:
|
|
951
|
+
* 1) Find unencrypted byte length, depending on the codec, frame type and kind.
|
|
952
|
+
* 2) Form the GCM IV for the frame as described above.
|
|
953
|
+
* 3) Encrypt the rest of the frame using AES-GCM.
|
|
954
|
+
* 4) Allocate space for the encrypted frame.
|
|
955
|
+
* 5) Copy the unencrypted bytes to the start of the encrypted frame.
|
|
956
|
+
* 6) Append the ciphertext to the encrypted frame.
|
|
957
|
+
* 7) Append the IV.
|
|
958
|
+
* 8) Append a single byte for the key identifier.
|
|
959
|
+
* 9) Enqueue the encrypted frame for sending.
|
|
960
|
+
*/
|
|
961
|
+
encodeFunction(encodedFrame, controller) {
|
|
962
|
+
var _a;
|
|
963
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
964
|
+
if (!this.keys.isEnabled() ||
|
|
965
|
+
// skip for encryption for empty dtx frames
|
|
966
|
+
encodedFrame.data.byteLength === 0) {
|
|
967
|
+
return controller.enqueue(encodedFrame);
|
|
968
|
+
}
|
|
969
|
+
const {
|
|
970
|
+
encryptionKey
|
|
971
|
+
} = this.keys.getKeySet();
|
|
972
|
+
const keyIndex = this.keys.getCurrentKeyIndex();
|
|
973
|
+
if (encryptionKey) {
|
|
974
|
+
const iv = this.makeIV((_a = encodedFrame.getMetadata().synchronizationSource) !== null && _a !== void 0 ? _a : -1, encodedFrame.timestamp);
|
|
975
|
+
// Thіs is not encrypted and contains the VP8 payload descriptor or the Opus TOC byte.
|
|
976
|
+
const frameHeader = new Uint8Array(encodedFrame.data, 0, this.getUnencryptedBytes(encodedFrame));
|
|
977
|
+
// Frame trailer contains the R|IV_LENGTH and key index
|
|
978
|
+
const frameTrailer = new Uint8Array(2);
|
|
979
|
+
frameTrailer[0] = IV_LENGTH;
|
|
980
|
+
frameTrailer[1] = keyIndex;
|
|
981
|
+
// Construct frame trailer. Similar to the frame header described in
|
|
982
|
+
// https://tools.ietf.org/html/draft-omara-sframe-00#section-4.2
|
|
983
|
+
// but we put it at the end.
|
|
984
|
+
//
|
|
985
|
+
// ---------+-------------------------+-+---------+----
|
|
986
|
+
// payload |IV...(length = IV_LENGTH)|R|IV_LENGTH|KID |
|
|
987
|
+
// ---------+-------------------------+-+---------+----
|
|
988
|
+
try {
|
|
989
|
+
const cipherText = yield crypto.subtle.encrypt({
|
|
990
|
+
name: ENCRYPTION_ALGORITHM,
|
|
991
|
+
iv,
|
|
992
|
+
additionalData: new Uint8Array(encodedFrame.data, 0, frameHeader.byteLength)
|
|
993
|
+
}, encryptionKey, new Uint8Array(encodedFrame.data, this.getUnencryptedBytes(encodedFrame)));
|
|
994
|
+
const newData = new ArrayBuffer(frameHeader.byteLength + cipherText.byteLength + iv.byteLength + frameTrailer.byteLength);
|
|
995
|
+
const newUint8 = new Uint8Array(newData);
|
|
996
|
+
newUint8.set(frameHeader); // copy first bytes.
|
|
997
|
+
newUint8.set(new Uint8Array(cipherText), frameHeader.byteLength); // add ciphertext.
|
|
998
|
+
newUint8.set(new Uint8Array(iv), frameHeader.byteLength + cipherText.byteLength); // append IV.
|
|
999
|
+
newUint8.set(frameTrailer, frameHeader.byteLength + cipherText.byteLength + iv.byteLength); // append frame trailer.
|
|
1000
|
+
encodedFrame.data = newData;
|
|
1001
|
+
return controller.enqueue(encodedFrame);
|
|
1002
|
+
} catch (e) {
|
|
1003
|
+
// TODO: surface this to the app.
|
|
1004
|
+
workerLogger.error(e);
|
|
1005
|
+
}
|
|
1006
|
+
} else {
|
|
1007
|
+
this.emit(CryptorEvent.Error, new CryptorError("encryption key missing for encoding", CryptorErrorReason.MissingKey));
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Function that will be injected in a stream and will decrypt the given encoded frames.
|
|
1013
|
+
*
|
|
1014
|
+
* @param {RTCEncodedVideoFrame|RTCEncodedAudioFrame} encodedFrame - Encoded video frame.
|
|
1015
|
+
* @param {TransformStreamDefaultController} controller - TransportStreamController.
|
|
1016
|
+
*/
|
|
1017
|
+
decodeFunction(encodedFrame, controller) {
|
|
1018
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1019
|
+
if (!this.keys.isEnabled() ||
|
|
1020
|
+
// skip for decryption for empty dtx frames
|
|
1021
|
+
encodedFrame.data.byteLength === 0 ||
|
|
1022
|
+
// skip decryption if frame is server injected
|
|
1023
|
+
isFrameServerInjected(encodedFrame.data, this.unencryptedFrameByteTrailer)) {
|
|
1024
|
+
return controller.enqueue(encodedFrame);
|
|
1025
|
+
}
|
|
1026
|
+
const data = new Uint8Array(encodedFrame.data);
|
|
1027
|
+
const keyIndex = data[encodedFrame.data.byteLength - 1];
|
|
1028
|
+
if (this.keys.getKeySet(keyIndex) && this.keys.hasValidKey) {
|
|
1029
|
+
try {
|
|
1030
|
+
const decodedFrame = yield this.decryptFrame(encodedFrame, keyIndex);
|
|
1031
|
+
this.keys.decryptionSuccess();
|
|
1032
|
+
if (decodedFrame) {
|
|
1033
|
+
return controller.enqueue(decodedFrame);
|
|
1034
|
+
}
|
|
1035
|
+
} catch (error) {
|
|
1036
|
+
if (error instanceof CryptorError && error.reason === CryptorErrorReason.InvalidKey) {
|
|
1037
|
+
if (this.keys.hasValidKey) {
|
|
1038
|
+
workerLogger.warn('invalid key');
|
|
1039
|
+
this.emit(CryptorEvent.Error, new CryptorError("invalid key for participant ".concat(this.participantId), CryptorErrorReason.InvalidKey));
|
|
1040
|
+
this.keys.decryptionFailure();
|
|
1041
|
+
}
|
|
1042
|
+
} else {
|
|
1043
|
+
workerLogger.warn('decoding frame failed', {
|
|
1044
|
+
error
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return controller.enqueue(encodedFrame);
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Function that will decrypt the given encoded frame. If the decryption fails, it will
|
|
1054
|
+
* ratchet the key for up to RATCHET_WINDOW_SIZE times.
|
|
1055
|
+
*/
|
|
1056
|
+
decryptFrame(encodedFrame, keyIndex) {
|
|
1057
|
+
let initialMaterial = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
1058
|
+
let ratchetOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
1059
|
+
ratchetCount: 0
|
|
1060
|
+
};
|
|
1061
|
+
var _a;
|
|
1062
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1063
|
+
const keySet = this.keys.getKeySet(keyIndex);
|
|
1064
|
+
// Construct frame trailer. Similar to the frame header described in
|
|
1065
|
+
// https://tools.ietf.org/html/draft-omara-sframe-00#section-4.2
|
|
1066
|
+
// but we put it at the end.
|
|
1067
|
+
//
|
|
1068
|
+
// ---------+-------------------------+-+---------+----
|
|
1069
|
+
// payload |IV...(length = IV_LENGTH)|R|IV_LENGTH|KID |
|
|
1070
|
+
// ---------+-------------------------+-+---------+----
|
|
1071
|
+
try {
|
|
1072
|
+
const frameHeader = new Uint8Array(encodedFrame.data, 0, this.getUnencryptedBytes(encodedFrame));
|
|
1073
|
+
const frameTrailer = new Uint8Array(encodedFrame.data, encodedFrame.data.byteLength - 2, 2);
|
|
1074
|
+
const ivLength = frameTrailer[0];
|
|
1075
|
+
const iv = new Uint8Array(encodedFrame.data, encodedFrame.data.byteLength - ivLength - frameTrailer.byteLength, ivLength);
|
|
1076
|
+
const cipherTextStart = frameHeader.byteLength;
|
|
1077
|
+
const cipherTextLength = encodedFrame.data.byteLength - (frameHeader.byteLength + ivLength + frameTrailer.byteLength);
|
|
1078
|
+
const plainText = yield crypto.subtle.decrypt({
|
|
1079
|
+
name: ENCRYPTION_ALGORITHM,
|
|
1080
|
+
iv,
|
|
1081
|
+
additionalData: new Uint8Array(encodedFrame.data, 0, frameHeader.byteLength)
|
|
1082
|
+
}, (_a = ratchetOpts.encryptionKey) !== null && _a !== void 0 ? _a : keySet.encryptionKey, new Uint8Array(encodedFrame.data, cipherTextStart, cipherTextLength));
|
|
1083
|
+
const newData = new ArrayBuffer(frameHeader.byteLength + plainText.byteLength);
|
|
1084
|
+
const newUint8 = new Uint8Array(newData);
|
|
1085
|
+
newUint8.set(new Uint8Array(encodedFrame.data, 0, frameHeader.byteLength));
|
|
1086
|
+
newUint8.set(new Uint8Array(plainText), frameHeader.byteLength);
|
|
1087
|
+
encodedFrame.data = newData;
|
|
1088
|
+
return encodedFrame;
|
|
1089
|
+
} catch (error) {
|
|
1090
|
+
if (this.keyProviderOptions.ratchetWindowSize > 0) {
|
|
1091
|
+
if (ratchetOpts.ratchetCount < this.keyProviderOptions.ratchetWindowSize) {
|
|
1092
|
+
workerLogger.debug("ratcheting key attempt ".concat(ratchetOpts.ratchetCount, " of ").concat(this.keyProviderOptions.ratchetWindowSize, ", for kind ").concat(encodedFrame instanceof RTCEncodedAudioFrame ? 'audio' : 'video'));
|
|
1093
|
+
let ratchetedKeySet;
|
|
1094
|
+
if (keySet === this.keys.getKeySet(keyIndex)) {
|
|
1095
|
+
// only ratchet if the currently set key is still the same as the one used to decrypt this frame
|
|
1096
|
+
// if not, it might be that a different frame has already ratcheted and we try with that one first
|
|
1097
|
+
const newMaterial = yield this.keys.ratchetKey(keyIndex, false);
|
|
1098
|
+
ratchetedKeySet = yield deriveKeys(newMaterial, this.keyProviderOptions.ratchetSalt);
|
|
1099
|
+
}
|
|
1100
|
+
const frame = yield this.decryptFrame(encodedFrame, keyIndex, initialMaterial || keySet, {
|
|
1101
|
+
ratchetCount: ratchetOpts.ratchetCount + 1,
|
|
1102
|
+
encryptionKey: ratchetedKeySet === null || ratchetedKeySet === void 0 ? void 0 : ratchetedKeySet.encryptionKey
|
|
1103
|
+
});
|
|
1104
|
+
if (frame && ratchetedKeySet) {
|
|
1105
|
+
this.keys.setKeySet(ratchetedKeySet, keyIndex, true);
|
|
1106
|
+
// decryption was successful, set the new key index to reflect the ratcheted key set
|
|
1107
|
+
this.keys.setCurrentKeyIndex(keyIndex);
|
|
1108
|
+
}
|
|
1109
|
+
return frame;
|
|
1110
|
+
} else {
|
|
1111
|
+
/**
|
|
1112
|
+
* Since the key it is first send and only afterwards actually used for encrypting, there were
|
|
1113
|
+
* situations when the decrypting failed due to the fact that the received frame was not encrypted
|
|
1114
|
+
* yet and ratcheting, of course, did not solve the problem. So if we fail RATCHET_WINDOW_SIZE times,
|
|
1115
|
+
* we come back to the initial key.
|
|
1116
|
+
*/
|
|
1117
|
+
if (initialMaterial) {
|
|
1118
|
+
workerLogger.debug('resetting to initial material');
|
|
1119
|
+
this.keys.setKeyFromMaterial(initialMaterial.material, keyIndex);
|
|
1120
|
+
}
|
|
1121
|
+
workerLogger.warn('maximum ratchet attempts exceeded, resetting key');
|
|
1122
|
+
this.emit(CryptorEvent.Error, new CryptorError("valid key missing for participant ".concat(this.participantId), CryptorErrorReason.MissingKey));
|
|
1123
|
+
}
|
|
1124
|
+
} else {
|
|
1125
|
+
throw new CryptorError('Decryption failed, most likely because of an invalid key', CryptorErrorReason.InvalidKey);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Construct the IV used for AES-GCM and sent (in plain) with the packet similar to
|
|
1132
|
+
* https://tools.ietf.org/html/rfc7714#section-8.1
|
|
1133
|
+
* It concatenates
|
|
1134
|
+
* - the 32 bit synchronization source (SSRC) given on the encoded frame,
|
|
1135
|
+
* - the 32 bit rtp timestamp given on the encoded frame,
|
|
1136
|
+
* - a send counter that is specific to the SSRC. Starts at a random number.
|
|
1137
|
+
* The send counter is essentially the pictureId but we currently have to implement this ourselves.
|
|
1138
|
+
* There is no XOR with a salt. Note that this IV leaks the SSRC to the receiver but since this is
|
|
1139
|
+
* randomly generated and SFUs may not rewrite this is considered acceptable.
|
|
1140
|
+
* The SSRC is used to allow demultiplexing multiple streams with the same key, as described in
|
|
1141
|
+
* https://tools.ietf.org/html/rfc3711#section-4.1.1
|
|
1142
|
+
* The RTP timestamp is 32 bits and advances by the codec clock rate (90khz for video, 48khz for
|
|
1143
|
+
* opus audio) every second. For video it rolls over roughly every 13 hours.
|
|
1144
|
+
* The send counter will advance at the frame rate (30fps for video, 50fps for 20ms opus audio)
|
|
1145
|
+
* every second. It will take a long time to roll over.
|
|
1146
|
+
*
|
|
1147
|
+
* See also https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams
|
|
1148
|
+
*/
|
|
1149
|
+
makeIV(synchronizationSource, timestamp) {
|
|
1150
|
+
var _a;
|
|
1151
|
+
const iv = new ArrayBuffer(IV_LENGTH);
|
|
1152
|
+
const ivView = new DataView(iv);
|
|
1153
|
+
// having to keep our own send count (similar to a picture id) is not ideal.
|
|
1154
|
+
if (!this.sendCounts.has(synchronizationSource)) {
|
|
1155
|
+
// Initialize with a random offset, similar to the RTP sequence number.
|
|
1156
|
+
this.sendCounts.set(synchronizationSource, Math.floor(Math.random() * 0xffff));
|
|
1157
|
+
}
|
|
1158
|
+
const sendCount = (_a = this.sendCounts.get(synchronizationSource)) !== null && _a !== void 0 ? _a : 0;
|
|
1159
|
+
ivView.setUint32(0, synchronizationSource);
|
|
1160
|
+
ivView.setUint32(4, timestamp);
|
|
1161
|
+
ivView.setUint32(8, timestamp - sendCount % 0xffff);
|
|
1162
|
+
this.sendCounts.set(synchronizationSource, sendCount + 1);
|
|
1163
|
+
return iv;
|
|
1164
|
+
}
|
|
1165
|
+
getUnencryptedBytes(frame) {
|
|
1166
|
+
var _a;
|
|
1167
|
+
if (isVideoFrame(frame)) {
|
|
1168
|
+
let detectedCodec = (_a = this.getVideoCodec(frame)) !== null && _a !== void 0 ? _a : this.videoCodec;
|
|
1169
|
+
if (detectedCodec === 'av1' || detectedCodec === 'vp9') {
|
|
1170
|
+
throw new Error("".concat(detectedCodec, " is not yet supported for end to end encryption"));
|
|
1171
|
+
}
|
|
1172
|
+
if (detectedCodec === 'vp8') {
|
|
1173
|
+
return UNENCRYPTED_BYTES[frame.type];
|
|
1174
|
+
}
|
|
1175
|
+
const data = new Uint8Array(frame.data);
|
|
1176
|
+
try {
|
|
1177
|
+
const naluIndices = findNALUIndices(data);
|
|
1178
|
+
// if the detected codec is undefined we test whether it _looks_ like a h264 frame as a best guess
|
|
1179
|
+
const isH264 = detectedCodec === 'h264' || naluIndices.some(naluIndex => [NALUType.SLICE_IDR, NALUType.SLICE_NON_IDR].includes(parseNALUType(data[naluIndex])));
|
|
1180
|
+
if (isH264) {
|
|
1181
|
+
for (const index of naluIndices) {
|
|
1182
|
+
let type = parseNALUType(data[index]);
|
|
1183
|
+
switch (type) {
|
|
1184
|
+
case NALUType.SLICE_IDR:
|
|
1185
|
+
case NALUType.SLICE_NON_IDR:
|
|
1186
|
+
return index + 2;
|
|
1187
|
+
default:
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
throw new TypeError('Could not find NALU');
|
|
1192
|
+
}
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
// no op, we just continue and fallback to vp8
|
|
1195
|
+
}
|
|
1196
|
+
return UNENCRYPTED_BYTES[frame.type];
|
|
1197
|
+
} else {
|
|
1198
|
+
return UNENCRYPTED_BYTES.audio;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* inspects frame payloadtype if available and maps it to the codec specified in rtpMap
|
|
1203
|
+
*/
|
|
1204
|
+
getVideoCodec(frame) {
|
|
1205
|
+
if (this.rtpMap.size === 0) {
|
|
1206
|
+
return undefined;
|
|
1207
|
+
}
|
|
1208
|
+
// @ts-expect-error payloadType is not yet part of the typescript definition and currently not supported in Safari
|
|
1209
|
+
const payloadType = frame.getMetadata().payloadType;
|
|
1210
|
+
const codec = payloadType ? this.rtpMap.get(payloadType) : undefined;
|
|
1211
|
+
return codec;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Slice the NALUs present in the supplied buffer, assuming it is already byte-aligned
|
|
1216
|
+
* code adapted from https://github.com/medooze/h264-frame-parser/blob/main/lib/NalUnits.ts to return indices only
|
|
1217
|
+
*/
|
|
1218
|
+
function findNALUIndices(stream) {
|
|
1219
|
+
const result = [];
|
|
1220
|
+
let start = 0,
|
|
1221
|
+
pos = 0,
|
|
1222
|
+
searchLength = stream.length - 2;
|
|
1223
|
+
while (pos < searchLength) {
|
|
1224
|
+
// skip until end of current NALU
|
|
1225
|
+
while (pos < searchLength && !(stream[pos] === 0 && stream[pos + 1] === 0 && stream[pos + 2] === 1)) pos++;
|
|
1226
|
+
if (pos >= searchLength) pos = stream.length;
|
|
1227
|
+
// remove trailing zeros from current NALU
|
|
1228
|
+
let end = pos;
|
|
1229
|
+
while (end > start && stream[end - 1] === 0) end--;
|
|
1230
|
+
// save current NALU
|
|
1231
|
+
if (start === 0) {
|
|
1232
|
+
if (end !== start) throw TypeError('byte stream contains leading data');
|
|
1233
|
+
} else {
|
|
1234
|
+
result.push(start);
|
|
1235
|
+
}
|
|
1236
|
+
// begin new NALU
|
|
1237
|
+
start = pos = pos + 3;
|
|
1238
|
+
}
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
function parseNALUType(startByte) {
|
|
1242
|
+
return startByte & kNaluTypeMask;
|
|
1243
|
+
}
|
|
1244
|
+
const kNaluTypeMask = 0x1f;
|
|
1245
|
+
var NALUType;
|
|
1246
|
+
(function (NALUType) {
|
|
1247
|
+
/** Coded slice of a non-IDR picture */
|
|
1248
|
+
NALUType[NALUType["SLICE_NON_IDR"] = 1] = "SLICE_NON_IDR";
|
|
1249
|
+
/** Coded slice data partition A */
|
|
1250
|
+
NALUType[NALUType["SLICE_PARTITION_A"] = 2] = "SLICE_PARTITION_A";
|
|
1251
|
+
/** Coded slice data partition B */
|
|
1252
|
+
NALUType[NALUType["SLICE_PARTITION_B"] = 3] = "SLICE_PARTITION_B";
|
|
1253
|
+
/** Coded slice data partition C */
|
|
1254
|
+
NALUType[NALUType["SLICE_PARTITION_C"] = 4] = "SLICE_PARTITION_C";
|
|
1255
|
+
/** Coded slice of an IDR picture */
|
|
1256
|
+
NALUType[NALUType["SLICE_IDR"] = 5] = "SLICE_IDR";
|
|
1257
|
+
/** Supplemental enhancement information */
|
|
1258
|
+
NALUType[NALUType["SEI"] = 6] = "SEI";
|
|
1259
|
+
/** Sequence parameter set */
|
|
1260
|
+
NALUType[NALUType["SPS"] = 7] = "SPS";
|
|
1261
|
+
/** Picture parameter set */
|
|
1262
|
+
NALUType[NALUType["PPS"] = 8] = "PPS";
|
|
1263
|
+
/** Access unit delimiter */
|
|
1264
|
+
NALUType[NALUType["AUD"] = 9] = "AUD";
|
|
1265
|
+
/** End of sequence */
|
|
1266
|
+
NALUType[NALUType["END_SEQ"] = 10] = "END_SEQ";
|
|
1267
|
+
/** End of stream */
|
|
1268
|
+
NALUType[NALUType["END_STREAM"] = 11] = "END_STREAM";
|
|
1269
|
+
/** Filler data */
|
|
1270
|
+
NALUType[NALUType["FILLER_DATA"] = 12] = "FILLER_DATA";
|
|
1271
|
+
/** Sequence parameter set extension */
|
|
1272
|
+
NALUType[NALUType["SPS_EXT"] = 13] = "SPS_EXT";
|
|
1273
|
+
/** Prefix NAL unit */
|
|
1274
|
+
NALUType[NALUType["PREFIX_NALU"] = 14] = "PREFIX_NALU";
|
|
1275
|
+
/** Subset sequence parameter set */
|
|
1276
|
+
NALUType[NALUType["SUBSET_SPS"] = 15] = "SUBSET_SPS";
|
|
1277
|
+
/** Depth parameter set */
|
|
1278
|
+
NALUType[NALUType["DPS"] = 16] = "DPS";
|
|
1279
|
+
// 17, 18 reserved
|
|
1280
|
+
/** Coded slice of an auxiliary coded picture without partitioning */
|
|
1281
|
+
NALUType[NALUType["SLICE_AUX"] = 19] = "SLICE_AUX";
|
|
1282
|
+
/** Coded slice extension */
|
|
1283
|
+
NALUType[NALUType["SLICE_EXT"] = 20] = "SLICE_EXT";
|
|
1284
|
+
/** Coded slice extension for a depth view component or a 3D-AVC texture view component */
|
|
1285
|
+
NALUType[NALUType["SLICE_LAYER_EXT"] = 21] = "SLICE_LAYER_EXT";
|
|
1286
|
+
// 22, 23 reserved
|
|
1287
|
+
})(NALUType || (NALUType = {}));
|
|
1288
|
+
/**
|
|
1289
|
+
* we use a magic frame trailer to detect whether a frame is injected
|
|
1290
|
+
* by the livekit server and thus to be treated as unencrypted
|
|
1291
|
+
* @internal
|
|
1292
|
+
*/
|
|
1293
|
+
function isFrameServerInjected(frameData, trailerBytes) {
|
|
1294
|
+
const frameTrailer = new Uint8Array(frameData.slice(frameData.byteLength - trailerBytes.byteLength));
|
|
1295
|
+
return trailerBytes.every((value, index) => value === frameTrailer[index]);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
// TODO ParticipantKeyHandlers currently don't get destroyed on participant disconnect
|
|
1299
|
+
// we could do this by having a separate worker message on participant disconnected.
|
|
1300
|
+
/**
|
|
1301
|
+
* ParticipantKeyHandler is responsible for providing a cryptor instance with the
|
|
1302
|
+
* en-/decryption key of a participant. It assumes that all tracks of a specific participant
|
|
1303
|
+
* are encrypted with the same key.
|
|
1304
|
+
* Additionally it exposes a method to ratchet a key which can be used by the cryptor either automatically
|
|
1305
|
+
* if decryption fails or can be triggered manually on both sender and receiver side.
|
|
1306
|
+
*
|
|
1307
|
+
*/
|
|
1308
|
+
class ParticipantKeyHandler extends eventsExports.EventEmitter {
|
|
1309
|
+
get hasValidKey() {
|
|
1310
|
+
return this._hasValidKey;
|
|
1311
|
+
}
|
|
1312
|
+
constructor(participantId, isEnabled, keyProviderOptions) {
|
|
1313
|
+
super();
|
|
1314
|
+
this.decryptionFailureCount = 0;
|
|
1315
|
+
this._hasValidKey = true;
|
|
1316
|
+
this.currentKeyIndex = 0;
|
|
1317
|
+
this.cryptoKeyRing = new Array(KEYRING_SIZE);
|
|
1318
|
+
this.enabled = isEnabled;
|
|
1319
|
+
this.keyProviderOptions = keyProviderOptions;
|
|
1320
|
+
this.ratchetPromiseMap = new Map();
|
|
1321
|
+
this.participantId = participantId;
|
|
1322
|
+
this.resetKeyStatus();
|
|
1323
|
+
}
|
|
1324
|
+
setEnabled(enabled) {
|
|
1325
|
+
this.enabled = enabled;
|
|
1326
|
+
}
|
|
1327
|
+
decryptionFailure() {
|
|
1328
|
+
if (this.keyProviderOptions.failureTolerance < 0) {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
this.decryptionFailureCount += 1;
|
|
1332
|
+
if (this.decryptionFailureCount > this.keyProviderOptions.failureTolerance) {
|
|
1333
|
+
this._hasValidKey = false;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
decryptionSuccess() {
|
|
1337
|
+
this.resetKeyStatus();
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Call this after user initiated ratchet or a new key has been set in order to make sure to mark potentially
|
|
1341
|
+
* invalid keys as valid again
|
|
1342
|
+
*/
|
|
1343
|
+
resetKeyStatus() {
|
|
1344
|
+
this.decryptionFailureCount = 0;
|
|
1345
|
+
this._hasValidKey = true;
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Ratchets the current key (or the one at keyIndex if provided) and
|
|
1349
|
+
* returns the ratcheted material
|
|
1350
|
+
* if `setKey` is true (default), it will also set the ratcheted key directly on the crypto key ring
|
|
1351
|
+
* @param keyIndex
|
|
1352
|
+
* @param setKey
|
|
1353
|
+
*/
|
|
1354
|
+
ratchetKey(keyIndex) {
|
|
1355
|
+
let setKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1356
|
+
const currentKeyIndex = keyIndex !== null && keyIndex !== void 0 ? keyIndex : keyIndex = this.getCurrentKeyIndex();
|
|
1357
|
+
const existingPromise = this.ratchetPromiseMap.get(currentKeyIndex);
|
|
1358
|
+
if (typeof existingPromise !== 'undefined') {
|
|
1359
|
+
return existingPromise;
|
|
1360
|
+
}
|
|
1361
|
+
const ratchetPromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
1362
|
+
try {
|
|
1363
|
+
const currentMaterial = this.getKeySet(currentKeyIndex).material;
|
|
1364
|
+
const newMaterial = yield importKey(yield ratchet(currentMaterial, this.keyProviderOptions.ratchetSalt), currentMaterial.algorithm.name, 'derive');
|
|
1365
|
+
if (setKey) {
|
|
1366
|
+
this.setKeyFromMaterial(newMaterial, currentKeyIndex, true);
|
|
1367
|
+
}
|
|
1368
|
+
this.emit('keyRatcheted', newMaterial, keyIndex, this.participantId);
|
|
1369
|
+
resolve(newMaterial);
|
|
1370
|
+
} catch (e) {
|
|
1371
|
+
reject(e);
|
|
1372
|
+
} finally {
|
|
1373
|
+
this.ratchetPromiseMap.delete(currentKeyIndex);
|
|
1374
|
+
}
|
|
1375
|
+
}));
|
|
1376
|
+
this.ratchetPromiseMap.set(currentKeyIndex, ratchetPromise);
|
|
1377
|
+
return ratchetPromise;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
|
1381
|
+
* and derives encryption keys from the material and sets it on the key ring buffer
|
|
1382
|
+
* together with the material
|
|
1383
|
+
* also resets the valid key property and updates the currentKeyIndex
|
|
1384
|
+
*/
|
|
1385
|
+
setKey(material) {
|
|
1386
|
+
let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1387
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1388
|
+
yield this.setKeyFromMaterial(material, keyIndex);
|
|
1389
|
+
this.resetKeyStatus();
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* takes in a key material with `deriveBits` and `deriveKey` set as key usages
|
|
1394
|
+
* and derives encryption keys from the material and sets it on the key ring buffer
|
|
1395
|
+
* together with the material
|
|
1396
|
+
* also updates the currentKeyIndex
|
|
1397
|
+
*/
|
|
1398
|
+
setKeyFromMaterial(material) {
|
|
1399
|
+
let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1400
|
+
let emitRatchetEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1401
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1402
|
+
workerLogger.debug('setting new key');
|
|
1403
|
+
if (keyIndex >= 0) {
|
|
1404
|
+
this.currentKeyIndex = keyIndex % this.cryptoKeyRing.length;
|
|
1405
|
+
}
|
|
1406
|
+
const keySet = yield deriveKeys(material, this.keyProviderOptions.ratchetSalt);
|
|
1407
|
+
this.setKeySet(keySet, this.currentKeyIndex, emitRatchetEvent);
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
setKeySet(keySet, keyIndex) {
|
|
1411
|
+
let emitRatchetEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1412
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1413
|
+
this.cryptoKeyRing[keyIndex % this.cryptoKeyRing.length] = keySet;
|
|
1414
|
+
if (emitRatchetEvent) {
|
|
1415
|
+
this.emit('keyRatcheted', keySet.material, keyIndex, this.participantId);
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
setCurrentKeyIndex(index) {
|
|
1420
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1421
|
+
this.currentKeyIndex = index % this.cryptoKeyRing.length;
|
|
1422
|
+
this.resetKeyStatus();
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
isEnabled() {
|
|
1426
|
+
return this.enabled;
|
|
1427
|
+
}
|
|
1428
|
+
getCurrentKeyIndex() {
|
|
1429
|
+
return this.currentKeyIndex;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* returns currently used KeySet or the one at `keyIndex` if provided
|
|
1433
|
+
* @param keyIndex
|
|
1434
|
+
* @returns
|
|
1435
|
+
*/
|
|
1436
|
+
getKeySet(keyIndex) {
|
|
1437
|
+
return this.cryptoKeyRing[keyIndex !== null && keyIndex !== void 0 ? keyIndex : this.currentKeyIndex];
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const participantCryptors = [];
|
|
1442
|
+
const participantKeys = new Map();
|
|
1443
|
+
let publishCryptors = [];
|
|
1444
|
+
let publisherKeys;
|
|
1445
|
+
let isEncryptionEnabled = false;
|
|
1446
|
+
let useSharedKey = false;
|
|
1447
|
+
let sharedKey;
|
|
1448
|
+
let keyProviderOptions = KEY_PROVIDER_DEFAULTS;
|
|
1449
|
+
workerLogger.setDefaultLevel('info');
|
|
1450
|
+
onmessage = ev => {
|
|
1451
|
+
const {
|
|
1452
|
+
kind,
|
|
1453
|
+
data
|
|
1454
|
+
} = ev.data;
|
|
1455
|
+
switch (kind) {
|
|
1456
|
+
case 'init':
|
|
1457
|
+
workerLogger.info('worker initialized');
|
|
1458
|
+
keyProviderOptions = data.keyProviderOptions;
|
|
1459
|
+
useSharedKey = !!data.keyProviderOptions.sharedKey;
|
|
1460
|
+
// acknowledge init successful
|
|
1461
|
+
const enableMsg = {
|
|
1462
|
+
kind: 'enable',
|
|
1463
|
+
data: {
|
|
1464
|
+
enabled: isEncryptionEnabled
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
publisherKeys = new ParticipantKeyHandler(undefined, isEncryptionEnabled, keyProviderOptions);
|
|
1468
|
+
publisherKeys.on('keyRatcheted', emitRatchetedKeys);
|
|
1469
|
+
postMessage(enableMsg);
|
|
1470
|
+
break;
|
|
1471
|
+
case 'enable':
|
|
1472
|
+
setEncryptionEnabled(data.enabled, data.participantId);
|
|
1473
|
+
workerLogger.info('updated e2ee enabled status');
|
|
1474
|
+
// acknowledge enable call successful
|
|
1475
|
+
postMessage(ev.data);
|
|
1476
|
+
break;
|
|
1477
|
+
case 'decode':
|
|
1478
|
+
let cryptor = getTrackCryptor(data.participantId, data.trackId);
|
|
1479
|
+
cryptor.setupTransform(kind, data.readableStream, data.writableStream, data.trackId, data.codec);
|
|
1480
|
+
break;
|
|
1481
|
+
case 'encode':
|
|
1482
|
+
let pubCryptor = getPublisherCryptor(data.trackId);
|
|
1483
|
+
pubCryptor.setupTransform(kind, data.readableStream, data.writableStream, data.trackId, data.codec);
|
|
1484
|
+
break;
|
|
1485
|
+
case 'setKey':
|
|
1486
|
+
if (useSharedKey) {
|
|
1487
|
+
workerLogger.debug('set shared key');
|
|
1488
|
+
setSharedKey(data.key, data.keyIndex);
|
|
1489
|
+
} else if (data.participantId) {
|
|
1490
|
+
getParticipantKeyHandler(data.participantId).setKey(data.key, data.keyIndex);
|
|
1491
|
+
} else {
|
|
1492
|
+
workerLogger.error('no participant Id was provided and shared key usage is disabled');
|
|
1493
|
+
}
|
|
1494
|
+
break;
|
|
1495
|
+
case 'removeTransform':
|
|
1496
|
+
unsetCryptorParticipant(data.trackId);
|
|
1497
|
+
break;
|
|
1498
|
+
case 'updateCodec':
|
|
1499
|
+
getTrackCryptor(data.participantId, data.trackId).setVideoCodec(data.codec);
|
|
1500
|
+
break;
|
|
1501
|
+
case 'setRTPMap':
|
|
1502
|
+
publishCryptors.forEach(cr => {
|
|
1503
|
+
cr.setRtpMap(data.map);
|
|
1504
|
+
});
|
|
1505
|
+
break;
|
|
1506
|
+
case 'ratchetRequest':
|
|
1507
|
+
handleRatchetRequest(data);
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
function handleRatchetRequest(data) {
|
|
1511
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1512
|
+
const keyHandler = getParticipantKeyHandler(data.participantId);
|
|
1513
|
+
yield keyHandler.ratchetKey(data.keyIndex);
|
|
1514
|
+
keyHandler.resetKeyStatus();
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function getTrackCryptor(participantId, trackId) {
|
|
1518
|
+
let cryptor = participantCryptors.find(c => c.getTrackId() === trackId);
|
|
1519
|
+
if (!cryptor) {
|
|
1520
|
+
workerLogger.info('creating new cryptor for', {
|
|
1521
|
+
participantId
|
|
1522
|
+
});
|
|
1523
|
+
if (!keyProviderOptions) {
|
|
1524
|
+
throw Error('Missing keyProvider options');
|
|
1525
|
+
}
|
|
1526
|
+
cryptor = new FrameCryptor({
|
|
1527
|
+
participantId,
|
|
1528
|
+
keys: getParticipantKeyHandler(participantId),
|
|
1529
|
+
keyProviderOptions
|
|
1530
|
+
});
|
|
1531
|
+
setupCryptorErrorEvents(cryptor);
|
|
1532
|
+
participantCryptors.push(cryptor);
|
|
1533
|
+
} else if (participantId !== cryptor.getParticipantId()) {
|
|
1534
|
+
// assign new participant id to track cryptor and pass in correct key handler
|
|
1535
|
+
cryptor.setParticipant(participantId, getParticipantKeyHandler(participantId));
|
|
1536
|
+
}
|
|
1537
|
+
return cryptor;
|
|
1538
|
+
}
|
|
1539
|
+
function getParticipantKeyHandler(participantId) {
|
|
1540
|
+
if (!participantId) {
|
|
1541
|
+
return publisherKeys;
|
|
1542
|
+
}
|
|
1543
|
+
let keys = participantKeys.get(participantId);
|
|
1544
|
+
if (!keys) {
|
|
1545
|
+
keys = new ParticipantKeyHandler(participantId, true, keyProviderOptions);
|
|
1546
|
+
if (sharedKey) {
|
|
1547
|
+
keys.setKey(sharedKey);
|
|
1548
|
+
}
|
|
1549
|
+
participantKeys.set(participantId, keys);
|
|
1550
|
+
}
|
|
1551
|
+
return keys;
|
|
1552
|
+
}
|
|
1553
|
+
function unsetCryptorParticipant(trackId) {
|
|
1554
|
+
var _a;
|
|
1555
|
+
(_a = participantCryptors.find(c => c.getTrackId() === trackId)) === null || _a === void 0 ? void 0 : _a.unsetParticipant();
|
|
1556
|
+
}
|
|
1557
|
+
function getPublisherCryptor(trackId) {
|
|
1558
|
+
let publishCryptor = publishCryptors.find(cryptor => cryptor.getTrackId() === trackId);
|
|
1559
|
+
if (!publishCryptor) {
|
|
1560
|
+
if (!keyProviderOptions) {
|
|
1561
|
+
throw new TypeError('Missing keyProvider options');
|
|
1562
|
+
}
|
|
1563
|
+
publishCryptor = new FrameCryptor({
|
|
1564
|
+
keys: publisherKeys,
|
|
1565
|
+
participantId: 'publisher',
|
|
1566
|
+
keyProviderOptions
|
|
1567
|
+
});
|
|
1568
|
+
setupCryptorErrorEvents(publishCryptor);
|
|
1569
|
+
publishCryptors.push(publishCryptor);
|
|
1570
|
+
}
|
|
1571
|
+
return publishCryptor;
|
|
1572
|
+
}
|
|
1573
|
+
function setEncryptionEnabled(enable, participantId) {
|
|
1574
|
+
if (!participantId) {
|
|
1575
|
+
isEncryptionEnabled = enable;
|
|
1576
|
+
publisherKeys.setEnabled(enable);
|
|
1577
|
+
} else {
|
|
1578
|
+
getParticipantKeyHandler(participantId).setEnabled(enable);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function setSharedKey(key, index) {
|
|
1582
|
+
workerLogger.debug('setting shared key');
|
|
1583
|
+
sharedKey = key;
|
|
1584
|
+
publisherKeys === null || publisherKeys === void 0 ? void 0 : publisherKeys.setKey(key, index);
|
|
1585
|
+
for (const [, keyHandler] of participantKeys) {
|
|
1586
|
+
keyHandler.setKey(key, index);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function setupCryptorErrorEvents(cryptor) {
|
|
1590
|
+
cryptor.on('cryptorError', error => {
|
|
1591
|
+
const msg = {
|
|
1592
|
+
kind: 'error',
|
|
1593
|
+
data: {
|
|
1594
|
+
error: new Error("".concat(CryptorErrorReason[error.reason], ": ").concat(error.message))
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
postMessage(msg);
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
function emitRatchetedKeys(material, keyIndex) {
|
|
1601
|
+
const msg = {
|
|
1602
|
+
kind: "ratchetKey",
|
|
1603
|
+
data: {
|
|
1604
|
+
// participantId,
|
|
1605
|
+
keyIndex,
|
|
1606
|
+
material
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
postMessage(msg);
|
|
1610
|
+
}
|
|
1611
|
+
// Operations using RTCRtpScriptTransform.
|
|
1612
|
+
// @ts-ignore
|
|
1613
|
+
if (self.RTCTransformEvent) {
|
|
1614
|
+
workerLogger.debug('setup transform event');
|
|
1615
|
+
// @ts-ignore
|
|
1616
|
+
self.onrtctransform = event => {
|
|
1617
|
+
const transformer = event.transformer;
|
|
1618
|
+
workerLogger.debug('transformer', transformer);
|
|
1619
|
+
transformer.handled = true;
|
|
1620
|
+
const {
|
|
1621
|
+
kind,
|
|
1622
|
+
participantId,
|
|
1623
|
+
trackId,
|
|
1624
|
+
codec
|
|
1625
|
+
} = transformer.options;
|
|
1626
|
+
const cryptor = kind === 'encode' ? getPublisherCryptor(trackId) : getTrackCryptor(participantId, trackId);
|
|
1627
|
+
workerLogger.debug('transform', {
|
|
1628
|
+
codec
|
|
1629
|
+
});
|
|
1630
|
+
cryptor.setupTransform(kind, transformer.readable, transformer.writable, trackId, codec);
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
//# sourceMappingURL=livekit-client.e2ee.worker.mjs.map
|