Stop handling messages from the room module, expose useful functions and let hall handle (de)connection messages instead

This commit is contained in:
Tissevert 2019-12-24 00:43:57 +01:00
parent dc920bd80b
commit 0ea6fec5ae
3 changed files with 14 additions and 18 deletions

View file

@ -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});

View file

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

View file

@ -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();
});