Skip to content

Commit

Permalink
fix: use URL to add searchParams for LLHLS (#1199)
Browse files Browse the repository at this point in the history
This commits also forces LLHLS to off for IE 11 to prevent it breaking on features that it doesn't support.
  • Loading branch information
brandonocasey authored Sep 15, 2021
1 parent 1517386 commit a8d3c1a
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 408 deletions.
37 changes: 27 additions & 10 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {getKnownPartCount} from './playlist.js';
const { mergeOptions, EventTarget } = videojs;

const addLLHLSQueryDirectives = (uri, media) => {
if (media.endList) {
if (media.endList || !media.serverControl) {
return uri;
}
const query = [];

if (media.serverControl && media.serverControl.canBlockReload) {
const parameters = {};

if (media.serverControl.canBlockReload) {
const {preloadSegment} = media;
// next msn is a zero based value, length is not.
let nextMSN = media.mediaSequence + media.segments.length;
Expand All @@ -44,7 +45,8 @@ const addLLHLSQueryDirectives = (uri, media) => {
// and we need to add the _HLS_part= query
if (nextPart > -1 && nextPart !== (parts.length - 1)) {
// add existing parts to our preload hints
query.push(`_HLS_part=${nextPart}`);
// eslint-disable-next-line
parameters._HLS_part = nextPart;
}

// this if statement makes sure that we request the msn
Expand All @@ -62,19 +64,29 @@ const addLLHLSQueryDirectives = (uri, media) => {
}

// add _HLS_msn= in front of any _HLS_part query
query.unshift(`_HLS_msn=${nextMSN}`);
// eslint-disable-next-line
parameters._HLS_msn = nextMSN;
}

if (media.serverControl && media.serverControl.canSkipUntil) {
// add _HLS_skip= infront of all other queries.
query.unshift('_HLS_skip=' + (media.serverControl.canSkipDateranges ? 'v2' : 'YES'));
// eslint-disable-next-line
parameters._HLS_skip = (media.serverControl.canSkipDateranges ? 'v2' : 'YES');
}

query.forEach(function(str, i) {
const symbol = i === 0 ? '?' : '&';
if (Object.keys(parameters).length) {
const parsedUri = new window.URL(uri);

uri += `${symbol}${str}`;
});
['_HLS_skip', '_HLS_msn', '_HLS_part'].forEach(function(name) {
if (!parameters.hasOwnProperty(name)) {
return;
}

parsedUri.searchParams.set(name, parameters[name]);
});

uri = parsedUri.toString();
}

return uri;
};
Expand Down Expand Up @@ -385,6 +397,11 @@ export default class PlaylistLoader extends EventTarget {
this.customTagMappers = (vhsOptions && vhsOptions.customTagMappers) || [];
this.experimentalLLHLS = (vhsOptions && vhsOptions.experimentalLLHLS) || false;

// force experimentalLLHLS for IE 11
if (videojs.browser.IE_VERSION) {
this.experimentalLLHLS = false;
}

// initialize the loader state
this.state = 'HAVE_NOTHING';

Expand Down
Loading

0 comments on commit a8d3c1a

Please sign in to comment.