Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming video from HTML5 to node.js

I have a node.js server which uses the "ws" npm package. From HTML5 I can get the users webcam stream but how do I send the webcam stream through a HTML5 websocket to my node.js server?

Currently I have this code on the server:

wss.on('connection', function(ws) {
  ws.on('message', function(data, flags) {
    console.log("Message received");
  });
});

And on the client this code:

var ws = new WebSocket('ws://localhost:8080');

ws.onopen = function() {
  ws.send(stream);
}

Where the stream is from navigator.getUserMedia with video: true.

Thanks in advance!

like image 897
Johan S Avatar asked Dec 07 '13 12:12

Johan S


People also ask

Is node JS suitable for video streaming?

Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.

Can we connect HTML with node js?

Using Clean architecture for Node.So far we sent html code directly from the send(0 function in response object. For sending larger code, we definitely require to have a separate file for html code. Response object gives a sendFile() function to return a html file to client.

How do I stream data in node JS?

Chaining the Streams Chaining is a mechanism to connect the output of one stream to another stream and create a chain of multiple stream operations. It is normally used with piping operations. Now we'll use piping and chaining to first compress a file and then decompress the same. Verify the Output.


1 Answers

I would use the socket.io-stream npm package and then use something like this after configure it (works on server and client):

// send data 
ss(socket).on('file', function(stream) {
  fs.createReadStream('/path/to/file').pipe(stream);
});

// receive data 
ss(socket).emit('file', stream);
stream.pipe(fs.createWriteStream('file.txt'));

from here

like image 116
JoaqiinRA Avatar answered Sep 19 '22 15:09

JoaqiinRA