2018-05-11 12:31:53 +02:00
|
|
|
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,
|
2018-05-12 15:32:00 +02:00
|
|
|
getKey: getKey,
|
2018-05-11 12:31:53 +02:00
|
|
|
loggedIn: loggedIn
|
|
|
|
};
|
|
|
|
|
|
|
|
function is(sessionKey) {
|
|
|
|
return key == sessionKey;
|
|
|
|
}
|
|
|
|
|
2018-05-12 15:32:00 +02:00
|
|
|
function getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2018-05-11 12:31:53 +02:00
|
|
|
function loggedIn() {
|
|
|
|
return name != undefined;
|
|
|
|
}
|
|
|
|
}
|