2020-05-11 14:18:59 +02:00
|
|
|
const config = require("./config/config");
|
2020-05-10 16:43:11 +02:00
|
|
|
|
2020-05-10 15:34:19 +02:00
|
|
|
class WhiteboardServerSideInfo {
|
2020-05-10 16:43:11 +02:00
|
|
|
static defaultScreenResolution = { w: 1000, h: 1000 };
|
|
|
|
|
2020-05-10 15:34:19 +02:00
|
|
|
constructor() {
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._nbConnectedUsers = 0;
|
|
|
|
|
2020-05-10 16:43:11 +02:00
|
|
|
/**
|
|
|
|
* @type {Map<int, {w: number, h: number}>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._screenResolutionByClients = new Map();
|
|
|
|
|
2020-05-10 15:34:19 +02:00
|
|
|
/**
|
|
|
|
* Variable to tell if these info have been sent or not
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this._hasNonSentUpdates = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
incrementNbConnectedUsers() {
|
|
|
|
this._nbConnectedUsers++;
|
|
|
|
this._hasNonSentUpdates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
decrementNbConnectedUsers() {
|
|
|
|
this._nbConnectedUsers--;
|
|
|
|
this._hasNonSentUpdates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasConnectedUser() {
|
|
|
|
return this._nbConnectedUsers > 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:11 +02:00
|
|
|
/**
|
|
|
|
* Store information about the client's screen resolution
|
|
|
|
*
|
|
|
|
* @param {number} clientId
|
|
|
|
* @param {number} w client's width
|
|
|
|
* @param {number} h client's hight
|
|
|
|
*/
|
|
|
|
setScreenResolutionForClient(clientId, { w, h }) {
|
|
|
|
this._screenResolutionByClients.set(clientId, { w, h });
|
|
|
|
this._hasNonSentUpdates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the stored information about the client's screen resoltion
|
|
|
|
* @param clientId
|
|
|
|
*/
|
|
|
|
deleteScreenResolutionOfClient(clientId) {
|
|
|
|
this._screenResolutionByClients.delete(clientId);
|
|
|
|
this._hasNonSentUpdates = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the smallest client's screen size on a whiteboard
|
|
|
|
* @return {{w: number, h: number}}
|
|
|
|
*/
|
|
|
|
getSmallestScreenResolution() {
|
|
|
|
const { _screenResolutionByClients: resolutions } = this;
|
|
|
|
return {
|
|
|
|
w: Math.min(...Array.from(resolutions.values()).map((res) => res.w)),
|
|
|
|
h: Math.min(...Array.from(resolutions.values()).map((res) => res.h)),
|
|
|
|
};
|
2020-05-10 15:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
infoWasSent() {
|
|
|
|
this._hasNonSentUpdates = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldSendInfo() {
|
|
|
|
return this._hasNonSentUpdates;
|
|
|
|
}
|
2020-05-10 16:43:11 +02:00
|
|
|
|
|
|
|
asObject() {
|
|
|
|
const out = {
|
|
|
|
nbConnectedUsers: this._nbConnectedUsers,
|
|
|
|
};
|
|
|
|
|
2020-05-10 22:19:32 +02:00
|
|
|
if (config.frontend.showSmallestScreenIndicator) {
|
2020-05-10 16:43:11 +02:00
|
|
|
out.smallestScreenResolution = this.getSmallestScreenResolution();
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2020-05-10 15:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = WhiteboardServerSideInfo;
|