651a0698 by David LaPalomento

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.
1 parent c7ea123a
......@@ -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,
......
......@@ -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({
......