const app = require ("express")(); const Stream = require("node-rtsp-stream"); const streams = {}; const stream_configs = [{ key:'OGI STREAM', port:9000, url: 'rtsp://192.168.18.248:10100', key2:'OGI STREAM', port2:9010, url2: 'rtsp://192.168.18.248:10600', key3:'OGI STREAM', port3:9020, url3: 'rtsp://192.168.0.143:10600', key4:'OGI STREAM', port4:9030, url4: 'rtsp://192.168.0.143:10700' }]; const startStream = (name,streamUrl,wsPort) =>{ const stream = new Stream({ name, streamUrl, wsPort, ffmpegOptions: { '-stats': "", '-r': 30 }, }); streams[wsPort]=stream; }; app.get("start-stream",(req,res) =>{ const{url,port,key="stream"} = req.query; if (!url && !port){ return res.json({ message:"Bad input", }); } if(streams[port]){ return res.json({ message:"Port is in use", }) } startStream(key,url,port); //streams[port]=stream; res.json({ message:"Started Stream", }); }); app.listen(8080, ()=> { console.log('Server running 8080'); stream_configs.forEach((config)=>{ startStream(config.key,config.url,config.port) startStream(config.key2,config.url2,config.port2) startStream(config.key3,config.url3,config.port3) startStream(config.key4,config.url4,config.port4) }) });