9c0cac0e by David LaPalomento

Invert conditional to remove a level of indentation

The segment response callback was getting pretty deeply nested, so invert the readyState check and return early. Also added some comments.
1 parent 225eb805
......@@ -292,11 +292,10 @@ var
// always start playback with the default rendition
if (!player.hls.media) {
player.hls.media = player.hls.master.playlists[0];
if (parser.manifest.totalDuration) {
// update the duration
if (parser.manifest.totalDuration) {
player.duration(parser.manifest.totalDuration);
// Notify the flash layer
//player.el().querySelector('.vjs-tech').vjs_setProperty('duration',parser.manifest.totalDuration);
} else {
player.duration(totalDuration(parser.manifest));
}
......@@ -311,8 +310,9 @@ var
downloadPlaylist(resolveUrl(srcUrl, playlist.uri));
} else {
player.hls.media = playlist;
if (player.hls.media.totalDuration) {
// update the duration
if (player.hls.media.totalDuration) {
player.duration(player.hls.media.totalDuration);
} else {
player.duration(totalDuration(player.hls.media));
......@@ -370,14 +370,8 @@ var
segmentXhr.onreadystatechange = function() {
var playlist;
if (this.readyState === 4) {
if (this.status >= 400) {
player.hls.error = {
status: segmentXhr.status,
message: 'HLS segment request error at URL: ' + segmentUri,
code: (segmentXhr.status >= 500) ? 4 : 2
};
player.trigger('error');
// wait until the request completes
if (this.readyState !== 4) {
return;
}
......@@ -389,6 +383,17 @@ var
return;
}
// trigger an error if the request was not successful
if (this.status >= 400) {
player.hls.error = {
status: segmentXhr.status,
message: 'HLS segment request error at URL: ' + segmentUri,
code: (segmentXhr.status >= 500) ? 4 : 2
};
player.trigger('error');
return;
}
// calculate the download bandwidth
player.hls.segmentXhrTime = (+new Date()) - startTime;
player.hls.bandwidth = (this.response.byteLength / player.hls.segmentXhrTime) * 8 * 1000;
......@@ -415,7 +420,6 @@ var
player.hls.mediaIndex++;
if (player.hls.mediaIndex === player.hls.media.segments.length) {
//TODO - Fix the endofstream //
mediaSource.endOfStream();
return;
}
......@@ -428,7 +432,6 @@ var
} else {
player.hls.media = playlist;
}
}
};
startTime = +new Date();
segmentXhr.send(null);
......