smartsocket/dist/smartsocket.classes.smartsocket.js

50 lines
3.4 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._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({
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
}
;
// 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,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