feat(config): cleaned & doc

This commit is contained in:
Florent Chehab 2020-05-11 16:00:45 +02:00
parent dbc7e8c2f9
commit f9804e750f
No known key found for this signature in database
GPG Key ID: 9A0CE018889EA246
9 changed files with 59 additions and 39 deletions

View File

@ -1,25 +1,45 @@
# Backend configuration
backend: backend:
# TODO # Access token required for interacting with the server -- string (empty string for no restrictions)
accessToken: "" accessToken: ""
# TODO
webdav: false # Is webdav saving enabled -- boolean
enableWebdav: false
# Backend performance tweaks
performance: 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 # => diminishing this will result in more latency
whiteboardInfoBroadcastFreq: 1 whiteboardInfoBroadcastFreq: 1
# Frontend configuration
frontend: frontend:
# When a whiteboard is loading in a client # When a whiteboard is loaded on a client
onWhiteboardLoad: 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 setReadOnly: false
# should the whiteboard info be displayed by default
# should the whiteboard info be displayed by default -- boolean
displayInfo: false displayInfo: false
# Show smallest screen indicator
# Show the smallest screen indicator ? (with dotted lines) -- boolean
showSmallestScreenIndicator: true showSmallestScreenIndicator: true
# Frontend performance tweaks
performance: performance:
pointerEventsThrottling: # Refresh frequency of the debug / info div (in Hz i.e. /s) -- number
- fromNbUser: 0
minDistDelta: 1
maxFreq: 30
refreshInfoFreq: 5 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

View File

@ -5,13 +5,13 @@
"properties": { "properties": {
"backend": { "backend": {
"type": "object", "type": "object",
"required": ["accessToken", "performance", "webdav"], "required": ["accessToken", "performance", "enableWebdav"],
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"accessToken": { "accessToken": {
"type": "string" "type": "string"
}, },
"webdav": { "enableWebdav": {
"type": "boolean" "type": "boolean"
}, },
"performance": { "performance": {
@ -59,9 +59,9 @@
"items": { "items": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": ["fromNbUser", "minDistDelta", "maxFreq"], "required": ["fromUserCount", "minDistDelta", "maxFreq"],
"properties": { "properties": {
"fromNbUser": { "fromUserCount": {
"type": "number", "type": "number",
"minimum": 0 "minimum": 0
}, },

View File

@ -38,7 +38,7 @@ function updateConfigFromStartArgs(startArgs) {
"disablesmallestscreen", "disablesmallestscreen",
() => (config.backend.showSmallestScreenIndicator = false) () => (config.backend.showSmallestScreenIndicator = false)
); );
deprecateCliArg("webdav", () => (config.backend.webdav = true)); deprecateCliArg("webdav", () => (config.backend.enableWebdav = true));
} }
/** /**
@ -63,7 +63,7 @@ function updateConfigFromEnv() {
"disablesmallestscreen", "disablesmallestscreen",
() => (config.backend.showSmallestScreenIndicator = false) () => (config.backend.showSmallestScreenIndicator = false)
); );
deprecateEnv("webdav", () => (config.backend.webdav = true)); deprecateEnv("webdav", () => (config.backend.enableWebdav = true));
} }
// compatibility layer // compatibility layer

View File

@ -33,7 +33,7 @@ function isConfigValid(config, warn = true) {
let structureIsValid = false; let structureIsValid = false;
try { try {
structureIsValid = config.frontend.performance.pointerEventsThrottling.some( structureIsValid = config.frontend.performance.pointerEventsThrottling.some(
(item) => item.fromNbUser === 0 (item) => item.fromUserCount === 0
); );
} catch (e) { } catch (e) {
if (!e instanceof TypeError) { if (!e instanceof TypeError) {
@ -44,7 +44,7 @@ function isConfigValid(config, warn = true) {
if (!structureIsValid && warn) if (!structureIsValid && warn)
console.warn( console.warn(
"At least one item under frontend.performance.pointerEventsThrottling" + "At least one item under frontend.performance.pointerEventsThrottling" +
"must have fromNbUser set to 0" "must have fromUserCount set to 0"
); );
return isValidAgainstSchema && structureIsValid; return isValidAgainstSchema && structureIsValid;

View File

@ -25,7 +25,7 @@ function startBackendServer(port) {
var io = require("socket.io")(server, { path: "/ws-api" }); var io = require("socket.io")(server, { path: "/ws-api" });
console.log("Webserver & socketserver running on port:" + port); 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) { app.get("/api/loadwhiteboard", function (req, res) {
var wid = req["query"]["wid"]; var wid = req["query"]["wid"];
@ -117,7 +117,7 @@ function startBackendServer(port) {
} else { } else {
if (webdavaccess) { if (webdavaccess) {
//Save image to webdav //Save image to webdav
if (webdav) { if (enableWebdav) {
saveImageToWebdav( saveImageToWebdav(
"./public/uploads/" + filename, "./public/uploads/" + filename,
filename, filename,

View File

@ -66,15 +66,15 @@ class ConfigService {
/** /**
* Refresh config that depends on the number of user connected to whiteboard * 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 { configFromServer } = this;
const { common } = configFromServer; const { common } = configFromServer;
const { performance } = common; const { performance } = common;
const { pointerEventsThrottling } = performance; const { pointerEventsThrottling } = performance;
this.#pointerEventsThrottling = getThrottling(pointerEventsThrottling, nbUser); this.#pointerEventsThrottling = getThrottling(pointerEventsThrottling, userCount);
} }
} }

View File

@ -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 {Array.<{fromUserCount: number, minDistDelta: number, maxFreq: number}>} pointerEventsThrottling
* @param {number} nbUser * @param {number} userCount
* @return {{minDistDelta: number, minTimeDelta: number}} * @return {{minDistDelta: number, minTimeDelta: number}}
*/ */
export function getThrottling(pointerEventsThrottling, nbUser) { export function getThrottling(pointerEventsThrottling, userCount) {
let tmpOut = pointerEventsThrottling[0]; let tmpOut = pointerEventsThrottling[0];
let lastDistToNbUser = nbUser - tmpOut.fromNbUser; let lastDistToUserCount = userCount - tmpOut.fromUserCount;
if (lastDistToNbUser < 0) lastDistToNbUser = Number.MAX_VALUE; if (lastDistToUserCount < 0) lastDistToUserCount = Number.MAX_VALUE;
for (const el of pointerEventsThrottling) { for (const el of pointerEventsThrottling) {
const distToNbUser = nbUser - el.fromNbUser; const distToUserCount = userCount - el.fromUserCount;
if (el.fromNbUser <= nbUser && distToNbUser <= lastDistToNbUser) { if (el.fromUserCount <= userCount && distToUserCount <= lastDistToUserCount) {
tmpOut = el; tmpOut = el;
lastDistToNbUser = distToNbUser; lastDistToUserCount = distToUserCount;
} }
} }

View File

@ -1,7 +1,7 @@
import { getThrottling } from "./ConfigService.utils"; import { getThrottling } from "./ConfigService.utils";
test("Simple throttling config", () => { 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 }; const target0 = { minDistDelta: 1, minTimeDelta: 1000 };
expect(getThrottling(throttling, 0)).toEqual(target0); expect(getThrottling(throttling, 0)).toEqual(target0);
@ -13,9 +13,9 @@ test("Simple throttling config", () => {
test("Complex throttling config", () => { test("Complex throttling config", () => {
// mix ordering // mix ordering
const throttling = [ const throttling = [
{ fromNbUser: 100, minDistDelta: 100, maxFreq: 1 }, { fromUserCount: 100, minDistDelta: 100, maxFreq: 1 },
{ fromNbUser: 0, minDistDelta: 1, maxFreq: 1 }, { fromUserCount: 0, minDistDelta: 1, maxFreq: 1 },
{ fromNbUser: 50, minDistDelta: 50, maxFreq: 1 }, { fromUserCount: 50, minDistDelta: 50, maxFreq: 1 },
]; ];
const target0 = { minDistDelta: 1, minTimeDelta: 1000 }; const target0 = { minDistDelta: 1, minTimeDelta: 1000 };

View File

@ -62,7 +62,7 @@ class InfoService {
updateInfoFromServer({ nbConnectedUsers, smallestScreenResolution = undefined }) { updateInfoFromServer({ nbConnectedUsers, smallestScreenResolution = undefined }) {
if (this.#nbConnectedUsers !== nbConnectedUsers) { if (this.#nbConnectedUsers !== nbConnectedUsers) {
// Refresh config service parameters on nb connected user change // Refresh config service parameters on nb connected user change
ConfigService.refreshNbUserDependant(nbConnectedUsers); ConfigService.refreshUserCountDependant(nbConnectedUsers);
} }
this.#nbConnectedUsers = nbConnectedUsers; this.#nbConnectedUsers = nbConnectedUsers;
if (smallestScreenResolution) { if (smallestScreenResolution) {