refacto(backend): real private read-only fields
* Just like in the backend thanks to node 12
This commit is contained in:
parent
25bcdee083
commit
0240171d0e
@ -6,40 +6,47 @@ const config = require("./config/config");
|
|||||||
class WhiteboardServerSideInfo {
|
class WhiteboardServerSideInfo {
|
||||||
static defaultScreenResolution = { w: 1000, h: 1000 };
|
static defaultScreenResolution = { w: 1000, h: 1000 };
|
||||||
|
|
||||||
constructor() {
|
/**
|
||||||
/**
|
* @type {number}
|
||||||
* @type {number}
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
#nbConnectedUsers = 0;
|
||||||
this._nbConnectedUsers = 0;
|
get nbConnectedUsers() {
|
||||||
|
return this.#nbConnectedUsers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Map<int, {w: number, h: number}>}
|
* @type {Map<int, {w: number, h: number}>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._screenResolutionByClients = new Map();
|
#screenResolutionByClients = new Map();
|
||||||
|
get screenResolutionByClients() {
|
||||||
|
return this.#screenResolutionByClients;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable to tell if these info have been sent or not
|
* Variable to tell if these info have been sent or not
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this._hasNonSentUpdates = false;
|
#hasNonSentUpdates = false;
|
||||||
|
get hasNonSentUpdates() {
|
||||||
|
return this.#hasNonSentUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementNbConnectedUsers() {
|
incrementNbConnectedUsers() {
|
||||||
this._nbConnectedUsers++;
|
this.#nbConnectedUsers++;
|
||||||
this._hasNonSentUpdates = true;
|
this.#hasNonSentUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
decrementNbConnectedUsers() {
|
decrementNbConnectedUsers() {
|
||||||
this._nbConnectedUsers--;
|
this.#nbConnectedUsers--;
|
||||||
this._hasNonSentUpdates = true;
|
this.#hasNonSentUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConnectedUser() {
|
hasConnectedUser() {
|
||||||
return this._nbConnectedUsers > 0;
|
return this.#nbConnectedUsers > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,8 +57,8 @@ class WhiteboardServerSideInfo {
|
|||||||
* @param {number} h client's hight
|
* @param {number} h client's hight
|
||||||
*/
|
*/
|
||||||
setScreenResolutionForClient(clientId, { w, h }) {
|
setScreenResolutionForClient(clientId, { w, h }) {
|
||||||
this._screenResolutionByClients.set(clientId, { w, h });
|
this.#screenResolutionByClients.set(clientId, { w, h });
|
||||||
this._hasNonSentUpdates = true;
|
this.#hasNonSentUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,8 +66,8 @@ class WhiteboardServerSideInfo {
|
|||||||
* @param clientId
|
* @param clientId
|
||||||
*/
|
*/
|
||||||
deleteScreenResolutionOfClient(clientId) {
|
deleteScreenResolutionOfClient(clientId) {
|
||||||
this._screenResolutionByClients.delete(clientId);
|
this.#screenResolutionByClients.delete(clientId);
|
||||||
this._hasNonSentUpdates = true;
|
this.#hasNonSentUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +75,7 @@ class WhiteboardServerSideInfo {
|
|||||||
* @return {{w: number, h: number}}
|
* @return {{w: number, h: number}}
|
||||||
*/
|
*/
|
||||||
getSmallestScreenResolution() {
|
getSmallestScreenResolution() {
|
||||||
const { _screenResolutionByClients: resolutions } = this;
|
const { screenResolutionByClients: resolutions } = this;
|
||||||
return {
|
return {
|
||||||
w: Math.min(...Array.from(resolutions.values()).map((res) => res.w)),
|
w: Math.min(...Array.from(resolutions.values()).map((res) => res.w)),
|
||||||
h: Math.min(...Array.from(resolutions.values()).map((res) => res.h)),
|
h: Math.min(...Array.from(resolutions.values()).map((res) => res.h)),
|
||||||
@ -76,16 +83,16 @@ class WhiteboardServerSideInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
infoWasSent() {
|
infoWasSent() {
|
||||||
this._hasNonSentUpdates = false;
|
this.#hasNonSentUpdates = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldSendInfo() {
|
shouldSendInfo() {
|
||||||
return this._hasNonSentUpdates;
|
return this.#hasNonSentUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
asObject() {
|
asObject() {
|
||||||
const out = {
|
const out = {
|
||||||
nbConnectedUsers: this._nbConnectedUsers,
|
nbConnectedUsers: this.#nbConnectedUsers,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.frontend.showSmallestScreenIndicator) {
|
if (config.frontend.showSmallestScreenIndicator) {
|
||||||
|
Loading…
Reference in New Issue
Block a user