|
|
@@ -104,9 +104,18 @@ function getFileStream(srcUrl, options, cb) {
|
|
|
headers['range'] = 'bytes=' + options.start + '-';
|
|
|
|
|
|
var req = (options.probe ? request.head : request.get)({uri:url.format(srcUrl), pool:false, headers:headers, timeout:60*1000});
|
|
|
- req.on('error', cb);
|
|
|
- req.on('response', function (res) {
|
|
|
- req.removeListener('error', cb);
|
|
|
+ req.on('error', onreqerror);
|
|
|
+ req.on('response', onresponse);
|
|
|
+
|
|
|
+ function onreqerror(err) {
|
|
|
+ req.removeListener('error', onreqerror);
|
|
|
+ req.removeListener('response', onresponse);
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ function onresponse(res) {
|
|
|
+ req.removeListener('error', onreqerror);
|
|
|
+ req.removeListener('response', onresponse);
|
|
|
|
|
|
if (res.statusCode !== 200 && res.statusCode !== 206) {
|
|
|
req.abort();
|
|
|
@@ -164,7 +173,7 @@ function getFileStream(srcUrl, options, cb) {
|
|
|
modified = res.headers['last-modified'] ? new Date(res.headers['last-modified']) : null;
|
|
|
|
|
|
cb(null, stream, {url:url.format(req.uri), mime:mimetype, size:start+size, modified:modified});
|
|
|
- });
|
|
|
+ }
|
|
|
} else {
|
|
|
process.nextTick(function() {
|
|
|
cb(new Error('Unsupported protocol: '+srcUrl.protocol));
|
|
|
@@ -236,7 +245,7 @@ function HlsStreamReader(src, options) {
|
|
|
if (err) {
|
|
|
if (self.index && self.keepConnection) {
|
|
|
console.error('Failed to update index at '+url.format(self.url)+':', err.stack || err);
|
|
|
- return updatecheck();
|
|
|
+ return updatecheck(false);
|
|
|
}
|
|
|
return self.emit('error', err);
|
|
|
}
|
|
|
@@ -248,7 +257,13 @@ function HlsStreamReader(src, options) {
|
|
|
|
|
|
self.baseUrl = meta.url;
|
|
|
m3u8.parse(stream, function(err, index) {
|
|
|
- if (err) return self.emit('error', err);
|
|
|
+ if (err) {
|
|
|
+ if (self.index && self.keepConnection) {
|
|
|
+ console.error('Failed to parse index at '+url.format(self.url)+':', err.stack || err);
|
|
|
+ return updatecheck(false);
|
|
|
+ }
|
|
|
+ return self.emit('error', err);
|
|
|
+ }
|
|
|
|
|
|
var updated = true;
|
|
|
if (self.index && self.index.lastSeqNo() === index.lastSeqNo()) {
|