smartsocket/dist/smartsocket.classes.smartsocket.js

46 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-08-07 12:58:20 +00:00
"use strict";
const plugins = require("./smartsocket.plugins");
// classes
const lik_1 = require("lik");
2016-08-08 16:20:00 +00:00
const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
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
/**
* 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
*/
2016-08-08 16:20:00 +00:00
_handleSocket(socketArg) {
let socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
authenticated: false,
socket: socketArg
});
2016-08-07 16:59:39 +00:00
plugins.beautylog.log("Socket connected. Trying to authenticate...");
2016-08-08 16:20:00 +00:00
this.openSockets.add(socketConnection);
2016-08-09 09:42:21 +00:00
socketConnection.authenticate()
.then(socketConnection.listenToFunctionRequests);
2016-08-07 12:58:20 +00:00
}
;
}
exports.Smartsocket = Smartsocket;
2016-08-09 09:42:21 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nl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