feat(streaming): add local TURN relay support
This commit is contained in:
5
WebApp/.env.example
Normal file
5
WebApp/.env.example
Normal file
@@ -0,0 +1,5 @@
|
||||
VITE_BACKEND_URL=http://localhost:3000
|
||||
VITE_STUN_URLS=stun:stun.l.google.com:19302
|
||||
VITE_TURN_URLS=turn:localhost:3478?transport=udp,turn:localhost:3478?transport=tcp
|
||||
VITE_TURN_USERNAME=securecam
|
||||
VITE_TURN_CREDENTIAL=securecamturn
|
||||
@@ -76,8 +76,36 @@ const SOCKET_HEARTBEAT_INTERVAL_MS = 10_000;
|
||||
const MAX_STREAM_DIAGNOSTIC_SESSIONS = 12;
|
||||
const MAX_STREAM_DIAGNOSTIC_ENTRIES = 24;
|
||||
|
||||
const parseRtcUrls = (value = '') =>
|
||||
value
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const buildIceServers = () => {
|
||||
const stunUrls = parseRtcUrls(import.meta.env.VITE_STUN_URLS ?? 'stun:stun.l.google.com:19302');
|
||||
const turnUrls = parseRtcUrls(import.meta.env.VITE_TURN_URLS ?? '');
|
||||
const turnUsername = (import.meta.env.VITE_TURN_USERNAME ?? '').trim();
|
||||
const turnCredential = (import.meta.env.VITE_TURN_CREDENTIAL ?? '').trim();
|
||||
const iceServers = [];
|
||||
|
||||
if (stunUrls.length > 0) {
|
||||
iceServers.push({ urls: stunUrls });
|
||||
}
|
||||
|
||||
if (turnUrls.length > 0) {
|
||||
iceServers.push({
|
||||
urls: turnUrls,
|
||||
username: turnUsername,
|
||||
credential: turnCredential
|
||||
});
|
||||
}
|
||||
|
||||
return iceServers.length > 0 ? iceServers : [{ urls: 'stun:stun.l.google.com:19302' }];
|
||||
};
|
||||
|
||||
const rtcConfig = {
|
||||
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
|
||||
iceServers: buildIceServers()
|
||||
};
|
||||
|
||||
let initialized = false;
|
||||
|
||||
Reference in New Issue
Block a user