在linux上使用Motion,每个网络摄像头都在其自己的端口上作为流提供服务。 我现在想要使用Node.js提供所有在同一端口上的流。通过Node.js代理管理MJPEG流
- 编辑:此解决方案现在工作。我需要得到从原来的MJPEG流的边界线(这是“BoundaryString”在我的运动配置)
app.get('/motion', function(req, res) {
var boundary = "BoundaryString";
var options = {
// host to forward to
host: '192.168.1.2',
// port to forward to
port: 8302,
// path to forward to
path: '/',
// request method
method: 'GET',
// headers to send
headers: req.headers
};
var creq = http.request(options, function(cres) {
res.setHeader('Content-Type', 'multipart/x-mixed-replace;boundary="' + boundary + '"');
res.setHeader('Connection', 'close');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Cache-Control', 'no-cache, private');
res.setHeader('Expires', 0);
res.setHeader('Max-Age', 0);
// wait for data
cres.on('data', function(chunk){
res.write(chunk);
});
cres.on('close', function(){
// closed, let's end client request as well
res.writeHead(cres.statusCode);
res.end();
});
}).on('error', function(e) {
// we got an error, return 500 error to client and log error
console.log(e.message);
res.writeHead(500);
res.end();
});
creq.end();
});
我认为这在192.168.1.2:8302 MJPEG编码流提供了AS /运动,但事实并非如此。 也许因为它永远不会结束,而这个代理例子并不是真正的流式例子吗?
你可以看看使用nginx代替。 – david
它需要成为一个节点解决方案 – skerit