diff --git a/lib/getLiveKitURL.test.ts b/lib/getLiveKitURL.test.ts index b8afac7..404cac8 100644 --- a/lib/getLiveKitURL.test.ts +++ b/lib/getLiveKitURL.test.ts @@ -10,7 +10,7 @@ describe('getLiveKitURL', () => { it('inserts the region into livekit.cloud URLs', () => { const url = 'https://myproject.livekit.cloud'; const region = 'eu'; - expect(getLiveKitURL(url, region)).toBe('https://myproject.eu.myproject.livekit.cloud/'); + expect(getLiveKitURL(url, region)).toBe('https://myproject.eu.livekit.cloud/'); }); it('returns the original URL for non-livekit.cloud hosts, even with region', () => { @@ -22,8 +22,6 @@ describe('getLiveKitURL', () => { it('handles URLs with paths and query params', () => { const url = 'https://myproject.livekit.cloud/room?foo=bar'; const region = 'ap'; - expect(getLiveKitURL(url, region)).toBe( - 'https://myproject.ap.myproject.livekit.cloud/room?foo=bar', - ); + expect(getLiveKitURL(url, region)).toBe('https://myproject.ap.livekit.cloud/room?foo=bar'); }); }); diff --git a/lib/getLiveKitURL.ts b/lib/getLiveKitURL.ts index 09f2750..94192de 100644 --- a/lib/getLiveKitURL.ts +++ b/lib/getLiveKitURL.ts @@ -1,8 +1,8 @@ export function getLiveKitURL(projectUrl: string, region: string | null): string { const url = new URL(projectUrl); if (region && url.hostname.includes('livekit.cloud')) { - const hostParts = url.hostname.split('.'); - const regionURL = [hostParts[0], region, ...hostParts].join('.'); + const [projectId, ...hostParts] = url.hostname.split('.'); + const regionURL = [projectId, region, ...hostParts].join('.'); url.hostname = regionURL; } return url.toString();