Files
pollets/server.js
Carlos Narro 2ae32f8914 Init commit
2026-03-17 17:22:25 +01:00

102 lines
3.0 KiB
JavaScript

const NodeMediaServer = require('node-media-server');
const express = require('express');
const path = require('path');
// Configuración del servidor RTMP
const config = {
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
http: {
port: 8000,
mediaroot: './media',
allow_origin: '*'
},
trans: {
ffmpeg: 'ffmpeg',
tasks: [
{
app: 'live',
hls: true,
hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
hlsKeep: false,
dash: true,
dashFlags: '[f=dash:window_size=3:extra_window_size=5]',
dashKeep: false
}
]
}
};
// Servidor de medios RTMP
const nms = new NodeMediaServer(config);
nms.on('preConnect', (id, args) => {
console.log('[NodeEvent on preConnect]', `id=${id} args=${JSON.stringify(args)}`);
});
nms.on('postConnect', (id, args) => {
console.log('[NodeEvent on postConnect]', `id=${id} args=${JSON.stringify(args)}`);
});
nms.on('doneConnect', (id, args) => {
console.log('[NodeEvent on doneConnect]', `id=${id} args=${JSON.stringify(args)}`);
});
nms.on('prePublish', (id, StreamPath, args) => {
console.log('[NodeEvent on prePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('postPublish', (id, StreamPath, args) => {
console.log('[NodeEvent on postPublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('donePublish', (id, StreamPath, args) => {
console.log('[NodeEvent on donePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('prePlay', (id, StreamPath, args) => {
console.log('[NodeEvent on prePlay]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('postPlay', (id, StreamPath, args) => {
console.log('[NodeEvent on postPlay]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.on('donePlay', (id, StreamPath, args) => {
console.log('[NodeEvent on donePlay]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nms.run();
// Servidor web Express para la página
const app = express();
const WEB_PORT = 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.listen(WEB_PORT, () => {
console.log('='.repeat(50));
console.log('🐔 POLLETS STREAMING SERVER');
console.log('='.repeat(50));
console.log(`📺 Web del stream: http://localhost:${WEB_PORT}`);
console.log(`📡 Servidor RTMP: rtmp://localhost:1935/live`);
console.log(`🎬 Stream HTTP-FLV: http://localhost:8000/live/CLAVE.flv`);
console.log('='.repeat(50));
console.log('');
console.log('📋 CONFIGURACIÓN PARA OBS:');
console.log(' Servidor: rtmp://localhost/live');
console.log(' Clave de retransmisión: pollets');
console.log('');
console.log(' (Para producción usar: rtmp://pollets.com.es/live)');
console.log('='.repeat(50));
});