From afb781a15635d48fc2a575ba518ca0ff35176b57 Mon Sep 17 00:00:00 2001 From: Trey Hayden Date: Mon, 20 May 2024 21:33:34 -0400 Subject: [PATCH] adding xAPI version to cts/player --- cts/docker-compose.yml | 1 + cts/service/index.js | 2 +- cts/service/plugins/routes/v1/sessions.js | 7 +++++++ player/docker-compose.yml | 1 + player/service/plugins/routes/lrs.js | 8 +++++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cts/docker-compose.yml b/cts/docker-compose.yml index 6794bcc..f9337dd 100644 --- a/cts/docker-compose.yml +++ b/cts/docker-compose.yml @@ -70,6 +70,7 @@ services: - LRS_ENDPOINT - LRS_USERNAME - LRS_PASSWORD + - LRS_XAPI_VERSION networks: - public diff --git a/cts/service/index.js b/cts/service/index.js index fab5a02..7ede030 100644 --- a/cts/service/index.js +++ b/cts/service/index.js @@ -117,7 +117,7 @@ const provision = async () => { (req) => ({ baseUrl: LRS_ENDPOINT.endsWith("/") ? LRS_ENDPOINT : LRS_ENDPOINT + "/", headers: { - "X-Experience-API-Version": "1.0.3", + "X-Experience-API-Version": (process.env.LRS_XAPI_VERSION || "1.0.3"), Authorization: `Basic ${Buffer.from(`${LRS_USERNAME}:${LRS_PASSWORD}`).toString("base64")}` }, json: true diff --git a/cts/service/plugins/routes/v1/sessions.js b/cts/service/plugins/routes/v1/sessions.js index 9143209..3982b29 100644 --- a/cts/service/plugins/routes/v1/sessions.js +++ b/cts/service/plugins/routes/v1/sessions.js @@ -496,6 +496,13 @@ module.exports = { options.headers["x-forwarded-host"] = options.headers["x-forwarded-host"] || req.info.host; } + // The cmi5 JS stuff won't know what the configured LRS's xAPI version is + // between 1.0.3 and 2.0, so replace that here if it was specified. + // + let configuredXAPIVersion = process.env.LRS_XAPI_VERSION; + if (configuredXAPIVersion != undefined) + options.headers["x-experience-api-version"] = configuredXAPIVersion; + // Concurrency check required or xAPI 2.0 // if (req.method == "post" || req.method == "put") { diff --git a/player/docker-compose.yml b/player/docker-compose.yml index f6fb7c0..c5232cf 100644 --- a/player/docker-compose.yml +++ b/player/docker-compose.yml @@ -35,6 +35,7 @@ services: - LRS_ENDPOINT - LRS_USERNAME - LRS_PASSWORD + - LRS_XAPI_VERSIONs - DATABASE_USER=catapult - DATABASE_USER_PASSWORD=quartz - DATABASE_NAME=catapult_player diff --git a/player/service/plugins/routes/lrs.js b/player/service/plugins/routes/lrs.js index c90a844..4d334b9 100644 --- a/player/service/plugins/routes/lrs.js +++ b/player/service/plugins/routes/lrs.js @@ -736,7 +736,13 @@ module.exports = { options.headers["x-forwarded-host"] = options.headers["x-forwarded-host"] || req.info.host; } - // console.error(uri, options); + + // The cmi5 JS stuff won't know what the configured LRS's xAPI version is + // between 1.0.3 and 2.0, so replace that here if it was specified. + // + let configuredXAPIVersion = process.env.LRS_XAPI_VERSION; + if (configuredXAPIVersion != undefined) + options.headers["x-experience-api-version"] = configuredXAPIVersion; let lrsResourcePath = req.params.resource;