Skip to content

Commit

Permalink
Change the way of loading players engine and default versions (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-rutkowski-red committed Jan 17, 2023
1 parent 41c68cb commit d3a5fcf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ Most of the URL parameters can be combined. Here's a full list of supported quer
- `stoponfailure=false|true` - tests execution will stop on the first failed test.
- `disable_log=false|true` - enable/disable logging.
- `engine_shaka=2.5.20|3.0.1|3.2.1` - select Shaka Player version. Please note it will only affect Shaka test suites.
- `engine_dashjs=2.9.3|3.0.1|latest` - select dash.js version. Please note it will only affect dash.js test suites.
- `engine_dashjs=2.9.3|3.1.1|4.4.0|latest` - select dash.js version. Please note it will only affect dash.js test suites.
- `engine_hlsjs=1.0.0|1.1.5|1.2.1|1.2.9|1.3.0` - select hls.js version. Please note it will only affect hls.js test suites.

### JavaScript API

Expand Down
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
// Do NOT Change order of script sources!
var scriptSources = [
// Required by Shaka Player to support MPEG-2 TS
"https://cdnjs.cloudflare.com/ajax/libs/mux.js/5.10.0/mux.min.js",
"https://cdn.jsdelivr.net/npm/hls.js@1.2.1",
"https://cdnjs.cloudflare.com/ajax/libs/mux.js/6.2.0/mux.min.js",
"src/engineChange.js",
"js_mse_eme/harness/util.js",
"js_mse_eme/harness/constants.js",
"js_mse_eme/harness/key.js",
Expand All @@ -50,7 +50,6 @@
"src/common.js",
"mediaStreams.js",
"src/mvtTest.js",
"src/engineChange.js",
"src/profiles.js",
"src/engines.js",
"src/mediaTests.js",
Expand Down
1 change: 1 addition & 0 deletions mediaStreams.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ var MS = {
audio: {
codec: "aac",
},
unstable: new Unstable("ONEM-28049"),
},
FMP4_AVC_EAC3: {
variant: "hls",
Expand Down
74 changes: 44 additions & 30 deletions src/engineChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ var EngineVersions = {
versions: {
"2.9.3": ["https://cdn.dashjs.org/v2.9.3/dash.all.min.js", "https://cdn.dashjs.org/v2.9.3/dash.mss.min.js"],
"3.1.1": ["https://cdn.dashjs.org/v3.1.1/dash.all.min.js", "https://cdn.dashjs.org/v3.1.1/dash.mss.min.js"],
"4.4.0": ["https://cdn.dashjs.org/v4.4.0/dash.all.min.js", "https://cdn.dashjs.org/v4.4.0/dash.mss.min.js"],
latest: ["https://cdn.dashjs.org/latest/dash.all.min.js", "https://cdn.dashjs.org/latest/dash.mss.min.js"],
},
name: "Dash.JS",
defaultVersion: "latest",
defaultVersion: "4.4.0",
},
hlsjs: {
versions: {
"1.0.0": ["https://cdn.jsdelivr.net/npm/hls.js@1.0.0"],
"1.1.5": ["https://cdn.jsdelivr.net/npm/hls.js@1.1.5"],
"1.2.1": ["https://cdn.jsdelivr.net/npm/hls.js@1.2.1"],
"1.2.9": ["https://cdn.jsdelivr.net/npm/hls.js@1.2.9"],
"1.3.0": ["https://cdn.jsdelivr.net/npm/hls.js@1.3.0"],
},
name: "HLS.js",
defaultVersion: "1.3.0",
},
};

Expand All @@ -54,38 +66,40 @@ function getQueryVariable(variable) {

function loadStoredEngine() {
for (var engineId in EngineVersions) {
var engine = EngineVersions[engineId];
var queryVariable = getQueryVariable("engine_" + engineId);
if (window.location.search.includes(engineId)) {
var engine = EngineVersions[engineId];
var queryVariable = getQueryVariable("engine_" + engineId);

if (queryVariable) {
// if engine version is provided but it does not exist in 'EngineVersions', replace it to the default value:
if (engine.versions[queryVariable] === undefined) {
console.warn(
`${engineId} player version '${queryVariable}' is not available, it has been set to default: '${engine.defaultVersion}'`
);
window.history.pushState("", "", window.location.search.replace(`&engine_${engineId}=${queryVariable}`, ""));
// remove version parameter from the url if the provided version is the default one:
} else if (queryVariable === engine.defaultVersion) {
window.history.pushState("", "", window.location.search.replace(`&engine_${engineId}=${queryVariable}`, ""));
} else {
engine.defaultVersion = queryVariable;
if (queryVariable) {
// if engine version is provided but it does not exist in 'EngineVersions', replace it to the default value:
if (engine.versions[queryVariable] === undefined) {
console.warn(
`${engineId} player version '${queryVariable}' is not available, it has been set to default: '${engine.defaultVersion}'`
);
window.history.pushState("", "", window.location.search.replace(`&engine_${engineId}=${queryVariable}`, ""));
// remove version parameter from the url if the provided version is the default one:
} else if (queryVariable === engine.defaultVersion) {
window.history.pushState("", "", window.location.search.replace(`&engine_${engineId}=${queryVariable}`, ""));
} else {
engine.defaultVersion = queryVariable;
}
}
}
console.log("Engine : " + engine.name + " : " + engine.defaultVersion);
console.log("Engine : " + engine.name + " : " + engine.defaultVersion);

var scriptSources = engine.versions[engine.defaultVersion];
(function loadNextScript() {
if (scriptSources.length) {
var script = document.createElement("script");
script.src = scriptSources[0];
script.async = script.defer = true;
script.onload = function () {
scriptSources.shift();
loadNextScript();
};
document.head.appendChild(script);
}
})();
var scriptSources = engine.versions[engine.defaultVersion];
(function loadNextScript() {
if (scriptSources.length) {
var script = document.createElement("script");
script.src = scriptSources[0];
script.async = script.defer = true;
script.onload = function () {
scriptSources.shift();
loadNextScript();
};
document.head.appendChild(script);
}
})();
}
}
}

Expand Down

0 comments on commit d3a5fcf

Please sign in to comment.