39 lines
2.8 KiB
JavaScript
39 lines
2.8 KiB
JavaScript
|
"use strict";
|
||
|
const plugins = require("./smartsocket.plugins");
|
||
|
// classes
|
||
|
const lik_1 = require("lik");
|
||
|
;
|
||
|
class Smartsocket {
|
||
|
constructor(options) {
|
||
|
this.openSockets = new lik_1.Objectmap();
|
||
|
this.closeServer = () => {
|
||
|
this.io.close();
|
||
|
this.openSockets.forEach((socketObjectArg) => {
|
||
|
socketObjectArg.socket.disconnect();
|
||
|
});
|
||
|
this.openSockets.wipe();
|
||
|
};
|
||
|
this.io = plugins.socketIo(options.port);
|
||
|
this.io.on('connection', (socket) => {
|
||
|
let socketObject = {
|
||
|
socket: socket,
|
||
|
authenticated: false
|
||
|
};
|
||
|
this.openSockets.add(socketObject);
|
||
|
this.authenticateSocket(socketObject);
|
||
|
});
|
||
|
}
|
||
|
;
|
||
|
authenticateSocket(socketObjectArg) {
|
||
|
let done = plugins.q.defer();
|
||
|
socketObjectArg.socket.on("dataAuth", data => {
|
||
|
socketObjectArg.socket.removeListener("dataAuth", () => { });
|
||
|
done.resolve();
|
||
|
});
|
||
|
socketObjectArg.socket.emit("requestAuth");
|
||
|
return done.promise;
|
||
|
}
|
||
|
;
|
||
|
}
|
||
|
exports.Smartsocket = Smartsocket;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUsvQixDQUFDO0FBT0Y7SUFHSSxZQUFZLE9BQXVDO1FBRG5ELGdCQ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