d7381365 by David LaPalomento

Merge pull request #151 from amfr/fix_timeouts

Fix timeouts
2 parents 5662e402 e64ce8ac
...@@ -42,20 +42,12 @@ ...@@ -42,20 +42,12 @@
42 request.withCredentials = true; 42 request.withCredentials = true;
43 } 43 }
44 if (options.timeout) { 44 if (options.timeout) {
45 if (request.timeout === 0) { 45 abortTimeout = window.setTimeout(function() {
46 request.timeout = options.timeout; 46 if (request.readyState !== 4) {
47 request.ontimeout = function() {
48 request.timedout = true; 47 request.timedout = true;
49 }; 48 request.abort();
50 } else { 49 }
51 // polyfill XHR2 by aborting after the timeout 50 }, options.timeout);
52 abortTimeout = window.setTimeout(function() {
53 if (request.readyState !== 4) {
54 request.timedout = true;
55 request.abort();
56 }
57 }, options.timeout);
58 }
59 } 51 }
60 52
61 request.onreadystatechange = function() { 53 request.onreadystatechange = function() {
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
58 <script src="m3u8_test.js"></script> 58 <script src="m3u8_test.js"></script>
59 <script src="playlist-loader_test.js"></script> 59 <script src="playlist-loader_test.js"></script>
60 <script src="decrypter_test.js"></script> 60 <script src="decrypter_test.js"></script>
61 <script src="xhr_test.js"></script>
61 </head> 62 </head>
62 <body> 63 <body>
63 <div id="qunit"></div> 64 <div id="qunit"></div>
......
1 (function(window, videojs, undefined) {
2 'use strict';
3
4 /*
5 XHR test suite
6 */
7
8 var xhr;
9
10 module('XHR', {
11 setup: function() {
12 xhr = sinon.useFakeXMLHttpRequest();
13 },
14
15 teardown: function() {
16 xhr.restore();
17 }
18 });
19
20 test('handles xhr timeouts correctly', function () {
21 var error;
22 var clock = sinon.useFakeTimers();
23 videojs.Hls.xhr({
24 url: 'http://example.com',
25 timeout: 1
26 }, function(innerError) {
27 error = innerError;
28 });
29 clock.tick(1);
30 strictEqual(error, 'timeout', 'called with timeout error');
31 clock.restore();
32 });
33
34 })(window, window.videojs);