diff --git a/www/login.js b/www/login.js index b966523..0dcce3e 100644 --- a/www/login.js +++ b/www/login.js @@ -36,7 +36,7 @@ function Login(modules) { function initDOMEvents() { root.addEventListener('submit', function(e) { e.preventDefault(); - if(modules.session.loggedIn()) { + if(modules.session.isLoggedIn()) { modules.messaging.send({tag: "Invitation", to: them}); } else { modules.session.start(root.you.value); @@ -100,7 +100,7 @@ function Login(modules) { function refreshPlayers() { modules.dom.clear(players); - if(modules.session.loggedIn()) { + if(modules.session.isLoggedIn()) { refreshThem(); } else { refreshYou(); @@ -151,7 +151,7 @@ function Login(modules) { } function setMode() { - var loggedIn = modules.session.loggedIn() + var loggedIn = modules.session.isLoggedIn() root.join.disabled = loggedIn; root.invite.disabled = !loggedIn; if(loggedIn) { diff --git a/www/room.js b/www/room.js index cf76190..fa0967d 100644 --- a/www/room.js +++ b/www/room.js @@ -45,7 +45,7 @@ function Room(modules) { }; function filter(name) { - if(modules.session.loggedIn()) { + if(modules.session.isLoggedIn()) { var keep = function(player) { return player.name.match(name) && !modules.session.is(player.key) && player.alone; }; diff --git a/www/session.js b/www/session.js index 7549e9b..5d34933 100644 --- a/www/session.js +++ b/www/session.js @@ -1,9 +1,11 @@ function Session(modules) { var key = null; var name = null; + var loggedIn = false; modules.messaging.addEventListener(["Welcome"], function(o) { key = o.key; + modules.save.set('player.id', key); }); modules.messaging.addEventListener(["Relay", "LogIn"], function(o) { @@ -15,7 +17,8 @@ function Session(modules) { return { is: is, getKey: getKey, - loggedIn: loggedIn + loggedIn: loggedIn, + start: start }; function is(sessionKey) { @@ -26,7 +29,17 @@ function Session(modules) { return key; } - function loggedIn() { - return name != undefined; + function isLoggedIn() { + return loggedIn; + } + + function start(name) { + var myID = modules.save.get('player.id'); + if(myID != undefined) { + modules.messaging.send({tag: 'Tadaima', myID: myID, name: name}); + } else { + modules.messaging.send({tag: 'Hello', name: name}); + } + modules.save.set('player.name', name); } }