-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PUBLIC_SIGNALING_URL="ws://localhost:8000/signaling" | ||
METERED_API_KEY="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { METERED_API_KEY } from '$env/static/private' | ||
import { PUBLIC_SIGNALING_URL } from '$env/static/public' | ||
|
||
import type { LayoutServerLoad } from './$types'; | ||
|
||
export interface IceServer { | ||
urls: string | string[]; | ||
username?: string; | ||
credential?: string; | ||
} | ||
|
||
export interface Config { | ||
iceServers: IceServer[]; | ||
signaling: string[]; | ||
} | ||
|
||
const fetchIceServers = async (fetch: typeof globalThis.fetch): Promise<IceServer[]> => { | ||
try { | ||
if (!METERED_API_KEY) { | ||
throw new Error('METERED_API_KEY is not set'); | ||
} | ||
const response = await fetch(`https://sobaka.metered.live/api/v1/turn/credentials?apiKey=${METERED_API_KEY}`); | ||
|
||
if (response.ok) { | ||
const data = await response.json(); | ||
return data; | ||
} | ||
} catch { | ||
// Fallback to static configuration in case of error or timeout | ||
} | ||
|
||
return [ | ||
{ | ||
urls: [ | ||
'stun:stun.l.google.com:19302', | ||
'stun:global.stun.twilio.com:3478', | ||
], | ||
}, | ||
]; | ||
}; | ||
|
||
export const load: LayoutServerLoad = async ({ fetch }): Promise<{ config: Config }> => { | ||
return { | ||
config: { | ||
iceServers: await fetchIceServers(fetch), | ||
signaling: [PUBLIC_SIGNALING_URL], | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const ssr = false | ||
export const prerender = true; | ||
export const ssr = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const ssr = false | ||
export const prerender = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters