From d86f357f561e132e9498c457607c7004bfd2ad3e Mon Sep 17 00:00:00 2001 From: lukasIO Date: Wed, 18 Jun 2025 16:57:48 +0200 Subject: [PATCH] fix staging/prod --- lib/getLiveKitURL.test.ts | 12 ++++++++++-- lib/getLiveKitURL.ts | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/getLiveKitURL.test.ts b/lib/getLiveKitURL.test.ts index 404cac8..68dc9ea 100644 --- a/lib/getLiveKitURL.test.ts +++ b/lib/getLiveKitURL.test.ts @@ -10,7 +10,13 @@ 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.livekit.cloud/'); + expect(getLiveKitURL(url, region)).toBe('https://myproject.eu.production.livekit.cloud/'); + }); + + it('inserts the region into livekit.cloud URLs and preserves the staging environment', () => { + const url = 'https://myproject.staging.livekit.cloud'; + const region = 'eu'; + expect(getLiveKitURL(url, region)).toBe('https://myproject.eu.staging.livekit.cloud/'); }); it('returns the original URL for non-livekit.cloud hosts, even with region', () => { @@ -22,6 +28,8 @@ 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.livekit.cloud/room?foo=bar'); + expect(getLiveKitURL(url, region)).toBe( + 'https://myproject.ap.production.livekit.cloud/room?foo=bar', + ); }); }); diff --git a/lib/getLiveKitURL.ts b/lib/getLiveKitURL.ts index 94192de..9634eba 100644 --- a/lib/getLiveKitURL.ts +++ b/lib/getLiveKitURL.ts @@ -1,7 +1,10 @@ export function getLiveKitURL(projectUrl: string, region: string | null): string { const url = new URL(projectUrl); if (region && url.hostname.includes('livekit.cloud')) { - const [projectId, ...hostParts] = url.hostname.split('.'); + let [projectId, ...hostParts] = url.hostname.split('.'); + if (hostParts[0] !== 'staging') { + hostParts = ['production', ...hostParts]; + } const regionURL = [projectId, region, ...hostParts].join('.'); url.hostname = regionURL; }