Session Manager and Storage Manager Implemented.
This commit is contained in:
1 parent
441c2d1c5b
commit
b7c8d6342a
5 files changed
+241
-111
No files matched your search
@@ -0,0 +1,48 @@
|
||||
exports.newSessionManager = function newSessionManager() {
|
||||
|
||||
let thisObject = {
|
||||
getSession: getSession,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let activeSessions = new Map();
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
|
||||
readSessions();
|
||||
|
||||
function readSessions() {
|
||||
|
||||
try {
|
||||
let fs = require('fs');
|
||||
let filePath = '../' + 'Sessions' + '/' + 'Open.Sessions' + '.json';
|
||||
|
||||
let sessions = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
|
||||
for (let i = 0; i < sessions.lenght; i++) {
|
||||
|
||||
let session = sessions[i];
|
||||
|
||||
activeSessions.set(session.sessionToken, session);
|
||||
|
||||
}
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] readSessions -> err = " + err.message);
|
||||
console.log("[HINT] You need to have a file at this path -> " + filePath);
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSession(pSessionToken) {
|
||||
|
||||
return activeSessions.get(pSessionToken);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user