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?
我有一个node.js服务器,它使用“ws”npm包。从HTML5我可以获得用户网络摄像头流,但如何通过HTML5 websocket将网络摄像头流发送到我的node.js服务器?
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
.
流来自navigator.getUserMedia的视频:true。
Thanks in advance!
提前致谢!
1 个解决方案
#1
1
I would use the socket.io-stream
npm package and then use something like this after configure it (works on server and client):
我会使用socket.io-stream npm包,然后在配置它之后使用这样的东西(适用于服务器和客户端):
// 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
从这里
#1
1
I would use the socket.io-stream
npm package and then use something like this after configure it (works on server and client):
我会使用socket.io-stream npm包,然后在配置它之后使用这样的东西(适用于服务器和客户端):
// 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
从这里