Trigger an error when playlist request fail with status zero
When CORS headers aren't enabled on a server, XHRs fail with status 0. Handle this case when downloading playlists and abort further processing. Ideally, we would ignore this for variant playlists if we have alternatives but I'm not tackling that yet.
Showing
2 changed files
with
26 additions
and
1 deletions
... | @@ -246,7 +246,7 @@ var | ... | @@ -246,7 +246,7 @@ var |
246 | var i, parser, playlist, playlistUri; | 246 | var i, parser, playlist, playlistUri; |
247 | 247 | ||
248 | if (xhr.readyState === 4) { | 248 | if (xhr.readyState === 4) { |
249 | if (xhr.status >= 400) { | 249 | if (xhr.status >= 400 || this.status === 0) { |
250 | player.hls.error = { | 250 | player.hls.error = { |
251 | status: xhr.status, | 251 | status: xhr.status, |
252 | message: 'HLS playlist request error at URL: ' + url, | 252 | message: 'HLS playlist request error at URL: ' + url, | ... | ... |
... | @@ -189,6 +189,31 @@ test('re-initializes the plugin for each source', function() { | ... | @@ -189,6 +189,31 @@ test('re-initializes the plugin for each source', function() { |
189 | notStrictEqual(firstInit, secondInit, 'the plugin object is replaced'); | 189 | notStrictEqual(firstInit, secondInit, 'the plugin object is replaced'); |
190 | }); | 190 | }); |
191 | 191 | ||
192 | test('triggers an error when a master playlist request errors', function() { | ||
193 | var | ||
194 | status = 0, | ||
195 | error; | ||
196 | window.XMLHttpRequest = function() { | ||
197 | this.open = function() {}; | ||
198 | this.send = function() { | ||
199 | this.readyState = 4; | ||
200 | this.status = status; | ||
201 | this.onreadystatechange(); | ||
202 | }; | ||
203 | }; | ||
204 | |||
205 | player.on('error', function() { | ||
206 | error = player.hls.error; | ||
207 | }); | ||
208 | player.hls('manifest/master.m3u8'); | ||
209 | videojs.mediaSources[player.currentSrc()].trigger({ | ||
210 | type: 'sourceopen' | ||
211 | }); | ||
212 | |||
213 | ok(error, 'an error is triggered'); | ||
214 | strictEqual(2, error.code, 'a network error is triggered'); | ||
215 | }); | ||
216 | |||
192 | test('downloads media playlists after loading the master', function() { | 217 | test('downloads media playlists after loading the master', function() { |
193 | player.hls('manifest/master.m3u8'); | 218 | player.hls('manifest/master.m3u8'); |
194 | videojs.mediaSources[player.currentSrc()].trigger({ | 219 | videojs.mediaSources[player.currentSrc()].trigger({ | ... | ... |
-
Please register or sign in to post a comment