-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (39 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var EventEmitter = require('events.js');
var mage = require('mage-sdk-js');
exports = module.exports = new EventEmitter();
var sessionKey;
var actorId;
function commandHook() {
return { key: sessionKey };
}
// Some day, we'll need to deprecate actorId from this module.
// It's the login system that needs to provide an actor ID, not the session system
exports.getActorId = function () {
return actorId;
};
exports.setActorId = function (id) {
actorId = id;
};
exports.getKey = function () {
return sessionKey;
};
exports.setKey = function (key) {
if (key === sessionKey) {
// no change
return;
}
sessionKey = key;
if (key) {
mage.commandCenter.registerCommandHook('mage.session', commandHook);
} else {
mage.commandCenter.unregisterCommandHook('mage.session');
}
};
mage.eventManager.on('session.set', function (path, info) {
exports.setActorId(info.actorId);
exports.setKey(info.key);
});
mage.eventManager.on('session.unset', function () {
exports.setActorId(null);
exports.setKey(null);
});