2022-10-24 17:03:12 +02:00
|
|
|
import { RoomServiceClient } from 'livekit-server-sdk';
|
|
|
|
|
|
|
|
export function getRoomClient(): RoomServiceClient {
|
|
|
|
checkKeys();
|
|
|
|
return new RoomServiceClient(getLiveKitURL());
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getLiveKitURL(region?: string): string {
|
2023-01-19 19:56:00 +01:00
|
|
|
let targetKey = 'NEXT_PUBLIC_LK_SERVER_URL';
|
2022-10-24 17:03:12 +02:00
|
|
|
if (region) {
|
2023-01-19 19:56:00 +01:00
|
|
|
targetKey = `NEXT_PUBLIC_LK_SERVER_URL${region}`.toUpperCase();
|
2022-10-24 17:03:12 +02:00
|
|
|
}
|
|
|
|
const url = process.env[targetKey];
|
|
|
|
if (!url) {
|
|
|
|
throw new Error(`${targetKey} is not defined`);
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkKeys() {
|
|
|
|
if (typeof process.env.LIVEKIT_API_KEY === 'undefined') {
|
|
|
|
throw new Error('LIVEKIT_API_KEY is not defined');
|
|
|
|
}
|
|
|
|
if (typeof process.env.LIVEKIT_API_SECRET === 'undefined') {
|
|
|
|
throw new Error('LIVEKIT_API_SECRET is not defined');
|
|
|
|
}
|
|
|
|
}
|