如何结束永不结束的 request.js ServerResponse 流
How to end a request.js ServerResponse stream that never ends
我有这段代码可以根据命令抓取视频源,但一旦开始就永远不会停止
async function getBandonBeachesOne(req, res, next) {
let timer = 0;
let videoURL =
"http://dizzyisadog.viewnetcam.com:50000/nphMotionJpeg?Resolution=640x480&Quality=Clarity";
let videoStream = request
.get(videoURL)
.on("data", function (data) {
timer++;
if (timer > 30) {
timer = 0;
console.log("received " + data.length + " bytes of compressed data");
}
})
.on("end", () => {
console.log("end");
})
.pipe(res);
req.on("close", () => {
console.log("Client left");
videoStream.end("end");
videoStream.destroy();//data keeps comming from the request.get(videoURL)
});
}
这是一个请求处理程序,它获取视频源并将其通过管道传输到客户端。客户离开后,我收到 "Client left"
消息,但无论我尝试什么,我都无法阻止 on('data')
事件表单永远触发
多亏了这个
我发现解决方案是
videoStream.abort()
我有这段代码可以根据命令抓取视频源,但一旦开始就永远不会停止
async function getBandonBeachesOne(req, res, next) {
let timer = 0;
let videoURL =
"http://dizzyisadog.viewnetcam.com:50000/nphMotionJpeg?Resolution=640x480&Quality=Clarity";
let videoStream = request
.get(videoURL)
.on("data", function (data) {
timer++;
if (timer > 30) {
timer = 0;
console.log("received " + data.length + " bytes of compressed data");
}
})
.on("end", () => {
console.log("end");
})
.pipe(res);
req.on("close", () => {
console.log("Client left");
videoStream.end("end");
videoStream.destroy();//data keeps comming from the request.get(videoURL)
});
}
这是一个请求处理程序,它获取视频源并将其通过管道传输到客户端。客户离开后,我收到 "Client left"
消息,但无论我尝试什么,我都无法阻止 on('data')
事件表单永远触发
多亏了这个videoStream.abort()