1
0
mirror of synced 2024-11-16 11:03:50 +00:00
SecurityCam.js/basehttpstreamprocessor.js
2016-08-07 11:02:21 +02:00

72 lines
1.1 KiB
JavaScript

var util = require('util');
var http = require('http');
var logger = require('./logger');
var BaseProcessor = require('./baseprocessor');
function BaseHTTPStreamProcessor(camId, cam, now)
{
BaseProcessor.apply(this, arguments);
}
util.inherits(BaseHTTPStreamProcessor, BaseProcessor);
BaseHTTPStreamProcessor.prototype.run = function()
{
var self = this;
var timer = null;
var req = null;
var doCleanup = function()
{
if (timer !== null)
{
clearTimeout(timer);
timer = null;
}
self.cleanup();
self.doEnd();
};
req = http.request(self.cam.options.url, function(res)
{
self.doStart();
timer = setTimeout(function()
{
req.abort();
doCleanup();
}, self.cam.options.time || 10000);
res.on('end', function()
{
doCleanup();
});
res.pipe(self.getStream());
});
req.on('error', function(e)
{
logger.error(e);
doCleanup();
});
req.end();
};
BaseHTTPStreamProcessor.prototype.getStream = function()
{
}
BaseHTTPStreamProcessor.prototype.cleanup = function()
{
}
module.exports = BaseHTTPStreamProcessor;