Browse Source

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.
pull/80/head
David LaPalomento 12 years ago
parent
commit
651a069828
  1. 2
      src/videojs-hls.js
  2. 25
      test/videojs-hls_test.js

2
src/videojs-hls.js

@ -246,7 +246,7 @@ var
var i, parser, playlist, playlistUri;
if (xhr.readyState === 4) {
if (xhr.status >= 400) {
if (xhr.status >= 400 || this.status === 0) {
player.hls.error = {
status: xhr.status,
message: 'HLS playlist request error at URL: ' + url,

25
test/videojs-hls_test.js

@ -189,6 +189,31 @@ test('re-initializes the plugin for each source', function() {
notStrictEqual(firstInit, secondInit, 'the plugin object is replaced');
});
test('triggers an error when a master playlist request errors', function() {
var
status = 0,
error;
window.XMLHttpRequest = function() {
this.open = function() {};
this.send = function() {
this.readyState = 4;
this.status = status;
this.onreadystatechange();
};
};
player.on('error', function() {
error = player.hls.error;
});
player.hls('manifest/master.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
ok(error, 'an error is triggered');
strictEqual(2, error.code, 'a network error is triggered');
});
test('downloads media playlists after loading the master', function() {
player.hls('manifest/master.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({

Loading…
Cancel
Save