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) => {
|
2016-08-12 03:56:40 +00:00
|
|
|
this._handleSocketConnection(socketArg);
|
2016-08-07 16:59:39 +00:00
|
|
|
});
|
|
|
|
};
|
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-12 03:56:40 +00:00
|
|
|
_handleSocketConnection(socketArg) {
|
2016-08-08 16:20:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
;
|
2016-08-12 03:56:40 +00:00
|
|
|
// communication
|
|
|
|
clientCall() {
|
|
|
|
// TODO: target specific client and initiate response
|
|
|
|
}
|
2016-08-07 12:58:20 +00:00
|
|
|
}
|
|
|
|
exports.Smartsocket = Smartsocket;
|
2016-08-12 03:56:40 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUdoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUt6RSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUFtQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFD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