From 0ea6fec5ae8c10937a4c040b0c0f5d49dcb0575f Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 24 Dec 2019 00:43:57 +0100 Subject: [PATCH] Stop handling messages from the room module, expose useful functions and let hall handle (de)connection messages instead --- www/main.js | 2 +- www/room.js | 16 +++------------- www/screen/hall.js | 14 ++++++++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/www/main.js b/www/main.js index 92d7b5b..ca7e067 100644 --- a/www/main.js +++ b/www/main.js @@ -9,7 +9,7 @@ window.addEventListener('load', function() { var messaging = Messaging({screen: screen}); var ui = Ui({messaging: messaging}); var session = Session({messaging: messaging, save: save}); - var room = Room({dom: dom, messaging: messaging, session: session, fun: fun}); + var room = Room({dom: dom, session: session, fun: fun}); var statusHandler = StatusHandler(); var login = Screen.Login({dom: dom, i18n: i18n, messaging: messaging, room: room, save: save, screen: screen, session: session, statusHandler: statusHandler, ui: ui}); var hall = Screen.Hall({dom: dom, i18n: i18n, messaging: messaging, room: room, save: save, screen: screen, session: session, statusHandler: statusHandler, ui: ui}); diff --git a/www/room.js b/www/room.js index d183959..4f5f23e 100644 --- a/www/room.js +++ b/www/room.js @@ -15,24 +15,14 @@ function Room(modules) { selected: null }; - modules.messaging.addEventListener(["Welcome"], populate); - modules.messaging.addEventListener(["Okaeri"], populate); - - modules.messaging.addEventListener(["LogIn"], function(o) { - enter(o.from, o.as); - }); - - modules.messaging.addEventListener(["Relay", "LogOut"], function(o) { - leave(o.from); - }); - var compareKeysByLogin = modules.fun.map(function(key) {return players[key].name;}, modules.fun.defaultCompare); return { filter: filter, - /*enter: enter,*/ + enter: enter, leave: leave, - name: name + name: name, + populate: populate }; function filter(name) { diff --git a/www/screen/hall.js b/www/screen/hall.js index d155689..3d14030 100644 --- a/www/screen/hall.js +++ b/www/screen/hall.js @@ -44,19 +44,25 @@ Screen.Hall = function(modules) { } function initMessageHandlers() { - modules.messaging.addEventListener(["Okaeri"], function() { + modules.messaging.addEventListener(["Okaeri"], function(o) { + modules.room.populate(o); refreshPlayers(); refreshGames(); }); - modules.messaging.addEventListener(["Welcome"], function() { + modules.messaging.addEventListener(["Welcome"], function(o) { + modules.room.populate(o); refreshPlayers(); refreshGames(); }); modules.messaging.addEventListener(["LogIn"], function(o) { - console.log("Someone joined in, they should be added to the lists"); - console.log(o); + modules.room.enter(o.from, o.as); + refreshPlayers(); + }); + + modules.messaging.addEventListener(["LogOut"], function(o) { + modules.room.leave(o.from); refreshPlayers(); });