now tests run trough
This commit is contained in:
parent
d005ceff58
commit
8b8a940be6
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +1,2 @@
|
||||
export * from "./smartsocket.classes.smartsocket";
|
||||
export * from "./smartsocket.classes.smartsocketclient";
|
||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -3,4 +3,5 @@ function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
__export(require("./smartsocket.classes.smartsocket"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsbUNBQW1DLENBQUMsRUFBQSJ9
|
||||
__export(require("./smartsocket.classes.smartsocketclient"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsbUNBQW1DLENBQUMsRUFBQTtBQUNsRCxpQkFBYyx5Q0FBeUMsQ0FBQyxFQUFBIn0=
|
22
dist/smartsocket.classes.smartsocket.d.ts
vendored
22
dist/smartsocket.classes.smartsocket.d.ts
vendored
@ -1,19 +1,29 @@
|
||||
/// <reference types="socket.io" />
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { Objectmap } from "lik";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
export interface ISocketObject {
|
||||
socket: SocketIO.Socket;
|
||||
alias?: string;
|
||||
authenticated: boolean;
|
||||
role?: string;
|
||||
socket: SocketIO.Socket;
|
||||
}
|
||||
export interface ISmartsocketConstructorOptions {
|
||||
port: number;
|
||||
}
|
||||
export declare class Smartsocket {
|
||||
options: ISmartsocketConstructorOptions;
|
||||
io: SocketIO.Server;
|
||||
openSockets: Objectmap;
|
||||
constructor(options: ISmartsocketConstructorOptions);
|
||||
startListening: any;
|
||||
authenticateSocket(socketObjectArg: ISocketObject): plugins.q.Promise<{}>;
|
||||
registeredRoles: Objectmap;
|
||||
constructor(optionsArg: ISmartsocketConstructorOptions);
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocket(socket);
|
||||
registerFunctions(socketRoleArg: SocketRole): void;
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
startServer: () => void;
|
||||
closeServer: () => void;
|
||||
}
|
||||
|
44
dist/smartsocket.classes.smartsocket.js
vendored
44
dist/smartsocket.classes.smartsocket.js
vendored
@ -1,39 +1,51 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
const helpers = require("./smartsocket.helpers");
|
||||
// classes
|
||||
const lik_1 = require("lik");
|
||||
;
|
||||
;
|
||||
class Smartsocket {
|
||||
constructor(options) {
|
||||
constructor(optionsArg) {
|
||||
this.openSockets = new lik_1.Objectmap();
|
||||
this.registeredRoles = new lik_1.Objectmap();
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
this.startServer = () => {
|
||||
this.io = plugins.socketIo(this.options.port);
|
||||
this.io.on('connection', (socketArg) => {
|
||||
this._handleSocket(socketArg);
|
||||
});
|
||||
};
|
||||
this.closeServer = () => {
|
||||
this.io.close();
|
||||
this.openSockets.forEach((socketObjectArg) => {
|
||||
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
};
|
||||
this.io = plugins.socketIo(options.port);
|
||||
this.io.on('connection', (socket) => {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
_handleSocket(socket) {
|
||||
let socketObject = {
|
||||
socket: socket,
|
||||
authenticated: false
|
||||
};
|
||||
plugins.beautylog.log("Socket connected. Trying to authenticate...");
|
||||
this.openSockets.add(socketObject);
|
||||
this.authenticateSocket(socketObject);
|
||||
});
|
||||
helpers.authenticateSocket(socketObject)
|
||||
.then();
|
||||
}
|
||||
;
|
||||
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;
|
||||
registerFunctions(socketRoleArg) {
|
||||
this.registeredRoles.add(socketRoleArg);
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.Smartsocket = Smartsocket;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUsvQixDQUFDO0FBT0Y7SUFHSSxZQUFZLE9BQXVDO1FBRG5ELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQUUsQ0FBQztRQXNCOUIsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFFLENBQUM7WUFDaEIsSUFBSSxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsQ0FBQyxlQUE4QjtnQkFDcEQsZUFB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VBQWUsQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFDO2dCQUNqRixlQUFlLENBQUMsTUFBTSxDQUFDLFVBQVUsRUFBRSxDQUFDO1lBQ3hDLENBQUMsQ0FBQyxDQUFDO1lBQ0gsSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLEVBQUUsQ0FBQztZQUN4QixJQUFJLENBQUMsRUFBRSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3BCLENBQUMsQ0FBQTtRQXZDRyxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQztJQUM5QixDQUFDOztJQUVEOztPQUVHO0lBQ0ssYUFBYSxDQUFDLE1BQU07UUFDeEIsSUFBSSxZQUFZLEdBQWtCO1lBQzlCLE1BQU0sRUFBRSxNQUFNO1lBQ2QsYUFBYSxFQUFFLEtBQUs7U0FDdkIsQ0FBQztRQUNGLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLDZDQUE2QyxDQUFDLENBQUE7UUFDcEUsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUM7UUFDbkMsT0FBTyxDQUFDLGtCQUFrQixDQUFDLFlBQVksQ0FBQzthQUNuQyxJQUFJLEVBQUUsQ0FBQztJQUNoQixDQUFDO0lBRUQsaUJBQWlCLENBQUMsYUFBd0I7UUFDdEMsSUFBSSxDQUFDLGVBQWUsQ0FBQyxHQUFHLENBQUMsYUFBYSxDQUFDLENBQUM7SUFDNUMsQ0FBQzs7QUFxQkwsQ0FBQztBQTlDWSxtQkFBVyxjQThDdkIsQ0FBQSJ9
|
10
dist/smartsocket.classes.smartsocketclient.d.ts
vendored
Normal file
10
dist/smartsocket.classes.smartsocketclient.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* interface for class SmartsocketClient
|
||||
*/
|
||||
export interface ISmartsocketClientOptions {
|
||||
port: number;
|
||||
url: string;
|
||||
}
|
||||
export declare class SmartsocketClient {
|
||||
constructor();
|
||||
}
|
7
dist/smartsocket.classes.smartsocketclient.js
vendored
Normal file
7
dist/smartsocket.classes.smartsocketclient.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
class SmartsocketClient {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
exports.SmartsocketClient = SmartsocketClient;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVBO0lBQ0k7SUFFQSxDQUFDO0FBQ0wsQ0FBQztBQUpZLHlCQUFpQixvQkFJN0IsQ0FBQSJ9
|
12
dist/smartsocket.classes.socketfunction.d.ts
vendored
Normal file
12
dist/smartsocket.classes.socketfunction.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
export interface SocketFunctionOptions {
|
||||
name: string;
|
||||
func: any;
|
||||
roles: SocketRole[];
|
||||
}
|
||||
export declare class SocketFunction {
|
||||
name: string;
|
||||
func: any;
|
||||
roles: SocketRole[];
|
||||
constructor(optionsArg: SocketFunctionOptions);
|
||||
}
|
12
dist/smartsocket.classes.socketfunction.js
vendored
Normal file
12
dist/smartsocket.classes.socketfunction.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
;
|
||||
class SocketFunction {
|
||||
constructor(optionsArg) {
|
||||
this.name = optionsArg.name;
|
||||
this.func = optionsArg.func;
|
||||
this.roles = optionsArg.roles;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.SocketFunction = SocketFunction;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVlDLENBQUM7QUFFRjtJQUlJLFlBQVksVUFBaUM7UUFDekMsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsS0FBSyxHQUFHLFVBQVUsQ0FBQyxLQUFLLENBQUM7SUFDbEMsQ0FBQzs7QUFDTCxDQUFDO0FBVFksc0JBQWMsaUJBUzFCLENBQUEifQ==
|
15
dist/smartsocket.classes.socketrole.d.ts
vendored
Normal file
15
dist/smartsocket.classes.socketrole.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* interface for class SocketRole
|
||||
*/
|
||||
export interface SocketRoleOptions {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
}
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
export declare class SocketRole {
|
||||
name: string;
|
||||
passwordHash: string;
|
||||
constructor(optionsArg: SocketRoleOptions);
|
||||
}
|
12
dist/smartsocket.classes.socketrole.js
vendored
Normal file
12
dist/smartsocket.classes.socketrole.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
class SocketRole {
|
||||
constructor(optionsArg) {
|
||||
this.name = optionsArg.name;
|
||||
this.passwordHash = optionsArg.passwordHash;
|
||||
}
|
||||
}
|
||||
exports.SocketRole = SocketRole;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFjQTs7R0FFRztBQUNIO0lBR0ksWUFBWSxVQUE0QjtRQUNwQyxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO0lBQ2hELENBQUM7QUFDTCxDQUFDO0FBUFksa0JBQVUsYUFPdEIsQ0FBQSJ9
|
7
dist/smartsocket.helpers.d.ts
vendored
7
dist/smartsocket.helpers.d.ts
vendored
@ -0,0 +1,7 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import { ISocketObject } from "./smartsocket.classes.smartsocket";
|
||||
/**
|
||||
* authenticate a socket
|
||||
*/
|
||||
export declare let authenticateSocket: (socketObjectArg: ISocketObject) => plugins.q.Promise<{}>;
|
28
dist/smartsocket.helpers.js
vendored
28
dist/smartsocket.helpers.js
vendored
@ -1,2 +1,28 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
||||
const plugins = require("./smartsocket.plugins");
|
||||
/**
|
||||
* authenticate a socket
|
||||
*/
|
||||
exports.authenticateSocket = (socketObjectArg) => {
|
||||
let done = plugins.q.defer();
|
||||
socketObjectArg.socket.on("dataAuth", dataArg => {
|
||||
plugins.beautylog.log("received authentication data. now hashing and comparing...");
|
||||
socketObjectArg.socket.removeListener("dataAuth", () => { });
|
||||
if ((true)) {
|
||||
socketObjectArg.alias = dataArg.alias;
|
||||
socketObjectArg.authenticated = true;
|
||||
socketObjectArg.role = dataArg.role;
|
||||
socketObjectArg.socket.emit("authenticated");
|
||||
plugins.beautylog.ok(`socket with >>alias ${socketObjectArg.alias} >>role ${socketObjectArg.role} is authenticated!`);
|
||||
done.resolve(socketObjectArg);
|
||||
}
|
||||
else {
|
||||
socketObjectArg.socket.disconnect();
|
||||
done.reject("not authenticated");
|
||||
}
|
||||
;
|
||||
});
|
||||
socketObjectArg.socket.emit("requestAuth");
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFRakQ7O0dBRUc7QUFDUSwwQkFBa0IsR0FBRyxDQUFDLGVBQThCO0lBQzNELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxFQUFFLE9BQU87UUFDekMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsNERBQTRELENBQUMsQ0FBQztRQUNwRixlQUFlLENBQUMsTUFBTSxDQUFDLGNBQWMsQ0FBQyxVQUFVLEVBQUUsUUFBUSxDQUFDLENBQUMsQ0FBQztRQUM3RCxFQUFFLENBQUEsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUEsQ0FBQztZQUNQLGVBQWUsQ0FBQyxLQUFLLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQTtZQUNyQyxlQUFlLENBQUMsYUFBYSxHQUFHLElBQUksQ0FBQztZQUNyQyxlQUFlLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUM7WUFDcEMsZUFBZSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLENBQUM7WUFDN0MsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsdUJBQXVCLGVBQWUsQ0FBQyxLQUFLLFdBQVcsZUFBZSxDQUFDLElBQUksb0JBQW9CLENBQUMsQ0FBQTtZQUNySCxJQUFJLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ2xDLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLGVBQWUsQ0FBQyxNQUFNLENBQUMsVUFBVSxFQUFFLENBQUM7WUFDcEMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDO1FBQ3JDLENBQUM7UUFBQSxDQUFDO0lBQ04sQ0FBQyxDQUFDLENBQUM7SUFDSCxlQUFlLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQztJQUMzQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUMifQ==
|
1
dist/smartsocket.plugins.d.ts
vendored
1
dist/smartsocket.plugins.d.ts
vendored
@ -3,4 +3,5 @@ export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import q = require("q");
|
||||
export import socketIo = require("socket.io");
|
||||
export import socketIoClient = require("socket.io-client");
|
||||
export import taskbuffer = require("taskbuffer");
|
||||
|
3
dist/smartsocket.plugins.js
vendored
3
dist/smartsocket.plugins.js
vendored
@ -4,5 +4,6 @@ exports.beautylog = require("beautylog");
|
||||
exports.lik = require("lik");
|
||||
exports.q = require("q");
|
||||
exports.socketIo = require("socket.io");
|
||||
exports.socketIoClient = require("socket.io-client");
|
||||
exports.taskbuffer = require("taskbuffer");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsV0FBRyxXQUFZLEtBQUssQ0FBQyxDQUFDO0FBQ3RCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixnQkFBUSxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2hDLGtCQUFVLFdBQVcsWUFBWSxDQUFDLENBQUMifQ==
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsV0FBRyxXQUFZLEtBQUssQ0FBQyxDQUFDO0FBQ3RCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixnQkFBUSxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2hDLHNCQUFjLFdBQVcsa0JBQWtCLENBQUMsQ0FBQztBQUM3QyxrQkFBVSxXQUFXLFlBQVksQ0FBQyxDQUFDIn0=
|
@ -22,7 +22,7 @@
|
||||
"@types/socket.io": "^1.4.26",
|
||||
"@types/socket.io-client": "^1.4.26",
|
||||
"beautylog": "^5.0.20",
|
||||
"lik": "^1.0.9",
|
||||
"lik": "^1.0.10",
|
||||
"q": "^1.4.1",
|
||||
"socket.io": "^1.4.8",
|
||||
"socket.io-client": "^1.4.8",
|
||||
|
17
test/test.js
17
test/test.js
@ -9,16 +9,29 @@ describe("smartsocket", function () {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: 3000 });
|
||||
testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
it("should register a new Function", function () {
|
||||
});
|
||||
it("should start listening when .started is called", function () {
|
||||
testSmartsocket.startServer();
|
||||
});
|
||||
it("should react to a new websocket connection", function (done) {
|
||||
this.timeout(10000);
|
||||
let socket = socketIoClient("http://localhost:3000", {});
|
||||
socket.on("requestAuth", function () {
|
||||
console.log("server requested authentication");
|
||||
socket.emit("dataAuth", {
|
||||
secret: "hello"
|
||||
role: "coreflowContainer",
|
||||
password: "somePassword",
|
||||
alias: "coreflow1"
|
||||
});
|
||||
socket.on("authenticated", () => {
|
||||
console.log("client is authenticated");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it("should close the server", function () {
|
||||
testSmartsocket.closeServer();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixNQUFPLGNBQWMsV0FBVyxrQkFBa0IsQ0FBQyxDQUFDO0FBQ3BELE1BQU8sV0FBVyxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBRTlDLElBQUksZUFBd0MsQ0FBQztBQUU3QyxRQUFRLENBQUMsYUFBY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ixPQUFPLENBQUMsR0FBRyxDQUFDLHlCQUF5QixDQUFDLENBQUM7Z0JBQ3ZDLElBQUksRUFBRSxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDUCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0lBQ0gsRUFBRSxDQUFDLHlCQUF5QixFQUFDO1FBQ3pCLGVBQWUsQ0FBQyxXQUFXLEVBQUUsQ0FBQztJQUNsQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0=
|
16
test/test.ts
16
test/test.ts
@ -10,15 +10,29 @@ describe("smartsocket", function () {
|
||||
testSmartsocket = new smartsocket.Smartsocket({ port: 3000 });
|
||||
testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
it("should register a new Function",function(){
|
||||
|
||||
})
|
||||
it("should start listening when .started is called",function(){
|
||||
testSmartsocket.startServer();
|
||||
})
|
||||
it("should react to a new websocket connection", function (done) {
|
||||
this.timeout(10000);
|
||||
let socket = socketIoClient("http://localhost:3000", {});
|
||||
socket.on("requestAuth", function () {
|
||||
console.log("server requested authentication");
|
||||
socket.emit("dataAuth", {
|
||||
secret: "hello"
|
||||
role: "coreflowContainer",
|
||||
password: "somePassword",
|
||||
alias: "coreflow1"
|
||||
});
|
||||
socket.on("authenticated",() => {
|
||||
console.log("client is authenticated");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it("should close the server",function(){
|
||||
testSmartsocket.closeServer();
|
||||
})
|
||||
});
|
@ -8,9 +8,10 @@ import {SocketFunction} from "./smartsocket.classes.socketfunction";
|
||||
|
||||
|
||||
export interface ISocketObject {
|
||||
group?:string,
|
||||
socket: SocketIO.Socket,
|
||||
alias?:string;
|
||||
authenticated: boolean
|
||||
role?:string,
|
||||
socket: SocketIO.Socket,
|
||||
};
|
||||
|
||||
export interface ISmartsocketConstructorOptions {
|
||||
@ -19,12 +20,12 @@ export interface ISmartsocketConstructorOptions {
|
||||
};
|
||||
|
||||
export class Smartsocket {
|
||||
options:ISmartsocketConstructorOptions
|
||||
io: SocketIO.Server;
|
||||
openSockets = new Objectmap();
|
||||
registeredRoles = new Objectmap();
|
||||
constructor(options: ISmartsocketConstructorOptions) {
|
||||
this.io = plugins.socketIo(options.port);
|
||||
this.io.on('connection', this._handleSocket);
|
||||
constructor(optionsArg: ISmartsocketConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -35,22 +36,33 @@ export class Smartsocket {
|
||||
socket: socket,
|
||||
authenticated: false
|
||||
};
|
||||
plugins.beautylog.log("Socket connected. Trying to authenticate...")
|
||||
this.openSockets.add(socketObject);
|
||||
helpers.authenticateSocket(socketObject)
|
||||
.then();
|
||||
}
|
||||
|
||||
registerRole(socketRoleArg:SocketRole){
|
||||
registerFunctions(socketRoleArg:SocketRole){
|
||||
this.registeredRoles.add(socketRoleArg);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* starts listening to incling sockets:
|
||||
*/
|
||||
|
||||
startServer = () => {
|
||||
this.io = plugins.socketIo(this.options.port);
|
||||
this.io.on('connection', (socketArg) => {
|
||||
this._handleSocket(socketArg);
|
||||
});
|
||||
}
|
||||
closeServer = () => {
|
||||
this.io.close();
|
||||
this.openSockets.forEach((socketObjectArg: ISocketObject) => {
|
||||
plugins.beautylog.log(`disconnect socket with >>alias ${socketObjectArg.alias}`);
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
// import classes
|
||||
import { Stringmap } from "lik";
|
||||
import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
// import classes
|
||||
import { Stringmap } from "lik";
|
||||
|
||||
/**
|
||||
* interface for class SocketRole
|
||||
*/
|
||||
|
@ -11,9 +11,20 @@ import {ISocketObject} from "./smartsocket.classes.smartsocket";
|
||||
*/
|
||||
export let authenticateSocket = (socketObjectArg: ISocketObject) => {
|
||||
let done = plugins.q.defer();
|
||||
socketObjectArg.socket.on("dataAuth", data => {
|
||||
socketObjectArg.socket.on("dataAuth", dataArg => {
|
||||
plugins.beautylog.log("received authentication data. now hashing and comparing...");
|
||||
socketObjectArg.socket.removeListener("dataAuth", () => { });
|
||||
done.resolve();
|
||||
if((true)){ // TODO: authenticate password
|
||||
socketObjectArg.alias = dataArg.alias
|
||||
socketObjectArg.authenticated = true;
|
||||
socketObjectArg.role = dataArg.role;
|
||||
socketObjectArg.socket.emit("authenticated");
|
||||
plugins.beautylog.ok(`socket with >>alias ${socketObjectArg.alias} >>role ${socketObjectArg.role} is authenticated!`)
|
||||
done.resolve(socketObjectArg);
|
||||
} else {
|
||||
socketObjectArg.socket.disconnect();
|
||||
done.reject("not authenticated");
|
||||
};
|
||||
});
|
||||
socketObjectArg.socket.emit("requestAuth");
|
||||
return done.promise;
|
||||
|
Loading…
Reference in New Issue
Block a user