feat(config): cleaned & doc

This commit is contained in:
Florent Chehab
2020-05-11 16:00:45 +02:00
parent dbc7e8c2f9
commit f9804e750f
9 changed files with 59 additions and 39 deletions

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