ICE servers config

Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-06-15 13:07:16 +02:00
padre 69205d212f
commit 7c3921cdd3
Se han modificado 8 ficheros con 219 adiciones y 20 borrados

42
node.js
Ver fichero

@@ -2,6 +2,7 @@
import { RingNode } from './src/ring-node.js';
import chalk from 'chalk';
import { readFileSync } from 'fs';
const args = process.argv.slice(2);
const options = {};
@@ -21,6 +22,26 @@ for (let i = 0; i < args.length; i++) {
case '--position':
options.ringPosition = parseInt(args[++i]);
break;
case '--ice-servers':
try {
options.iceServers = JSON.parse(args[++i]);
} catch (error) {
console.error(chalk.red('Error parsing ICE servers JSON:'), error.message);
process.exit(1);
}
break;
case '--config':
try {
const configPath = args[++i];
const configData = JSON.parse(readFileSync(configPath, 'utf8'));
if (configData.iceServers) {
options.iceServers = configData.iceServers;
}
} catch (error) {
console.error(chalk.red('Error loading config file:'), error.message);
process.exit(1);
}
break;
case '--help':
console.log(`
${chalk.blue('Ring Network Node')}
@@ -28,16 +49,27 @@ ${chalk.blue('Ring Network Node')}
Usage: node node.js [options]
Options:
--port <port> Port to listen on (default: random)
--id <id> Node ID (default: auto-generated)
--bootstrap <addr> Bootstrap node address (host:port)
--position <pos> Initial ring position (default: 0)
--help Show this help message
--port <port> Port to listen on (default: random)
--id <id> Node ID (default: auto-generated)
--bootstrap <addr> Bootstrap node address (host:port)
--position <pos> Initial ring position (default: 0)
--ice-servers <json> ICE servers configuration (JSON array)
--config <file> Load configuration from JSON file
--help Show this help message
Examples:
node node.js --port 8080
node node.js --port 8081 --bootstrap localhost:8080
node node.js --id mynode --port 8082 --bootstrap localhost:8080
node node.js --config config/ice-servers-with-turn.json --port 8080
ICE Servers Example:
--ice-servers '[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:turn.example.com:3478","username":"user","credential":"pass"}]'
Config File Example:
config/ice-servers-default.json - Default STUN servers
config/ice-servers-with-turn.json - With TURN server
config/ice-servers-public-turn.json - Public TURN servers
`);
process.exit(0);
break;