Skip to content

Commit

Permalink
Add engines versions to the URL and logic change (#8)
Browse files Browse the repository at this point in the history
* Add engines versions to the URL

* Reformat code with Prettier

* Update logic for loadStoredEngine()
  • Loading branch information
lukasz-rutkowski-red authored Jul 5, 2022
1 parent 88db535 commit 809746a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ All interactive elements are navigable via arrow keys and can be selected throug

Test execution can be controlled through URL parameters, e.g. to run `DASH Shaka` tests 1,2,3 on Shaka Player version 2.5.20 use:

http://MVT_INSTANCE_ADDRESS?test_type=dash-shaka-test&tests=1-3&engine_shaka_player=2.5.20
http://MVT_INSTANCE_ADDRESS?test_type=dash-shaka-test&tests=1-3&engine_shaka=2.5.20

Most of the URL parameters can be combined. Here's a full list of supported queries:

Expand All @@ -170,8 +170,8 @@ Most of the URL parameters can be combined. Here's a full list of supported quer
- `loop=false|true`
- `stoponfailure=false|true`
- `disable_log=false|true`
- `engine_shaka_player=2.5.20|3.0.1|3.2.1` - select Shaka Player version. Please note it will only affect Shaka test suites.
- `engine_dashjs_player=2.9.3|3.0.1|latest` - select dash.js version. Please note it will only affect dash.js test suites.
- `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.

### JavaScript API

Expand Down
25 changes: 14 additions & 11 deletions src/engineChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"use strict";

var EngineVersions = {
shaka_player: {
shaka: {
versions: {
"2.5.20": ["https://ajax.googleapis.com/ajax/libs/shaka-player/2.5.20/shaka-player.compiled.js"],
"3.0.1": ["https://ajax.googleapis.com/ajax/libs/shaka-player/3.0.1/shaka-player.compiled.js"],
Expand All @@ -29,7 +29,7 @@ var EngineVersions = {
name: "Shaka Player",
defaultVersion: "3.2.1",
},
dashjs_player: {
dashjs: {
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"],
Expand Down Expand Up @@ -57,15 +57,18 @@ function loadStoredEngine() {
var engine = EngineVersions[engineId];
var queryVariable = getQueryVariable("engine_" + engineId);

if (queryVariable && engine.versions[queryVariable] !== undefined) {
window.localStorage["engine_" + engineId] = queryVariable;
window.location.href = window.location.search.replace("engine_" + engineId + "=" + queryVariable, "");
} else if (window.localStorage["engine_" + engineId] === undefined) {
window.localStorage["engine_" + engineId] = engine.defaultVersion;
} else {
var version = window.localStorage["engine_" + engineId];
if (engine.versions[version] !== undefined) {
engine.defaultVersion = window.localStorage["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;
}
}
console.log("Engine : " + engine.name + " : " + engine.defaultVersion);
Expand Down

0 comments on commit 809746a

Please sign in to comment.