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!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.