function Session(modules) { var key = null; var name = null; modules.messaging.addEventListener(["Welcome"], function(o) { key = o.key; }); modules.messaging.addEventListener(["Relay", "LogIn"], function(o) { if(is(o.from)) { name = o.message.name; } }); return { is: is, getKey: getKey, loggedIn: loggedIn }; function is(sessionKey) { return key == sessionKey; } function getKey() { return key; } function loggedIn() { return name != undefined; } }