update smartsocket class to use standard class method definition

This commit is contained in:
Philipp Kunz 2017-07-15 23:16:22 +02:00
parent cccee35f2c
commit 7170e58457
3 changed files with 37 additions and 15 deletions

View File

@ -12,10 +12,13 @@ export declare class Smartsocket {
socketRoles: Objectmap<SocketRole>; socketRoles: Objectmap<SocketRole>;
constructor(optionsArg: ISmartsocketConstructorOptions); constructor(optionsArg: ISmartsocketConstructorOptions);
/** /**
* starts listening to incling sockets: * starts listening to incoming sockets:
*/ */
startServer: () => void; startServer(): Promise<void>;
closeServer: () => void; /**
* closes the server
*/
closeServer(): Promise<void>;
/** /**
* allows call to specific client. * allows call to specific client.
*/ */

View File

@ -1,4 +1,12 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartsocket.plugins"); const plugins = require("./smartsocket.plugins");
// classes // classes
@ -9,24 +17,31 @@ class Smartsocket {
constructor(optionsArg) { constructor(optionsArg) {
this.openSockets = new lik_1.Objectmap(); this.openSockets = new lik_1.Objectmap();
this.socketRoles = new lik_1.Objectmap(); this.socketRoles = new lik_1.Objectmap();
this.options = optionsArg;
}
/** /**
* starts listening to incling sockets: * starts listening to incoming sockets:
*/ */
this.startServer = () => { startServer() {
return __awaiter(this, void 0, void 0, function* () {
this.io = plugins.socketIo(this.options.port); this.io = plugins.socketIo(this.options.port);
this.io.on('connection', (socketArg) => { this.io.on('connection', (socketArg) => {
this._handleSocketConnection(socketArg); this._handleSocketConnection(socketArg);
}); });
}; });
this.closeServer = () => { }
/**
* closes the server
*/
closeServer() {
return __awaiter(this, void 0, void 0, function* () {
this.openSockets.forEach((socketObjectArg) => { this.openSockets.forEach((socketObjectArg) => {
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`); plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
socketObjectArg.socket.disconnect(); socketObjectArg.socket.disconnect();
}); });
this.openSockets.wipe(); this.openSockets.wipe();
this.io.close(); this.io.close();
}; });
this.options = optionsArg;
} }
// communication // communication
/** /**
@ -82,4 +97,4 @@ class Smartsocket {
} }
} }
exports.Smartsocket = Smartsocket; exports.Smartsocket = Smartsocket;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpREFBZ0Q7QUFHaEQsVUFBVTtBQUNWLDZCQUErQjtBQUUvQixpR0FBeUU7QUFDekUsMkZBQW1FO0FBT25FO0lBS0UsWUFBYSxVQUEwQztRQUZ2RCxnQkFBVyxHQUFHLElBQUksZUFBUyxFQUFvQixDQUFBO1FBQy9DLGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQWMsQ0FBQTtRQUt6Qzs7V0FFRztRQUNILGdCQUFXLEdBQUc7WUFDWixJQUFJLENBQUMsRUFBRSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQTtZQUM3QyxJQUFJLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxZQUFZLEVBQUUsQ0FBQyxTQUFTO2dCQUNqQyxJQUFJLENBQUMsdUJBQXVCLENBQUMsU0FBUyxDQUFDLENBQUE7WU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BQztZQUN4QyxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNsQyxDQUFDO1FBQ0QsTUFBTSxDQUFBO0lBQ1IsQ0FBQztJQUVEOztPQUVHO0lBQ0ssdUJBQXVCLENBQUUsU0FBUztRQUN4QyxJQUFJLGdCQUFnQixHQUFxQixJQUFJLHVEQUFnQixDQUFDO1lBQzVELEtBQUssRUFBRSxTQUFTO1lBQ2hCLGFBQWEsRUFBRSxLQUFLO1lBQ3BCLElBQUksRUFBRSxTQUFTO1lBQ2YsSUFBSSxFQUFFLFFBQVE7WUFDZCxlQUFlLEVBQUUsSUFBSTtZQUNyQixNQUFNLEVBQUUsU0FBUztTQUNsQixDQUFDLENBQUE7UUFDRixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyw2Q0FBNkMsQ0FBQyxDQUFBO1FBQ3BFLElBQUksQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLGdCQUFnQixDQUFDLENBQUE7UUFDdEMsZ0JBQWdCLENBQUMsWUFBWSxFQUFFO2FBQzVCLElBQUksQ0FBQztZQUNKLE1BQU0sQ0FBQyxnQkFBZ0IsQ0FBQyx3QkFBd0IsRUFBRSxDQUFBO1FBQ3BELENBQUMsQ0FBQzthQUNELEtBQUssQ0FBQyxDQUFDLEdBQUc7WUFDVCxPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFBO1FBQ2xCLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQztDQUVGO0FBdkZELGtDQXVGQyJ9

View File

@ -22,15 +22,19 @@ export class Smartsocket {
} }
/** /**
* starts listening to incling sockets: * starts listening to incoming sockets:
*/ */
startServer = () => { async startServer () {
this.io = plugins.socketIo(this.options.port) this.io = plugins.socketIo(this.options.port)
this.io.on('connection', (socketArg) => { this.io.on('connection', (socketArg) => {
this._handleSocketConnection(socketArg) this._handleSocketConnection(socketArg)
}) })
} }
closeServer = () => {
/**
* closes the server
*/
async closeServer () {
this.openSockets.forEach((socketObjectArg: SocketConnection) => { this.openSockets.forEach((socketObjectArg: SocketConnection) => {
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`) plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`)
socketObjectArg.socket.disconnect() socketObjectArg.socket.disconnect()