2016-08-07 12:58:20 +00:00
|
|
|
"use strict";
|
|
|
|
const plugins = require("./smartsocket.plugins");
|
2016-08-07 16:59:39 +00:00
|
|
|
const helpers = require("./smartsocket.helpers");
|
2016-08-07 12:58:20 +00:00
|
|
|
// classes
|
|
|
|
const lik_1 = require("lik");
|
|
|
|
;
|
2016-08-07 16:59:39 +00:00
|
|
|
;
|
2016-08-07 12:58:20 +00:00
|
|
|
class Smartsocket {
|
2016-08-07 16:59:39 +00:00
|
|
|
constructor(optionsArg) {
|
2016-08-07 12:58:20 +00:00
|
|
|
this.openSockets = new lik_1.Objectmap();
|
2016-08-07 16:59:39 +00:00
|
|
|
this.registeredRoles = new lik_1.Objectmap();
|
|
|
|
/**
|
|
|
|
* starts listening to incling sockets:
|
|
|
|
*/
|
|
|
|
this.startServer = () => {
|
|
|
|
this.io = plugins.socketIo(this.options.port);
|
|
|
|
this.io.on('connection', (socketArg) => {
|
|
|
|
this._handleSocket(socketArg);
|
|
|
|
});
|
|
|
|
};
|
2016-08-07 12:58:20 +00:00
|
|
|
this.closeServer = () => {
|
|
|
|
this.openSockets.forEach((socketObjectArg) => {
|
2016-08-07 16:59:39 +00:00
|
|
|
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
|
2016-08-07 12:58:20 +00:00
|
|
|
socketObjectArg.socket.disconnect();
|
|
|
|
});
|
|
|
|
this.openSockets.wipe();
|
2016-08-07 16:59:39 +00:00
|
|
|
this.io.close();
|
2016-08-07 12:58:20 +00:00
|
|
|
};
|
2016-08-07 16:59:39 +00:00
|
|
|
this.options = optionsArg;
|
2016-08-07 12:58:20 +00:00
|
|
|
}
|
|
|
|
;
|
2016-08-07 16:59:39 +00:00
|
|
|
/**
|
|
|
|
* the standard handler for new socket connections
|
|
|
|
*/
|
|
|
|
_handleSocket(socket) {
|
|
|
|
let socketObject = {
|
|
|
|
socket: socket,
|
|
|
|
authenticated: false
|
|
|
|
};
|
|
|
|
plugins.beautylog.log("Socket connected. Trying to authenticate...");
|
|
|
|
this.openSockets.add(socketObject);
|
|
|
|
helpers.authenticateSocket(socketObject)
|
|
|
|
.then();
|
|
|
|
}
|
|
|
|
registerFunctions(socketRoleArg) {
|
|
|
|
this.registeredRoles.add(socketRoleArg);
|
2016-08-07 12:58:20 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
}
|
|
|
|
exports.Smartsocket = Smartsocket;
|
2016-08-07 16:59:39 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFDakQsTUFBWSxPQUFPLFdBQU0sdUJBQXVCLENBQUMsQ0FBQTtBQUVqRCxVQUFVO0FBQ1Ysc0JBQTBCLEtBQUssQ0FBQyxDQUFBO0FBVS9CLENBQUM7QUFLRCxDQUFDO0FBRUY7SUFLSSxZQUFZLFVBQTBDO1FBRnRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQUUsQ0FBQztRQUM5QixvQkFBZSxHQUFHLElBQUksZUFBUyxFQUFFLENBQUM7UUF3QmxDOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLFlBQVksRUFBRSxDQUFDLFNBQVM7Z0JBQy9CLElBQUksQ0FBQyxhQUFhLENBQUMsU0FBUyxDQUFDLENBQUM7WUFDbEMsQ0FBQ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