UNPKG

ernest

Version:

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

71 lines (67 loc) 1.39 kB
const Ernest_Commands = require('./Ernest_Commands'); const SCM = require('./ServerCommunicationModule'); class Ernest_CSI { constructor(ernest,logPath,serverId,serverChannel) { this.ernest = ernest; this.scm = new SCM(serverId,serverChannel); this.socket = null; this.ernestCommand = null; this.msg = ""; this.funct = null; this.loggedOn = false; this.logPath = logPath; }; Start() { var _this = this; this.ernestCommand = new Ernest_Commands(_this.ernest,_this.logPath,function(message,funct) { _this.scm.Send(message,_this.socket); _this.funct = funct; },function(message) { _this.scm.Send(message,_this.socket); }); this.Hook(); this.scm.Start(); }; Hook() { var _this = this; _this.scm.OnData((data,currentSocket) => { _this.socket = currentSocket; if(data == "admin") { _this.loggedOn = true; _this.scm.Send("Welcome Admin \n",currentSocket); _this.ernestCommand.MainMenu(); } else { if(data == "logout") { _this.loggedOn = false; _this.scm.Disconnect(_this.socket); } else { if(!_this.loggedOn) { _this.scm.Send("Not loggin \n",currentSocket); } else { if(typeof _this.funct == 'function') { _this.funct(data); } } } }; }); }; }; module.exports = Ernest_CSI;