diff --git a/lib/DummyKeyProvider.ts b/lib/DummyKeyProvider.ts deleted file mode 100644 index b0c5b80..0000000 --- a/lib/DummyKeyProvider.ts +++ /dev/null @@ -1,16 +0,0 @@ -// just for demonstration purposes, extremely insecure - -import { BaseKeyProvider, createKeyMaterialFromString } from 'livekit-client'; - -export class DummyKeyProvider extends BaseKeyProvider { - readonly participantKeys = new Map([ - ['dev1', 'dev1key'], - ['dev2', 'dev2key'], - ]); - - async setKey(participantId: string) { - // @ts-ignore - const cryptoKey = await createKeyMaterialFromString(this.participantKeys.get(participantId)); - this.onSetEncryptionKey(cryptoKey, participantId); - } -} diff --git a/pages/custom/index.tsx b/pages/custom/index.tsx index aeed27a..93b85a8 100644 --- a/pages/custom/index.tsx +++ b/pages/custom/index.tsx @@ -1,5 +1,12 @@ import { formatChatMessageLinks, LiveKitRoom, VideoConference } from '@livekit/components-react'; -import { ExternalE2EEKeyProvider, LogLevel, Room, RoomOptions, VideoPresets } from 'livekit-client'; +import { + ExternalE2EEKeyProvider, + LogLevel, + RoomConnectOptions, + Room, + RoomOptions, + VideoPresets, +} from 'livekit-client'; import { useRouter } from 'next/router'; import { DebugMode } from '../../lib/Debug'; import { decodePassphrase } from '../../lib/client-utils'; @@ -10,14 +17,12 @@ export default function CustomRoomConnection() { const { liveKitUrl, token } = router.query; const hash = typeof window !== 'undefined' && window.location.hash; - const keyProvider = new ExternalE2EEKeyProvider(); - if (hash) { - keyProvider.setKey(decodePassphrase(hash.substring(1))); - } - const worker = typeof window !== 'undefined' && new Worker(new URL('livekit-client/e2ee-worker', import.meta.url)); + const keyProvider = new ExternalE2EEKeyProvider(); + + const e2eeEnabled = !!(hash && worker); const roomOptions = useMemo((): RoomOptions => { return { @@ -26,17 +31,26 @@ export default function CustomRoomConnection() { }, adaptiveStream: { pixelDensity: 'screen' }, dynacast: true, - e2ee: - hash && worker - ? { - keyProvider, - worker, - } - : undefined, + e2ee: e2eeEnabled + ? { + keyProvider, + worker, + } + : undefined, }; }, []); const room = useMemo(() => new Room(roomOptions), []); + if (e2eeEnabled) { + keyProvider.setKey(decodePassphrase(hash.substring(1))); + room.setE2EEEnabled(true); + } + + const connectOptions = useMemo((): RoomConnectOptions => { + return { + autoSubscribe: false, + }; + }, []); if (typeof liveKitUrl !== 'string') { return