a5ab53ec by David LaPalomento Committed by brandonocasey

Style fixes and restoring some command ordering

The refactor should not have changed the required ordering for statements so restore it. Adjust styles a tad.
1 parent 99580d5c
......@@ -91,7 +91,7 @@ Hls.findSoleUncommonTimeRangesEnd_ = function(original, update) {
/**
* Whether the browser has built-in HLS support.
*/
Hls.supportsNativeHls = function() {
Hls.supportsNativeHls = (function() {
let video = document.createElement('video');
let xMpegUrl;
let vndMpeg;
......@@ -105,7 +105,7 @@ Hls.supportsNativeHls = function() {
vndMpeg = video.canPlayType('application/vnd.apple.mpegURL');
return (/probably|maybe/).test(xMpegUrl) ||
(/probably|maybe/).test(vndMpeg);
};
}());
// HLS is a source handler, not a tech. Make sure attempts to use it
// as one do not cause exceptions.
......@@ -717,6 +717,7 @@ export default class HlsHandler extends Component {
let variant;
let bandwidthBestVariant;
let resolutionPlusOne;
let resolutionPlusOneAttribute;
let resolutionBestVariant;
let width;
let height;
......@@ -725,9 +726,9 @@ export default class HlsHandler extends Component {
// filter out any playlists that have been excluded due to
// incompatible configurations or playback errors
sortedPlaylists = sortedPlaylists.filter((localvariant) => {
if (typeof localvariant.excludeUntil !== 'undefined') {
return now >= localvariant.excludeUntil;
sortedPlaylists = sortedPlaylists.filter((localVariant) => {
if (typeof localVariant.excludeUntil !== 'undefined') {
return now >= localVariant.excludeUntil;
}
return true;
});
......@@ -785,21 +786,22 @@ export default class HlsHandler extends Component {
// since the playlists are sorted, the first variant that has
// dimensions less than or equal to the player size is the best
if (variant.attributes.RESOLUTION.width === width &&
variant.attributes.RESOLUTION.height === height) {
let variantResolution = variant.attributes.RESOLUTION;
if (variantResolution.width === width &&
variantResolution.height === height) {
// if we have the exact resolution as the player use it
resolutionPlusOne = null;
resolutionBestVariant = variant;
break;
} else if (variant.attributes.RESOLUTION.width < width &&
variant.attributes.RESOLUTION.height < height) {
} else if (variantResolution.width < width &&
variantResolution.height < height) {
// if both dimensions are less than the player use the
// previous (next-largest) variant
break;
} else if (!resolutionPlusOne || (variant.attributes.RESOLUTION.width <
resolutionPlusOne.attributes.RESOLUTION.width &&
variant.attributes.RESOLUTION.height <
resolutionPlusOne.attributes.RESOLUTION.height)) {
} else if (!resolutionPlusOne ||
(variantResolution.width < resolutionPlusOneAttribute.width &&
variantResolution.height < resolutionPlusOneAttribute.height)) {
// If we still haven't found a good match keep a
// reference to the previous variant for the next loop
// iteration
......@@ -809,6 +811,7 @@ export default class HlsHandler extends Component {
// the highest bandwidth variant that is just-larger-than
// the video player
resolutionPlusOne = variant;
resolutionPlusOneAttribute = resolutionPlusOneAttribute.attributes.RESOLUTION;
}
}
......@@ -930,12 +933,13 @@ export default class HlsHandler extends Component {
// we have entered a state where we are fetching the same segment,
// try to walk forward
/* eslint-disable max-len */
if (this.lastSegmentLoaded_ &&
this.playlistUriToUrl(this.lastSegmentLoaded_.uri) ===
this.playlistUriToUrl(segment.uri) &&
this.playlistUriToUrl(this.lastSegmentLoaded_.uri) === this.playlistUriToUrl(segment.uri) &&
this.lastSegmentLoaded_.byterange === segment.byterange) {
return this.fillBuffer(mediaIndex + 1);
}
/* eslint-enable max-len */
// package up all the work to append the segment
segmentInfo = {
......@@ -1236,9 +1240,9 @@ export default class HlsHandler extends Component {
decrypter = new Hls.Decrypter(segmentInfo.encryptedBytes,
segment.key.bytes,
segIv,
function(err, localBytes) {
if (err) {
throw new Error(err);
function(error, localBytes) {
if (error) {
videojs.log.warn(error);
}
segmentInfo.bytes = localBytes;
});
......@@ -1415,10 +1419,10 @@ export default class HlsHandler extends Component {
* @return a new TimeRanges object.
*/
HlsHandler.prototype.findBufferedRange_ =
filterBufferedRanges(function(start, end, time) {
return start - TIME_FUDGE_FACTOR <= time &&
end + TIME_FUDGE_FACTOR >= time;
});
filterBufferedRanges(function(start, end, time) {
return start - TIME_FUDGE_FACTOR <= time &&
end + TIME_FUDGE_FACTOR >= time;
});
/**
* Returns the TimeRanges that begin at or later than the specified
* time.
......@@ -1427,9 +1431,9 @@ filterBufferedRanges(function(start, end, time) {
* @return a new TimeRanges object.
*/
HlsHandler.prototype.findNextBufferedRange_ =
filterBufferedRanges(function(start, end, time) {
return start - TIME_FUDGE_FACTOR >= time;
});
filterBufferedRanges(function(start, end, time) {
return start - TIME_FUDGE_FACTOR >= time;
});
/**
* The Source Handler object, which informs video.js what additional
......@@ -1468,7 +1472,7 @@ HlsSourceHandler.canPlayType = function(type) {
let mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
// favor native HLS support if it's available
if (Hls.supportsNativeHls()) {
if (Hls.supportsNativeHls) {
return false;
}
return mpegurlRE.test(type);
......