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:
# 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

View File

@ -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
},

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -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);
}
}

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 {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;
}
}

View File

@ -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 };

View File

@ -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) {