beginning admin api

This commit is contained in:
AlecM33
2022-07-04 15:08:47 -04:00
parent f57cbc44bd
commit 3796aab81b
13 changed files with 166 additions and 28 deletions

View File

@@ -199,12 +199,7 @@ class GameManager {
checkAvailability = (code) => {
const game = this.activeGameRunner.activeGames[code.toUpperCase()];
if (game) {
const unassignedPerson = game.people.find((person) => person.assigned === false);
if (!unassignedPerson) {
return Promise.resolve(new Error(globals.ERROR_MESSAGE.GAME_IS_FULL));
} else {
return Promise.resolve({ accessCode: code, playerCount: getGameSize(game.deck), timerParams: game.timerParams });
}
return Promise.resolve({ accessCode: code, playerCount: getGameSize(game.deck), timerParams: game.timerParams });
} else {
return Promise.resolve(404);
}

View File

@@ -0,0 +1,27 @@
const globals = require('../config/globals.js');
class SocketManager {
constructor (logger, io) {
this.logger = logger;
this.io = io;
}
broadcast = (message) => {
this.io.emit(globals.EVENTS.BROADCAST, message);
};
}
class Singleton {
constructor (logger, io) {
if (!Singleton.instance) {
logger.info('CREATING SINGLETON SOCKET MANAGER');
Singleton.instance = new SocketManager(logger, io);
}
}
getInstance () {
return Singleton.instance;
}
}
module.exports = Singleton;