import Messaging; import Session; import Table; var players = Table.make(function(o) {return o.value}); initMessageHandlers(); return { player: player, players: players }; function player(key) { return {id: key, name: players.get(key)}; } function initMessageHandlers() { Messaging.addEventListener(["Okaeri"], function(o) { players.insertAll(o.room); }); Messaging.addEventListener(["Welcome"], function(o) { players.insertAll(o.room); }); Messaging.addEventListener(["LogIn"], function(o) { if(!Session.is(o.from)) { players.insert(o.from, o.as); } }); Messaging.addEventListener(["LogOut"], function(o) { players.remove(o.from); }); }