add some more logic

This commit is contained in:
Philipp Kunz 2016-08-09 11:42:21 +02:00
parent 8d58e0b2f3
commit fee54dfb95
21 changed files with 315 additions and 74 deletions

View File

@ -1,20 +1,18 @@
/// <reference types="socket.io" />
import { Objectmap } from "lik";
import { SocketRole } from "./smartsocket.classes.socketrole";
import { SocketConnection } from "./smartsocket.classes.socketconnection";
export interface ISmartsocketConstructorOptions {
port: number;
}
export declare class Smartsocket {
options: ISmartsocketConstructorOptions;
io: SocketIO.Server;
openSockets: Objectmap;
registeredFunctions: Objectmap;
openSockets: Objectmap<SocketConnection>;
constructor(optionsArg: ISmartsocketConstructorOptions);
/**
* the standard handler for new socket connections
*/
private _handleSocket(socketArg);
registerFunction(socketRoleArg: SocketRole): void;
/**
* starts listening to incling sockets:
*/

View File

@ -1,6 +1,5 @@
"use strict";
const plugins = require("./smartsocket.plugins");
const helpers = require("./smartsocket.helpers");
// classes
const lik_1 = require("lik");
const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.socketconnection");
@ -8,7 +7,6 @@ const smartsocket_classes_socketconnection_1 = require("./smartsocket.classes.so
class Smartsocket {
constructor(optionsArg) {
this.openSockets = new lik_1.Objectmap();
this.registeredFunctions = new lik_1.Objectmap();
/**
* starts listening to incling sockets:
*/
@ -39,13 +37,10 @@ class Smartsocket {
});
plugins.beautylog.log("Socket connected. Trying to authenticate...");
this.openSockets.add(socketConnection);
helpers.authenticateSocket(socketConnection)
.then();
}
registerFunction(socketRoleArg) {
this.registeredFunctions.add(socketRoleArg);
socketConnection.authenticate()
.then(socketConnection.listenToFunctionRequests);
}
;
}
exports.Smartsocket = Smartsocket;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwib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DQUFDLENBQUM7UUFDSCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyw2Q0FBNkMsQ0FBQyxDQUFBO1FBQ3BFLElBQUksQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLGdCQUFnQixDQUFDLENBQUM7UUFDdkMsZ0JBQWdCLENBQUMsWUFBWSxFQUFFO2FBQzFCLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO0lBQ3pELENBQUM7O0FBb0JMLENBQUM7QUF4Q1ksbUJBQVcsY0F3Q3ZCLENBQUEifQ==

View File

@ -1,3 +1,6 @@
/// <reference types="q" />
import * as plugins from "./smartsocket.plugins";
import { ISocketFunctionRequestObject, ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction";
/**
* interface for class SmartsocketClient
*/
@ -7,4 +10,5 @@ export interface ISmartsocketClientOptions {
}
export declare class SmartsocketClient {
constructor();
dispatchFunctionRequest(dataArg: ISocketFunctionRequestObject): plugins.q.Promise<ISocketFunctionResponseObject>;
}

View File

@ -1,7 +1,15 @@
"use strict";
const plugins = require("./smartsocket.plugins");
class SmartsocketClient {
constructor() {
}
dispatchFunctionRequest(dataArg) {
let done = plugins.q.defer();
let responseData;
done.resolve(responseData);
return done.promise;
}
;
}
exports.SmartsocketClient = SmartsocketClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVBO0lBQ0k7SUFFQSxDQUFDO0FBQ0wsQ0FBQztBQUpZLHlCQUFpQixvQkFJN0IsQ0FBQSJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUl6QixDQUFDLENBSitDO0FBaUJoRDtJQUNJO0lBRUEsQ0FBQztJQUNELHVCQUF1QixDQUFDLE9BQW9DO1FBQ3hELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFpQyxDQUFDO1FBQzVELElBQUksWUFBMEMsQ0FBQztRQUMvQyxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDO1FBQzNCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBQ0wsQ0FBQztBQVZZLHlCQUFpQixvQkFVN0IsQ0FBQSJ9

View File

@ -1,14 +1,39 @@
/// <reference types="socket.io" />
/// <reference types="q" />
import * as plugins from "./smartsocket.plugins";
import { SocketRole } from "./smartsocket.classes.socketrole";
/**
* interface for constructor of class SocketConnection
*/
export interface ISocketConnectionOptions {
alias?: string;
authenticated: boolean;
role?: string;
role?: SocketRole;
socket: SocketIO.Socket;
}
/**
* interface for authentication data
*/
export interface ISocketConnectionAuthenticationObject {
role: "coreflowContainer";
password: "somePassword";
alias: "coreflow1";
}
/**
* class SocketConnection represents a websocket connection
*/
export declare class SocketConnection {
alias?: string;
authenticated: boolean;
role?: string;
role?: SocketRole;
socket: SocketIO.Socket;
constructor(optionsArg: ISocketConnectionOptions);
/**
* authenticate the socket
*/
authenticate(): plugins.q.Promise<{}>;
/**
* listen to function requests
*/
listenToFunctionRequests(): plugins.q.Promise<{}>;
}

View File

@ -1,5 +1,11 @@
"use strict";
const plugins = require("./smartsocket.plugins");
const helpers = require("./smartsocket.helpers");
;
// export classes
/**
* class SocketConnection represents a websocket connection
*/
class SocketConnection {
constructor(optionsArg) {
this.alias = optionsArg.alias;
@ -7,7 +13,58 @@ class SocketConnection {
this.role = optionsArg.role;
this.socket = optionsArg.socket;
}
/**
* authenticate the socket
*/
authenticate() {
let done = plugins.q.defer();
this.socket.on("dataAuth", dataArg => {
plugins.beautylog.log("received authentication data. now hashing and comparing...");
this.socket.removeListener("dataAuth", () => { });
if ((true)) {
this.alias = dataArg.alias;
this.authenticated = true;
this.role = helpers.findSocketRoleByString(dataArg.role);
this.socket.emit("authenticated");
plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`);
done.resolve(this);
}
else {
this.socket.disconnect();
done.reject("not authenticated");
}
;
});
this.socket.emit("requestAuth");
return done.promise;
}
;
/**
* listen to function requests
*/
listenToFunctionRequests() {
let done = plugins.q.defer();
if (this.authenticated) {
this.socket.on("function", (dataArg) => {
let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.functionName;
});
if (referencedFunction !== undefined) {
referencedFunction.invoke(dataArg);
}
else {
plugins.beautylog.warn("function not existent or out of access scope");
}
;
});
}
else {
done.reject("socket needs to be authenticated first");
}
;
return done.promise;
}
}
exports.SocketConnection = SocketConnection;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFPQyxDQUFDO0FBRUY7SUFLSSxZQUFZLFVBQW1DO1FBQzNDLElBQUksQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUF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DIn0=

View File

@ -1,19 +1,36 @@
import { SocketRole } from "./smartsocket.classes.socketrole";
export interface ISocketFunctionData {
export interface ISocketFunctionRequestObject {
functionName: string;
functionData: any;
argumentObject: any;
shortId: string;
responseTimeout?: number;
}
export interface ISocketFunctionResponseObject {
shortId: string;
argumentObject: any;
}
export interface SocketFunctionOptions {
name: string;
func: any;
roles: SocketRole[];
}
/**
* class SocketFunction respresents a function that can be transparently called using a SocketConnection
*/
export declare class SocketFunction {
name: string;
func: any;
roles: SocketRole[];
/**
* the constructor for SocketFunction
*/
constructor(optionsArg: SocketFunctionOptions);
/**
* notifies a role about access to this SocketFunction
*/
private _notifyRole(socketRoleArg);
functionRequest(dataArg: ISocketFunctionData): void;
/**
* invokes the function of this SocketFunction
*/
invoke(dataArg: ISocketFunctionRequestObject): void;
}

View File

@ -1,7 +1,15 @@
"use strict";
;
;
;
// export classes
/**
* class SocketFunction respresents a function that can be transparently called using a SocketConnection
*/
class SocketFunction {
/**
* the constructor for SocketFunction
*/
constructor(optionsArg) {
this.name = optionsArg.name;
this.func = optionsArg.func;
@ -11,11 +19,18 @@ class SocketFunction {
}
}
;
/**
* notifies a role about access to this SocketFunction
*/
_notifyRole(socketRoleArg) {
socketRoleArg.addSocketFunction(this);
}
functionRequest(dataArg) {
/**
* invokes the function of this SocketFunction
*/
invoke(dataArg) {
}
;
}
exports.SocketFunction = SocketFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVDLENBQUM7QUFNRCxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQWlDO1FBQ3pDLElBQUksQ0FBQyxJQUFJ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DQUFDO1FBQzlCLEdBQUcsQ0FBQyxDQUFDLElBQUksYUFBYSxJQUFJLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQSxDQUFDO1lBQ2xDLElBQUksQ0FBQyxXQUFXLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDcEMsQ0FBQztJQUNMLENBQUM7O0lBRUQ7O09BRUc7SUFDSyxXQUFXLENBQUMsYUFBd0I7UUFDeEMsYUFBYSxDQUFDLGlCQUFpQixDQUFDLElBQUksQ0FBQyxDQUFDO0lBQzFDLENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBQyxPQUFvQztJQUUzQyxDQUFDOztBQUVMLENBQUM7QUEvQlksc0JBQWMsaUJBK0IxQixDQUFBIn0=

View File

@ -0,0 +1,18 @@
import { ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction";
import { Objectmap } from "lik";
export declare type TSocketRequestStatus = "new" | "pending" | "finished";
export declare type TSocketRequestSide = "requesting" | "responding";
export interface SocketRequestConstructorOptions {
side: TSocketRequestSide;
shortid: string;
}
export declare let allRequestingSocketRequests: Objectmap<SocketRequest>;
export declare let allRespondingSocketRequests: Objectmap<SocketRequest>;
export declare class SocketRequest {
status: TSocketRequestStatus;
side: TSocketRequestSide;
shortid: string;
constructor(optionsArg: SocketRequestConstructorOptions);
respond(dataArg: ISocketFunctionResponseObject): void;
private _dispatch();
}

View File

@ -0,0 +1,30 @@
"use strict";
// import classes
const lik_1 = require("lik");
;
//export objects
exports.allRequestingSocketRequests = new lik_1.Objectmap();
exports.allRespondingSocketRequests = new lik_1.Objectmap();
// export classes
class SocketRequest {
constructor(optionsArg) {
this.status = "new";
this.side = optionsArg.side;
this.shortid = optionsArg.shortid;
if (this.side === "requesting") {
exports.allRequestingSocketRequests.add(this);
}
else {
exports.allRespondingSocketRequests.add(this);
}
;
}
;
respond(dataArg) {
}
_dispatch() {
}
}
exports.SocketRequest = SocketRequest;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJ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"./smartsocket.classes.socketfunction";
export declare let allSocketRoles: Objectmap<SocketRole>;
/**
* interface for class SocketRole
*/
@ -12,7 +14,7 @@ export interface SocketRoleOptions {
export declare class SocketRole {
name: string;
passwordHash: string;
allowedFunctions: SocketFunction[];
allowedFunctions: Objectmap<SocketFunction>;
constructor(optionsArg: SocketRoleOptions);
addSocketFunction(socketFunctionArg: SocketFunction): void;
}

View File

@ -1,16 +1,21 @@
"use strict";
// import classes
const lik_1 = require("lik");
exports.allSocketRoles = new lik_1.Objectmap();
/**
* A socketrole defines access to certain routines.
*/
class SocketRole {
constructor(optionsArg) {
this.allowedFunctions = new lik_1.Objectmap();
this.name = optionsArg.name;
this.passwordHash = optionsArg.passwordHash;
exports.allSocketRoles.add(this);
}
;
addSocketFunction(socketFunctionArg) {
this.allowedFunctions.push(socketFunctionArg);
this.allowedFunctions.add(socketFunctionArg);
}
}
exports.SocketRole = SocketRole;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFjQTs7R0FFRztBQUNIO0lBSUksWUFBWSxVQUE2QjtRQUNyQyxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO0lBQ2hELENBQUM7O0lBQ0QsaUJBQWlCLENBQUMsaUJBQWdDO1FBQzlDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxJQUFJLENBQUMsaUJBQWlCLENBQUMsQ0FBQztJQUNsRCxDQUFDO0FBQ0wsQ0FBQztBQVhZLGtCQUFVLGFBV3RCLENBQUEifQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxpQkFBaUI7QUFDakIsc0JBQTBCLEtBQUssQ0FBQyxDQUFBO0FBSXJCLHNCQUFjLEdBQUcsSUFBSSxlQUFTLEVBQWMsQ0FBQztBQVd4RDs7R0FFRztBQUNIO0lBSUksWUFBWSxVQUE2QjtRQUR6QyxxQkFBZ0IsR0FBRyxJQUFJLGVBQVMsRUFBa0IsQ0FBQztRQUUvQyxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFDO1FBQzVDLHNCQUFjLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQzdCLENBQUM7O0lBQ0QsaUJBQWlCLENBQUMsaUJBQWdDO1FBQzlDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxHQUFHLENBQUMsaUJBQWlCLENBQUMsQ0FBQztJQUNqRCxDQUFDO0FBQ0wsQ0FBQztBQVpZLGtCQUFVLGFBWXRCLENBQUEifQ==

View File

@ -1,8 +1,2 @@
/// <reference types="q" />
import * as plugins from "./smartsocket.plugins";
import { SocketConnection } from "./smartsocket.classes.socketconnection";
/**
* authenticate a socket
*/
export declare let authenticateSocket: (socketConnectionArg: SocketConnection) => plugins.q.Promise<{}>;
export declare let listenToReadySocket: (socketConnectionArg: SocketConnection) => plugins.q.Promise<{}>;
import { SocketRole } from "./smartsocket.classes.socketrole";
export declare let findSocketRoleByString: (socketRoleNameArg: string) => SocketRole;

View File

@ -1,33 +1,7 @@
"use strict";
const plugins = require("./smartsocket.plugins");
/**
* authenticate a socket
*/
exports.authenticateSocket = (socketConnectionArg) => {
let done = plugins.q.defer();
socketConnectionArg.socket.on("dataAuth", dataArg => {
plugins.beautylog.log("received authentication data. now hashing and comparing...");
socketConnectionArg.socket.removeListener("dataAuth", () => { });
if ((true)) {
socketConnectionArg.alias = dataArg.alias;
socketConnectionArg.authenticated = true;
socketConnectionArg.role = dataArg.role;
socketConnectionArg.socket.emit("authenticated");
plugins.beautylog.ok(`socket with >>alias ${socketConnectionArg.alias} >>role ${socketConnectionArg.role} is authenticated!`);
done.resolve(socketConnectionArg);
}
else {
socketConnectionArg.socket.disconnect();
done.reject("not authenticated");
}
;
});
socketConnectionArg.socket.emit("requestAuth");
return done.promise;
const smartsocket_classes_socketrole_1 = require("./smartsocket.classes.socketrole");
// SocketRole helpers
exports.findSocketRoleByString = (socketRoleNameArg) => {
return smartsocket_classes_socketrole_1.allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg; });
};
exports.listenToReadySocket = (socketConnectionArg) => {
let done = plugins.q.defer();
// socketConnectionArg.socket.listen("function", )
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFRakQ7O0dBRUc7QUFDUSwwQkFBa0IsR0FBRyxDQUFDLG1CQUFxQztJQUNsRSxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQzdCLG1CQUFtQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxFQUFFLE9BQ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FHLENBQUMsbUJBQXFDO0lBQ25FLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0Isa0RBQWtEO0lBQ2xELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQSJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQU1BLGlEQUEyQyxrQ0FBa0MsQ0FBQyxDQUFBO0FBRzlFLHFCQUFxQjtBQUNWLDhCQUFzQixHQUFHLENBQUMsaUJBQXlCO0lBQzFELE1BQU0sQ0FBQywrQ0FBYyxDQUFDLElBQUksQ0FBQyxDQUFDLGFBQWEsT0FBTyxNQUFNLENBQUMsYUFBYSxDQUFDLElBQUksS0FBSyxpQkFBaUIsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0FBQ3RHLENBQUMsQ0FBQyJ9

View File

@ -2,6 +2,7 @@ import "typings-global";
export import beautylog = require("beautylog");
export import lik = require("lik");
export import q = require("q");
export import shortid = require("shortid");
export import socketIo = require("socket.io");
export import socketIoClient = require("socket.io-client");
export import taskbuffer = require("taskbuffer");

View File

@ -3,7 +3,8 @@ require("typings-global");
exports.beautylog = require("beautylog");
exports.lik = require("lik");
exports.q = require("q");
exports.shortid = require("shortid");
exports.socketIo = require("socket.io");
exports.socketIoClient = require("socket.io-client");
exports.taskbuffer = require("taskbuffer");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsV0FBRyxXQUFZLEtBQUssQ0FBQyxDQUFDO0FBQ3RCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixnQkFBUSxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2hDLHNCQUFjLFdBQVcsa0JBQWtCLENBQUMsQ0FBQztBQUM3QyxrQkFBVSxXQUFXLFlBQVksQ0FBQyxDQUFDIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsV0FBRyxXQUFZLEtBQUssQ0FBQyxDQUFDO0FBQ3RCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNqQixlQUFPLFdBQVcsU0FBUyxDQUFDLENBQUM7QUFDN0IsZ0JBQVEsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNoQyxzQkFBYyxXQUFXLGtCQUFrQixDQUFDLENBQUM7QUFDN0Msa0JBQVUsV0FBVyxZQUFZLENBQUMsQ0FBQyJ9

View File

@ -1,5 +1,12 @@
import * as plugins from "./smartsocket.plugins"
// import interfaces
import { ISocketFunctionRequestObject, ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction";
// import classes
import { SocketFunction } from "./smartsocket.classes.socketfunction";
/**
* interface for class SmartsocketClient
*/
@ -12,4 +19,10 @@ export class SmartsocketClient {
constructor() {
}
dispatchFunctionRequest(dataArg:ISocketFunctionRequestObject): plugins.q.Promise<ISocketFunctionResponseObject> {
let done = plugins.q.defer<ISocketFunctionResponseObject>();
let responseData:ISocketFunctionResponseObject;
done.resolve(responseData);
return done.promise;
};
}

View File

@ -2,9 +2,15 @@ import * as plugins from "./smartsocket.plugins";
import * as helpers from "./smartsocket.helpers";
// import classes
import { SocketFunction, ISocketFunctionRequestObject } from "./smartsocket.classes.socketfunction";
import { SocketRequest } from "./smartsocket.classes.socketrequest";
import { SocketRole } from "./smartsocket.classes.socketrole";
import { SocketFunction, ISocketFunctionData } from "./smartsocket.classes.socketfunction";
// export interfaces
/**
* interface for constructor of class SocketConnection
*/
export interface ISocketConnectionOptions {
alias?: string;
authenticated: boolean;
@ -12,6 +18,20 @@ export interface ISocketConnectionOptions {
socket: SocketIO.Socket;
};
/**
* interface for authentication data
*/
export interface ISocketConnectionAuthenticationObject {
role: "coreflowContainer",
password: "somePassword",
alias: "coreflow1"
}
// export classes
/**
* class SocketConnection represents a websocket connection
*/
export class SocketConnection {
alias?: string;
authenticated: boolean;
@ -53,8 +73,15 @@ export class SocketConnection {
listenToFunctionRequests() {
let done = plugins.q.defer();
if(this.authenticated){
this.socket.on("function", (dataArg:ISocketFunctionData) => {
this.role.allowedFunctions
this.socket.on("function", (dataArg:ISocketFunctionRequestObject) => {
let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.functionName
});
if(referencedFunction !== undefined){
referencedFunction.invoke(dataArg);
} else {
plugins.beautylog.warn("function not existent or out of access scope");
};
})
} else {
done.reject("socket needs to be authenticated first");

View File

@ -4,18 +4,31 @@ import * as plugins from "./smartsocket.plugins";
import { Stringmap } from "lik";
import { SocketRole } from "./smartsocket.classes.socketrole";
export interface ISocketFunctionData {
// export interfaces
export interface ISocketFunctionRequestObject {
functionName:string,
functionData:any,
argumentObject:any,
shortId:string,
responseTimeout?:number
};
export interface ISocketFunctionResponseObject {
shortId:string;
argumentObject:any;
};
export interface SocketFunctionOptions {
name: string;
func: any;
roles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
};
// export classes
/**
* class SocketFunction respresents a function that can be transparently called using a SocketConnection
*/
export class SocketFunction {
name: string;
func: any;
@ -41,9 +54,9 @@ export class SocketFunction {
}
/**
* handles a function request to this SocketFunction
* invokes the function of this SocketFunction
*/
functionRequest(dataArg:ISocketFunctionData){
invoke(dataArg:ISocketFunctionRequestObject){
};

View File

@ -0,0 +1,43 @@
import * as plugins from "./smartsocket.plugins";
// import interfaces
import { ISocketFunctionRequestObject, ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction";
// import classes
import { Objectmap } from "lik";
import { SocketFunction } from "./smartsocket.classes.socketfunction";
// export interfaces
export type TSocketRequestStatus = "new" | "pending" | "finished";
export type TSocketRequestSide = "requesting" | "responding";
export interface SocketRequestConstructorOptions {
side: TSocketRequestSide;
shortid: string;
};
//export objects
export let allRequestingSocketRequests = new Objectmap<SocketRequest>();
export let allRespondingSocketRequests = new Objectmap<SocketRequest>();
// export classes
export class SocketRequest {
status: TSocketRequestStatus = "new";
side: TSocketRequestSide;
shortid: string;
constructor(optionsArg: SocketRequestConstructorOptions) {
this.side = optionsArg.side;
this.shortid = optionsArg.shortid;
if(this.side === "requesting"){
allRequestingSocketRequests.add(this);
} else {
allRespondingSocketRequests.add(this);
};
};
respond(dataArg:ISocketFunctionResponseObject){
}
private _dispatch(){ // note: dispatch is private as it will be fired from the constructor
}
};

View File

@ -2,6 +2,7 @@ import "typings-global";
export import beautylog = require("beautylog");
export import lik = require("lik");
export import q = require("q");
export import shortid = require("shortid");
export import socketIo = require("socket.io");
export import socketIoClient = require("socket.io-client");
export import taskbuffer = require("taskbuffer");