Проверка

This commit is contained in:
Халимов Рустам
2026-03-11 16:31:32 +03:00
parent 926482861f
commit 0f89b21dd4
3 changed files with 34 additions and 18 deletions

View File

@@ -120,16 +120,28 @@ app.get('/api/ice-servers', authenticateToken, (_req: AuthRequest, res) => {
const iceServers: Array<{ urls: string | string[]; username?: string; credential?: string }> = [];
// STUN серверы
if (config.stunUrls.length > 0) {
iceServers.push({ urls: config.stunUrls });
const stunUrls = [...config.stunUrls];
// Добавляем ваш VPS и как STUN тоже (раз он работает)
if (config.turnUrl) {
const vpsStun = config.turnUrl.replace('turn:', 'stun:');
if (!stunUrls.includes(vpsStun)) stunUrls.push(vpsStun);
}
if (stunUrls.length > 0) {
iceServers.push({ urls: stunUrls });
}
// TURN сервер (динамическая или статическая аутентификация)
if (config.turnUrl) {
const urls = config.turnUrl.split(',').map(s => s.trim());
if (config.turnSecret) {
// Динамический пароль (HMAC-SHA1)
if (config.turnUsername && config.turnPassword) {
iceServers.push({
urls: urls,
username: config.turnUsername,
credential: config.turnPassword,
});
} else if (config.turnSecret) {
const ttl = 48 * 3600;
const timestamp = Math.floor(Date.now() / 1000) + ttl;
const username = `${timestamp}:vortex`;
@@ -143,13 +155,6 @@ app.get('/api/ice-servers', authenticateToken, (_req: AuthRequest, res) => {
username,
credential,
});
} else if (config.turnUsername && config.turnPassword) {
// Статичный логин/пароль
iceServers.push({
urls: urls,
username: config.turnUsername,
credential: config.turnPassword,
});
}
}