d7381365 by David LaPalomento

Merge pull request #151 from amfr/fix_timeouts

Fix timeouts
2 parents 5662e402 e64ce8ac
......@@ -42,20 +42,12 @@
request.withCredentials = true;
}
if (options.timeout) {
if (request.timeout === 0) {
request.timeout = options.timeout;
request.ontimeout = function() {
abortTimeout = window.setTimeout(function() {
if (request.readyState !== 4) {
request.timedout = true;
};
} else {
// polyfill XHR2 by aborting after the timeout
abortTimeout = window.setTimeout(function() {
if (request.readyState !== 4) {
request.timedout = true;
request.abort();
}
}, options.timeout);
}
request.abort();
}
}, options.timeout);
}
request.onreadystatechange = function() {
......
......@@ -58,6 +58,7 @@
<script src="m3u8_test.js"></script>
<script src="playlist-loader_test.js"></script>
<script src="decrypter_test.js"></script>
<script src="xhr_test.js"></script>
</head>
<body>
<div id="qunit"></div>
......
(function(window, videojs, undefined) {
'use strict';
/*
XHR test suite
*/
var xhr;
module('XHR', {
setup: function() {
xhr = sinon.useFakeXMLHttpRequest();
},
teardown: function() {
xhr.restore();
}
});
test('handles xhr timeouts correctly', function () {
var error;
var clock = sinon.useFakeTimers();
videojs.Hls.xhr({
url: 'http://example.com',
timeout: 1
}, function(innerError) {
error = innerError;
});
clock.tick(1);
strictEqual(error, 'timeout', 'called with timeout error');
clock.restore();
});
})(window, window.videojs);