From 809746ac466a0f86b6fb8b779a3292b56589828e Mon Sep 17 00:00:00 2001 From: Lukasz Rutkowski <101095871+lukasz-rutkowski-red@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:20:00 +0200 Subject: [PATCH] Add engines versions to the URL and logic change (#8) * Add engines versions to the URL * Reformat code with Prettier * Update logic for loadStoredEngine() --- README.md | 6 +++--- src/engineChange.js | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 45d8b45..1bb1fb2 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/src/engineChange.js b/src/engineChange.js index 9e4773a..06b445a 100644 --- a/src/engineChange.js +++ b/src/engineChange.js @@ -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"], @@ -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"], @@ -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);