2023-03-13 16:46:37 +01:00
|
|
|
import { formatChatMessageLinks, LiveKitRoom, VideoConference } from '@livekit/components-react';
|
2023-08-30 11:25:22 +02:00
|
|
|
import { ExternalE2EEKeyProvider, LogLevel, Room, RoomOptions, VideoPresets } from 'livekit-client';
|
2023-03-13 16:46:37 +01:00
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { DebugMode } from '../../lib/Debug';
|
2023-08-30 11:25:22 +02:00
|
|
|
import { decodePassphrase } from '../../lib/client-utils';
|
|
|
|
import { useMemo } from 'react';
|
2023-03-13 16:46:37 +01:00
|
|
|
|
|
|
|
export default function CustomRoomConnection() {
|
|
|
|
const router = useRouter();
|
|
|
|
const { liveKitUrl, token } = router.query;
|
2023-08-30 11:25:22 +02:00
|
|
|
|
|
|
|
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 roomOptions = useMemo((): RoomOptions => {
|
|
|
|
return {
|
|
|
|
publishDefaults: {
|
|
|
|
videoSimulcastLayers: [VideoPresets.h540, VideoPresets.h216],
|
|
|
|
},
|
|
|
|
adaptiveStream: { pixelDensity: 'screen' },
|
|
|
|
dynacast: true,
|
|
|
|
e2ee:
|
|
|
|
hash && worker
|
|
|
|
? {
|
|
|
|
keyProvider,
|
|
|
|
worker,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const room = useMemo(() => new Room(roomOptions), []);
|
|
|
|
|
2023-03-13 16:46:37 +01:00
|
|
|
if (typeof liveKitUrl !== 'string') {
|
|
|
|
return <h2>Missing LiveKit URL</h2>;
|
|
|
|
}
|
|
|
|
if (typeof token !== 'string') {
|
|
|
|
return <h2>Missing LiveKit token</h2>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<main data-lk-theme="default">
|
|
|
|
{liveKitUrl && (
|
2023-08-30 11:25:22 +02:00
|
|
|
<LiveKitRoom room={room} token={token} serverUrl={liveKitUrl} audio={true} video={true}>
|
2023-03-13 16:46:37 +01:00
|
|
|
<VideoConference chatMessageFormatter={formatChatMessageLinks} />
|
|
|
|
<DebugMode logLevel={LogLevel.info} />
|
|
|
|
</LiveKitRoom>
|
|
|
|
)}
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|