smartsocket/dist/smartsocket.classes.smartsocket.js

57 lines
3.8 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);
2016-08-14 01:25:26 +00:00
this.io.on("connection", (socketArg) => {
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
*/
_handleSocketConnection(socketArg) {
2016-08-08 16:20:00 +00:00
let socketConnection = new smartsocket_classes_socketconnection_1.SocketConnection({
2016-08-14 01:25:26 +00:00
alias: undefined,
2016-08-08 16:20:00 +00:00
authenticated: false,
2016-08-14 01:25:26 +00:00
role: undefined,
2016-08-08 16:20:00 +00:00
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(() => {
return socketConnection.listenToFunctionRequests();
})
.catch((err) => {
console.log(err);
});
2016-08-07 12:58:20 +00:00
}
;
// communication
clientCall() {
// TODO: target specific client and initiate response
}
2016-08-07 12:58:20 +00:00
}
exports.Smartsocket = Smartsocket;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUdoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUt6RSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUEwQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLFlBQVksRUFBRSxDQUFDLFNBQVM7Z0JBQy9CLElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxTQUFTLENBQUMsQ0FBQztZQUM1QyxDQUFDLENBQUMsQ0FBQztRQUNQLENBQUMsQ0FBQTtRQUNELGdCQUFXLEdBQUc7WUFDVixJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxDQUFDLGVBQWlDO2dCQUN2RCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxrQ0FBa0MsZUFBZSxDQUFDL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