fix: détection automatique IP réseau pour connexions multi-appareils

Problème :
Le serveur retournait ws://localhost:7880 aux clients, empêchant
les connexions depuis d'autres appareils sur le réseau.

Solution :
- Ajout détection automatique IP réseau (WiFi/Ethernet)
- Variable LIVEKIT_URL=AUTO pour mode auto-détection
- Fonction getNetworkIP() avec priorité interfaces (en0, en1, eth0, wlan0)
- Affichage IP détectée au démarrage du serveur
- Fallback vers localhost si IP non détectée

Modifications :
- server/index.js : ajout getNetworkIP() et détection AUTO
- server/.env : LIVEKIT_URL=AUTO par défaut
- server/.env.example : documentation modes configuration
- NETWORK_SETUP.md : guide complet configuration réseau et dépannage

Les clients reçoivent maintenant ws://IP_RESEAU:7880 et peuvent
se connecter depuis n'importe quel appareil sur le même réseau WiFi.

Ports utilisés :
- 3000 : API REST
- 7880 : LiveKit WebSocket
- 7882 : LiveKit UDP (RTP)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-05-22 22:27:34 +02:00
parent efd697a9d3
commit 24edf36d3c
3 changed files with 217 additions and 3 deletions
+57 -1
View File
@@ -6,6 +6,7 @@ import { spawn } from 'child_process';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { networkInterfaces } from 'os';
import YAML from 'yaml';
import { AccessToken } from 'livekit-server-sdk';
@@ -16,14 +17,61 @@ const configPath = join(__dirname, 'config', 'config.yaml');
const configFile = readFileSync(configPath, 'utf8');
const config = YAML.parse(configFile);
/**
* Détecte l'IP réseau locale (WiFi/Ethernet)
* @returns {string|null} IP réseau ou null si non trouvée
*/
function getNetworkIP() {
const nets = networkInterfaces();
// Priorité : WiFi (en0 sur macOS) > Ethernet (en1)
const priorityInterfaces = ['en0', 'en1', 'eth0', 'wlan0'];
for (const interfaceName of priorityInterfaces) {
const interfaces = nets[interfaceName];
if (interfaces) {
for (const net of interfaces) {
// IPv4, non-interne
if (net.family === 'IPv4' && !net.internal) {
return net.address;
}
}
}
}
// Fallback : première IP non-interne trouvée
for (const name of Object.keys(nets)) {
for (const net of nets[name]) {
if (net.family === 'IPv4' && !net.internal) {
return net.address;
}
}
}
return null;
}
// Variables d'environnement
const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY || 'devkey';
const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || 'secret';
const LIVEKIT_URL = process.env.LIVEKIT_URL || config.server.livekit.url;
const USE_LOCAL_LIVEKIT = process.env.USE_LOCAL_LIVEKIT === 'true';
const SERVER_PORT = parseInt(process.env.PORT || config.server.port, 10);
const SERVER_HOST = config.server.host;
// Configuration URL LiveKit
let LIVEKIT_URL = process.env.LIVEKIT_URL || config.server.livekit.url;
// AUTO : détection automatique de l'IP réseau
if (LIVEKIT_URL === 'AUTO') {
const networkIP = getNetworkIP();
if (networkIP) {
LIVEKIT_URL = `ws://${networkIP}:7880`;
} else {
console.warn('⚠️ IP réseau non détectée, utilisation de localhost');
LIVEKIT_URL = 'ws://localhost:7880';
}
}
// Logging
const LOG_LEVEL = config.logging.level;
@@ -253,6 +301,14 @@ async function start() {
log('info', 'Phase 1 - MVP');
log('info', '');
// Affichage configuration réseau
const networkIP = getNetworkIP();
if (networkIP) {
log('info', `📡 IP réseau détectée : ${networkIP}`);
}
log('info', `🔗 URL LiveKit clients : ${LIVEKIT_URL}`);
log('info', '');
// 1. Démarrer LiveKit (si mode local)
if (USE_LOCAL_LIVEKIT) {
await startLiveKitServer();