From f9804e750fc25bd23f0bedb3319b2c29ae359bca Mon Sep 17 00:00:00 2001 From: Florent Chehab Date: Mon, 11 May 2020 16:00:45 +0200 Subject: [PATCH] feat(config): cleaned & doc --- config.default.yml | 44 +++++++++++++++------ scripts/config/config-schema.json | 8 ++-- scripts/config/config.js | 4 +- scripts/config/utils.js | 4 +- scripts/server-backend.js | 4 +- src/js/services/ConfigService.js | 6 +-- src/js/services/ConfigService.utils.js | 18 ++++----- src/js/services/ConfigService.utils.test.js | 8 ++-- src/js/services/InfoService.js | 2 +- 9 files changed, 59 insertions(+), 39 deletions(-) diff --git a/config.default.yml b/config.default.yml index 9155131..9b6688b 100644 --- a/config.default.yml +++ b/config.default.yml @@ -1,25 +1,45 @@ +# Backend configuration backend: - # TODO + # Access token required for interacting with the server -- string (empty string for no restrictions) accessToken: "" - # TODO - webdav: false + + # Is webdav saving enabled -- boolean + enableWebdav: false + + # Backend performance tweaks performance: - # Whiteboard information broadcasting frequency (in Hz i.e. /s) + # Whiteboard information broadcasting frequency (in Hz i.e. /s) -- number # => diminishing this will result in more latency whiteboardInfoBroadcastFreq: 1 +# Frontend configuration frontend: - # When a whiteboard is loading in a client + # When a whiteboard is loaded on a client onWhiteboardLoad: - # should an (editable) whiteboard be started in read-only mode by default + # should an (editable) whiteboard be started in read-only mode by default -- boolean setReadOnly: false - # should the whiteboard info be displayed by default + + # should the whiteboard info be displayed by default -- boolean displayInfo: false - # Show smallest screen indicator + + # Show the smallest screen indicator ? (with dotted lines) -- boolean showSmallestScreenIndicator: true + + # Frontend performance tweaks performance: - pointerEventsThrottling: - - fromNbUser: 0 - minDistDelta: 1 - maxFreq: 30 + # Refresh frequency of the debug / info div (in Hz i.e. /s) -- number refreshInfoFreq: 5 + + # Throttling of pointer events (except drawing related) -- array of object (one must have fromUserCount == 0) + # Throttling of events can be defined for different user count levels + # Throttling consist of skipping certain events (i.e. not broadcasting them to others) + pointerEventsThrottling: + - # User count from which the specific throttling is applied -- number + fromUserCount: 0 + # Min screen distance (in pixels) below which throttling is applied + minDistDelta: 1 + # Maximum frequency above which throttling is applied + maxFreq: 30 + - fromUserCount: 10 + minDistDelta: 5 + maxFreq: 10 diff --git a/scripts/config/config-schema.json b/scripts/config/config-schema.json index f138966..b482909 100644 --- a/scripts/config/config-schema.json +++ b/scripts/config/config-schema.json @@ -5,13 +5,13 @@ "properties": { "backend": { "type": "object", - "required": ["accessToken", "performance", "webdav"], + "required": ["accessToken", "performance", "enableWebdav"], "additionalProperties": false, "properties": { "accessToken": { "type": "string" }, - "webdav": { + "enableWebdav": { "type": "boolean" }, "performance": { @@ -59,9 +59,9 @@ "items": { "type": "object", "additionalProperties": false, - "required": ["fromNbUser", "minDistDelta", "maxFreq"], + "required": ["fromUserCount", "minDistDelta", "maxFreq"], "properties": { - "fromNbUser": { + "fromUserCount": { "type": "number", "minimum": 0 }, diff --git a/scripts/config/config.js b/scripts/config/config.js index c1f6266..10c9996 100644 --- a/scripts/config/config.js +++ b/scripts/config/config.js @@ -38,7 +38,7 @@ function updateConfigFromStartArgs(startArgs) { "disablesmallestscreen", () => (config.backend.showSmallestScreenIndicator = false) ); - deprecateCliArg("webdav", () => (config.backend.webdav = true)); + deprecateCliArg("webdav", () => (config.backend.enableWebdav = true)); } /** @@ -63,7 +63,7 @@ function updateConfigFromEnv() { "disablesmallestscreen", () => (config.backend.showSmallestScreenIndicator = false) ); - deprecateEnv("webdav", () => (config.backend.webdav = true)); + deprecateEnv("webdav", () => (config.backend.enableWebdav = true)); } // compatibility layer diff --git a/scripts/config/utils.js b/scripts/config/utils.js index e05702f..c44d151 100644 --- a/scripts/config/utils.js +++ b/scripts/config/utils.js @@ -33,7 +33,7 @@ function isConfigValid(config, warn = true) { let structureIsValid = false; try { structureIsValid = config.frontend.performance.pointerEventsThrottling.some( - (item) => item.fromNbUser === 0 + (item) => item.fromUserCount === 0 ); } catch (e) { if (!e instanceof TypeError) { @@ -44,7 +44,7 @@ function isConfigValid(config, warn = true) { if (!structureIsValid && warn) console.warn( "At least one item under frontend.performance.pointerEventsThrottling" + - "must have fromNbUser set to 0" + "must have fromUserCount set to 0" ); return isValidAgainstSchema && structureIsValid; diff --git a/scripts/server-backend.js b/scripts/server-backend.js index 54d14f7..66ae122 100644 --- a/scripts/server-backend.js +++ b/scripts/server-backend.js @@ -25,7 +25,7 @@ function startBackendServer(port) { var io = require("socket.io")(server, { path: "/ws-api" }); console.log("Webserver & socketserver running on port:" + port); - const { accessToken, webdav } = config.backend; + const { accessToken, enableWebdav } = config.backend; app.get("/api/loadwhiteboard", function (req, res) { var wid = req["query"]["wid"]; @@ -117,7 +117,7 @@ function startBackendServer(port) { } else { if (webdavaccess) { //Save image to webdav - if (webdav) { + if (enableWebdav) { saveImageToWebdav( "./public/uploads/" + filename, filename, diff --git a/src/js/services/ConfigService.js b/src/js/services/ConfigService.js index 097bc21..0405f65 100644 --- a/src/js/services/ConfigService.js +++ b/src/js/services/ConfigService.js @@ -66,15 +66,15 @@ class ConfigService { /** * Refresh config that depends on the number of user connected to whiteboard * - * @param {number} nbUser + * @param {number} userCount */ - refreshNbUserDependant(nbUser) { + refreshUserCountDependant(userCount) { const { configFromServer } = this; const { common } = configFromServer; const { performance } = common; const { pointerEventsThrottling } = performance; - this.#pointerEventsThrottling = getThrottling(pointerEventsThrottling, nbUser); + this.#pointerEventsThrottling = getThrottling(pointerEventsThrottling, userCount); } } diff --git a/src/js/services/ConfigService.utils.js b/src/js/services/ConfigService.utils.js index f2111ac..1733880 100644 --- a/src/js/services/ConfigService.utils.js +++ b/src/js/services/ConfigService.utils.js @@ -1,19 +1,19 @@ /** - * Helper to extract the correct correct throttling values based on the config and the number of user + * Helper to extract the correct throttling values based on the config and the number of user * - * @param {Array.<{fromNbUser: number, minDistDelta: number, maxFreq: number}>} pointerEventsThrottling - * @param {number} nbUser + * @param {Array.<{fromUserCount: number, minDistDelta: number, maxFreq: number}>} pointerEventsThrottling + * @param {number} userCount * @return {{minDistDelta: number, minTimeDelta: number}} */ -export function getThrottling(pointerEventsThrottling, nbUser) { +export function getThrottling(pointerEventsThrottling, userCount) { let tmpOut = pointerEventsThrottling[0]; - let lastDistToNbUser = nbUser - tmpOut.fromNbUser; - if (lastDistToNbUser < 0) lastDistToNbUser = Number.MAX_VALUE; + let lastDistToUserCount = userCount - tmpOut.fromUserCount; + if (lastDistToUserCount < 0) lastDistToUserCount = Number.MAX_VALUE; for (const el of pointerEventsThrottling) { - const distToNbUser = nbUser - el.fromNbUser; - if (el.fromNbUser <= nbUser && distToNbUser <= lastDistToNbUser) { + const distToUserCount = userCount - el.fromUserCount; + if (el.fromUserCount <= userCount && distToUserCount <= lastDistToUserCount) { tmpOut = el; - lastDistToNbUser = distToNbUser; + lastDistToUserCount = distToUserCount; } } diff --git a/src/js/services/ConfigService.utils.test.js b/src/js/services/ConfigService.utils.test.js index d60ed41..acb96ca 100644 --- a/src/js/services/ConfigService.utils.test.js +++ b/src/js/services/ConfigService.utils.test.js @@ -1,7 +1,7 @@ import { getThrottling } from "./ConfigService.utils"; test("Simple throttling config", () => { - const throttling = [{ fromNbUser: 0, minDistDelta: 1, maxFreq: 1 }]; + const throttling = [{ fromUserCount: 0, minDistDelta: 1, maxFreq: 1 }]; const target0 = { minDistDelta: 1, minTimeDelta: 1000 }; expect(getThrottling(throttling, 0)).toEqual(target0); @@ -13,9 +13,9 @@ test("Simple throttling config", () => { test("Complex throttling config", () => { // mix ordering const throttling = [ - { fromNbUser: 100, minDistDelta: 100, maxFreq: 1 }, - { fromNbUser: 0, minDistDelta: 1, maxFreq: 1 }, - { fromNbUser: 50, minDistDelta: 50, maxFreq: 1 }, + { fromUserCount: 100, minDistDelta: 100, maxFreq: 1 }, + { fromUserCount: 0, minDistDelta: 1, maxFreq: 1 }, + { fromUserCount: 50, minDistDelta: 50, maxFreq: 1 }, ]; const target0 = { minDistDelta: 1, minTimeDelta: 1000 }; diff --git a/src/js/services/InfoService.js b/src/js/services/InfoService.js index 56176f9..162d6eb 100644 --- a/src/js/services/InfoService.js +++ b/src/js/services/InfoService.js @@ -62,7 +62,7 @@ class InfoService { updateInfoFromServer({ nbConnectedUsers, smallestScreenResolution = undefined }) { if (this.#nbConnectedUsers !== nbConnectedUsers) { // Refresh config service parameters on nb connected user change - ConfigService.refreshNbUserDependant(nbConnectedUsers); + ConfigService.refreshUserCountDependant(nbConnectedUsers); } this.#nbConnectedUsers = nbConnectedUsers; if (smallestScreenResolution) {