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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With