Merge pull request #151 from amfr/fix_timeouts
Fix timeouts
Showing
3 changed files
with
35 additions
and
8 deletions
... | @@ -42,13 +42,6 @@ | ... | @@ -42,13 +42,6 @@ |
42 | request.withCredentials = true; | 42 | request.withCredentials = true; |
43 | } | 43 | } |
44 | if (options.timeout) { | 44 | if (options.timeout) { |
45 | if (request.timeout === 0) { | ||
46 | request.timeout = options.timeout; | ||
47 | request.ontimeout = function() { | ||
48 | request.timedout = true; | ||
49 | }; | ||
50 | } else { | ||
51 | // polyfill XHR2 by aborting after the timeout | ||
52 | abortTimeout = window.setTimeout(function() { | 45 | abortTimeout = window.setTimeout(function() { |
53 | if (request.readyState !== 4) { | 46 | if (request.readyState !== 4) { |
54 | request.timedout = true; | 47 | request.timedout = true; |
... | @@ -56,7 +49,6 @@ | ... | @@ -56,7 +49,6 @@ |
56 | } | 49 | } |
57 | }, options.timeout); | 50 | }, options.timeout); |
58 | } | 51 | } |
59 | } | ||
60 | 52 | ||
61 | request.onreadystatechange = function() { | 53 | request.onreadystatechange = function() { |
62 | // wait until the request completes | 54 | // wait until the request completes | ... | ... |
... | @@ -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> | ... | ... |
test/xhr_test.js
0 → 100644
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); |
-
Please register or sign in to post a comment