Stream from netcat to front-end

I am trying to get this config for video transmission:

Raspberry Pi => Node.js server => Browsers

      

The main advantage is that there can be multiple browsers and the Raspberry Pi does not overload. Now, I have worked so far for video streaming:

Raspberry Pi => Linux laptop

      

With these commands:

// [first] Computer: listen to video and play it with mplayer
nc -l 2222 | mplayer -fps 200 -demuxer h264es -

// [second] Raspberry Pi (emit video to the IP)
raspivid -t 0 -w 300 -h 300 -hf -fps 20 -o - | nc 192.168.1.44 2222

      

I am trying to replace the computer side first. I got this code:

const NetcatServer = require('netcat/server');
const nc = new NetcatServer();
const stream = nc.port(2222).k().listen();
stream.pipe(process.stdout);  // ~ correct

      

However, if I try to listen stream

with an event data

like this:

let i = 0;
stream.on('data', () => {
  i++;
  console.log(i);
});

      

With this, the on('data', ...)

thread runs for 20-25 events and then stops (something that didn't happen from stdout). So my questions are:

  • How do I move this thread from frontend to frontend? (given that it "ends".

Note. I check the event end

, error

, finish

and destroy

, but none of them does not run during the streaming. They are just stops.

+3


source to share





All Articles