structure update

This commit is contained in:
Philipp Kunz 2016-08-09 23:37:25 +02:00
parent 1f8e1fc7cb
commit 19a883c641
10 changed files with 129 additions and 97 deletions

View File

@ -1,6 +1,5 @@
/// <reference types="q" /> import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
import * as plugins from "./smartsocket.plugins"; import { SocketConnection } from "./smartsocket.classes.socketconnection";
import { ISocketFunctionRequestObject, ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction";
/** /**
* interface for class SmartsocketClient * interface for class SmartsocketClient
*/ */
@ -9,6 +8,7 @@ export interface ISmartsocketClientOptions {
url: string; url: string;
} }
export declare class SmartsocketClient { export declare class SmartsocketClient {
constructor(); socketConnection: SocketConnection;
dispatchFunctionRequest(dataArg: ISocketFunctionRequestObject): plugins.q.Promise<ISocketFunctionResponseObject>; constructor(optionsArg: ISmartsocketClientOptions);
serverCall(functionNameArg: string, dataArg: ISocketFunctionCall): void;
} }

View File

@ -1,15 +1,23 @@
"use strict"; "use strict";
const plugins = require("./smartsocket.plugins"); const plugins = require("./smartsocket.plugins");
const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest");
class SmartsocketClient { class SmartsocketClient {
constructor() { constructor(optionsArg) {
} // TODO: implement Socket init
dispatchFunctionRequest(dataArg) {
let done = plugins.q.defer();
let responseData;
done.resolve(responseData);
return done.promise;
} }
; ;
serverCall(functionNameArg, dataArg) {
let socketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
side: "requesting",
originSocketConnection: this.socketConnection,
shortId: plugins.shortid.generate(),
funcCallData: {
funcName: functionNameArg,
funcDataArg: dataArg
}
});
socketRequest.dispatch();
}
} }
exports.SmartsocketClient = SmartsocketClient; exports.SmartsocketClient = SmartsocketClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2V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UFPLEVBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxRQUFRLEVBQUU7WUFDbEMsWUFBWSxFQUFDO2dCQUNULFFBQVEsRUFBRSxlQUFlO2dCQUN6QixXQUFXLEVBQUMsT0FBTzthQUN0QjtTQUNKLENBQUMsQ0FBQztRQUNILGFBQWEsQ0FBQyxRQUFRLEVBQUUsQ0FBQztJQUM3QixDQUFDO0FBRUwsQ0FBQztBQWxCWSx5QkFBaUIsb0JBa0I3QixDQUFBIn0=

View File

@ -47,15 +47,18 @@ class SocketConnection {
let done = plugins.q.defer(); let done = plugins.q.defer();
if (this.authenticated) { if (this.authenticated) {
this.socket.on("function", (dataArg) => { this.socket.on("function", (dataArg) => {
// check if requested function is available to the socket's scope
let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => { let referencedFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.functionName; return socketFunctionArg.name === dataArg.funcCallData.funcName;
}); });
if (referencedFunction !== undefined) { if (referencedFunction !== undefined) {
let localSocketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({ let localSocketRequest = new smartsocket_classes_socketrequest_1.SocketRequest({
side: "responding", side: "responding",
shortid: dataArg.shortId, originSocketConnection: this,
requestData: dataArg shortId: dataArg.shortId,
funcCallData: dataArg.funcCallData
}); });
localSocketRequest;
} }
else { else {
plugins.beautylog.warn("function not existent or out of access scope"); plugins.beautylog.warn("function not existent or out of access scope");
@ -74,4 +77,4 @@ class SocketConnection {
} }
exports.SocketConnection = SocketConnection; exports.SocketConnection = SocketConnection;
; ;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIj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UFpQixDQUFDLElBQUksS0FBSyxPQUFPLENBQUMsWUFBWSxDQUFDLFFBQVEsQ0FBQztnQkFDcEUsQ0FBQyxDQUFDLENBQUM7Z0JBQ0gsRUFBRSxDQUFBLENBQUMsa0JBQWtCLEtBQUssU0FBUyxDQUFDLENBQUEsQ0FBQztvQkFDakMsSUFBSSxrQkFBa0IsR0FBRyxJQUFJLGlEQUFhLENBQUM7d0JBQ3ZDLElBQUksRUFBQyxZQUFZO3dCQUNqQixzQkFBc0IsRUFBQyxJQUFJO3dCQUMzQixPQUFPLEVBQUMsT0FBTyxDQUFDLE9BQU87d0JBQ3ZCLFlBQVksRUFBQyxPQUFPLENBQUMsWUFBWTtxQkFDcEMsQ0FBQyxDQUFDO29CQUNILGtCQUFrQixDQUFBO2dCQUN0QixDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNKLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLDhDQUE4QyxDQUFDLENBQUM7Z0JBQzNFLENBQUM7Z0JBQUEsQ0FBQztZQUNOLENBQUMsQ0FBQyxDQUFDO1lBQ0gsSUFBSSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsa0JBQWtCLEVBQUUsQ0FBQyxPQUFnQztZQUVwRSxDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLElBQUksQ0FBQyxNQUFNLENBQUMsd0NBQXdDLENBQUMsQ0FBQztRQUMxRCxDQUFDO1FBQUEsQ0FBQztRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7QUFDTCxDQUFDO0FBbEVZLHdCQUFnQixtQkFrRTVCLENBQUE7QUFBQSxDQUFDIn0=

View File

@ -1,21 +1,23 @@
/// <reference types="q" />
import * as plugins from "./smartsocket.plugins";
import { SocketRole } from "./smartsocket.classes.socketrole"; import { SocketRole } from "./smartsocket.classes.socketrole";
export interface ISocketFunctionRequestObject { /**
functionName: string; * interface of the contructor options of class SocketFunction
argumentObject: any; */
shortId: string; export interface ISocketFunctionOptions {
responseTimeout?: number; funcName: string;
} funcDef: any;
export interface ISocketFunctionResponseObject { allowedRoles: SocketRole[];
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 * interface of the Socket Function call
*/
export interface ISocketFunctionCall {
funcName: string;
funcDataArg: any;
}
/**
* class that respresents a function that can be transparently called using a SocketConnection
*/ */
export declare class SocketFunction { export declare class SocketFunction {
name: string; name: string;
@ -24,7 +26,7 @@ export declare class SocketFunction {
/** /**
* the constructor for SocketFunction * the constructor for SocketFunction
*/ */
constructor(optionsArg: SocketFunctionOptions); constructor(optionsArg: ISocketFunctionOptions);
/** /**
* notifies a role about access to this SocketFunction * notifies a role about access to this SocketFunction
*/ */
@ -32,5 +34,5 @@ export declare class SocketFunction {
/** /**
* invokes the function of this SocketFunction * invokes the function of this SocketFunction
*/ */
invoke(dataArg: ISocketFunctionRequestObject): void; invoke(dataArg: any): plugins.q.Promise<any>;
} }

View File

@ -1,19 +1,18 @@
"use strict"; "use strict";
; const plugins = require("./smartsocket.plugins");
;
; ;
// export classes // export classes
/** /**
* class SocketFunction respresents a function that can be transparently called using a SocketConnection * class that respresents a function that can be transparently called using a SocketConnection
*/ */
class SocketFunction { class SocketFunction {
/** /**
* the constructor for SocketFunction * the constructor for SocketFunction
*/ */
constructor(optionsArg) { constructor(optionsArg) {
this.name = optionsArg.name; this.name = optionsArg.funcName;
this.func = optionsArg.func; this.func = optionsArg.funcDef;
this.roles = optionsArg.roles; this.roles = optionsArg.allowedRoles;
for (let socketRoleArg of this.roles) { for (let socketRoleArg of this.roles) {
this._notifyRole(socketRoleArg); this._notifyRole(socketRoleArg);
} }
@ -29,8 +28,10 @@ class SocketFunction {
* invokes the function of this SocketFunction * invokes the function of this SocketFunction
*/ */
invoke(dataArg) { invoke(dataArg) {
let done = plugins.q.defer();
return done.promise;
} }
; ;
} }
exports.SocketFunction = SocketFunction; exports.SocketFunction = SocketFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQWFDLENBQUM7QUFLRCxDQUFDO0FBTUQsQ0FBQztBQUVGLGlCQUFpQjtBQUVqQjs7R0FFRztBQUNIO0lBS0k7O09BRUc7SUFDSCxZQUFZLFVBQWlDO1FBQ3pDLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLEtBQUssR0FBRyxVQUFVLENBQUMsS0FBSyxDQUFDO1FBQzlCLEdBQUcsQ0FBQyxDQUFDLElBQUksYUFBYSxJQUFJLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQSxDQUFDO1lBQ2xDLElBQUksQ0FBQyxXQUFXLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDcEMsQ0FBQztJQUNMLENBQUM7O0lBRUQ7O09BRUc7SUFDSyxXQUFXLENBQUMsYUFBd0I7UUFDeEMsYUFBYSxDQUFDLGlCQUFpQixDQUFDLElBQUksQ0FBQyxDQUFDO0lBQzFDLENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBQyxPQUFvQztJQUUzQyxDQUFDOztBQUVMLENBQUM7QUEvQlksc0JBQWMsaUJBK0IxQixDQUFBIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlI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unctionRequestObject, ISocketFunctionResponseObject } from "./smartsocket.classes.socketfunction"; /// <reference types="q" />
import * as plugins from "./smartsocket.plugins";
import { ISocketFunctionCall } from "./smartsocket.classes.socketfunction";
import { Objectmap } from "lik"; import { Objectmap } from "lik";
import { SocketConnection } from "./smartsocket.classes.socketconnection";
export declare type TSocketRequestStatus = "new" | "pending" | "finished"; export declare type TSocketRequestStatus = "new" | "pending" | "finished";
export declare type TSocketRequestSide = "requesting" | "responding"; export declare type TSocketRequestSide = "requesting" | "responding";
/**
* interface of constructor of class SocketRequest
*/
export interface SocketRequestConstructorOptions { export interface SocketRequestConstructorOptions {
side: TSocketRequestSide; side: TSocketRequestSide;
shortid: string; originSocketConnection: SocketConnection;
requestData?: ISocketFunctionRequestObject; shortId: string;
responseData?: ISocketFunctionResponseObject; funcCallData?: ISocketFunctionCall;
}
/**
* request object that is sent initially and may or may not receive a response
*/
export interface ISocketRequestDataObject {
funcCallData: ISocketFunctionCall;
shortId: string;
responseTimeout?: number;
} }
export declare let allRequestingSocketRequests: Objectmap<SocketRequest>; export declare let allRequestingSocketRequests: Objectmap<SocketRequest>;
export declare let allRespondingSocketRequests: Objectmap<SocketRequest>; export declare let allRespondingSocketRequests: Objectmap<SocketRequest>;
@ -14,12 +28,11 @@ export declare class SocketRequest {
status: TSocketRequestStatus; status: TSocketRequestStatus;
side: TSocketRequestSide; side: TSocketRequestSide;
shortid: string; shortid: string;
requestData: ISocketFunctionRequestObject; originSocketConnection: SocketConnection;
responseData: ISocketFunctionResponseObject; requestData: ISocketRequestDataObject;
done: plugins.q.Deferred<{}>;
constructor(optionsArg: SocketRequestConstructorOptions); constructor(optionsArg: SocketRequestConstructorOptions);
private _sendRequest(dataArg); dispatch(): plugins.q.Promise<{}>;
private _receiveRequest(dataArg); handleResponse(responseDataArg: ISocketRequestDataObject): void;
private _sendResponse(dataArg); respond(dataArg: any): void;
private _receiveResponse(dataArg);
private _dispatch(dataArg);
} }

View File

@ -1,7 +1,9 @@
"use strict"; "use strict";
const plugins = require("./smartsocket.plugins");
// import classes // import classes
const lik_1 = require("lik"); const lik_1 = require("lik");
; ;
;
//export objects //export objects
exports.allRequestingSocketRequests = new lik_1.Objectmap(); exports.allRequestingSocketRequests = new lik_1.Objectmap();
exports.allRespondingSocketRequests = new lik_1.Objectmap(); exports.allRespondingSocketRequests = new lik_1.Objectmap();
@ -9,10 +11,9 @@ exports.allRespondingSocketRequests = new lik_1.Objectmap();
class SocketRequest { class SocketRequest {
constructor(optionsArg) { constructor(optionsArg) {
this.status = "new"; this.status = "new";
this.done = plugins.q.defer();
this.side = optionsArg.side; this.side = optionsArg.side;
this.shortid = optionsArg.shortid; this.shortid = optionsArg.shortId;
this.requestData = optionsArg.requestData;
this.responseData = optionsArg.responseData;
if (this.side === "requesting") { if (this.side === "requesting") {
exports.allRequestingSocketRequests.add(this); exports.allRequestingSocketRequests.add(this);
} }
@ -20,23 +21,25 @@ class SocketRequest {
exports.allRespondingSocketRequests.add(this); exports.allRespondingSocketRequests.add(this);
} }
; ;
// build request and response dataArg
this.requestData = {
funcCallData: optionsArg.funcCallData,
shortId: optionsArg.shortId
};
} }
; ;
_sendRequest(dataArg) { dispatch() {
this.originSocketConnection.socket.emit("function", this.requestData);
return this.done.promise;
} }
; ;
_receiveRequest(dataArg) { handleResponse(responseDataArg) {
this.done.resolve(responseDataArg);
} }
; respond(dataArg) {
_sendResponse(dataArg) {
}
_receiveResponse(dataArg) {
}
;
_dispatch(dataArg) {
} }
; ;
} }
exports.SocketRequest = SocketRequest; exports.SocketRequest = SocketRequest;
; ;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGlu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7UUFBQSxDQUFDO1FBQ0YscUNBQXFDO1FBQ3JDLElBQUksQ0FBQyxXQUFXLEdBQUc7WUFDZixZQUFZLEVBQUMsVUFBVSxDQUFDLFlBQVk7WUFDcEMsT0FBTyxFQUFDLFVBQVUsQ0FBQyxPQUFPO1NBQzdCLENBQUE7SUFDTCxDQUFDOztJQUNELFFBQVE7UUFDSixJQUFJLENBQUMsc0JBQXNCLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFVLEVBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ3JFLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUM3QixDQUFDOztJQUNELGNBQWMsQ0FBQyxlQUF3QztRQUNuRCxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FBQztJQUN2QyxDQUFDO0lBQ0QsT0FBTyxDQUFDLE9BQU87SUFFZixDQUFDOztBQUNMLENBQUM7QUEvQlkscUJBQWEsZ0JBK0J6QixDQUFBO0FBQUEsQ0FBQyJ9

View File

@ -19,8 +19,8 @@ export interface ISmartsocketClientOptions {
export class SmartsocketClient { export class SmartsocketClient {
socketConnection:SocketConnection; socketConnection:SocketConnection;
constructor(){ constructor(optionsArg:ISmartsocketClientOptions){
// TODO: implement Socket init
}; };
serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){ serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){
let socketRequest = new SocketRequest({ let socketRequest = new SocketRequest({
@ -30,9 +30,9 @@ export class SmartsocketClient {
funcCallData:{ funcCallData:{
funcName: functionNameArg, funcName: functionNameArg,
funcDataArg:dataArg funcDataArg:dataArg
} }
}); });
socketRequest.dispatch();
} }
} }

View File

@ -74,16 +74,18 @@ export class SocketConnection {
let done = plugins.q.defer(); let done = plugins.q.defer();
if(this.authenticated){ if(this.authenticated){
this.socket.on("function", (dataArg:ISocketRequestDataObject) => { this.socket.on("function", (dataArg:ISocketRequestDataObject) => {
// check if requested function is available to the socket's scope
let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => { let referencedFunction:SocketFunction = this.role.allowedFunctions.find((socketFunctionArg) => {
return socketFunctionArg.name === dataArg.funcName return socketFunctionArg.name === dataArg.funcCallData.funcName;
}); });
if(referencedFunction !== undefined){ if(referencedFunction !== undefined){
let localSocketRequest = new SocketRequest({ let localSocketRequest = new SocketRequest({
side:"responding", side:"responding",
originSocketConnection:this, originSocketConnection:this,
shortId:dataArg.shortId, shortId:dataArg.shortId,
requestData:dataArg funcCallData:dataArg.funcCallData
}); });
localSocketRequest
} else { } else {
plugins.beautylog.warn("function not existent or out of access scope"); plugins.beautylog.warn("function not existent or out of access scope");
}; };

View File

@ -13,15 +13,8 @@ export type TSocketRequestStatus = "new" | "pending" | "finished";
export type TSocketRequestSide = "requesting" | "responding"; export type TSocketRequestSide = "requesting" | "responding";
/** /**
* request object that is sent initially and may or may not receive a response * interface of constructor of class SocketRequest
*/ */
export interface ISocketRequestDataObject {
funcName:string,
funcDataArg:any,
shortId:string,
responseTimeout?:number
};
export interface SocketRequestConstructorOptions { export interface SocketRequestConstructorOptions {
side: TSocketRequestSide; side: TSocketRequestSide;
originSocketConnection:SocketConnection; originSocketConnection:SocketConnection;
@ -29,6 +22,15 @@ export interface SocketRequestConstructorOptions {
funcCallData?: ISocketFunctionCall; funcCallData?: ISocketFunctionCall;
}; };
/**
* request object that is sent initially and may or may not receive a response
*/
export interface ISocketRequestDataObject {
funcCallData:ISocketFunctionCall;
shortId:string;
responseTimeout?:number;
};
//export objects //export objects
export let allRequestingSocketRequests = new Objectmap<SocketRequest>(); export let allRequestingSocketRequests = new Objectmap<SocketRequest>();
export let allRespondingSocketRequests = new Objectmap<SocketRequest>(); export let allRespondingSocketRequests = new Objectmap<SocketRequest>();
@ -40,7 +42,7 @@ export class SocketRequest {
shortid: string; shortid: string;
originSocketConnection:SocketConnection; originSocketConnection:SocketConnection;
requestData: ISocketRequestDataObject; requestData: ISocketRequestDataObject;
responseData: ISocketRequestDataObject; done = plugins.q.defer();
constructor(optionsArg: SocketRequestConstructorOptions) { constructor(optionsArg: SocketRequestConstructorOptions) {
this.side = optionsArg.side; this.side = optionsArg.side;
this.shortid = optionsArg.shortId; this.shortid = optionsArg.shortId;
@ -49,25 +51,23 @@ export class SocketRequest {
} else { } else {
allRespondingSocketRequests.add(this); allRespondingSocketRequests.add(this);
}; };
// build request and response dataArg
this.requestData = {
funcCallData:optionsArg.funcCallData,
shortId:optionsArg.shortId
}
}; };
/**
respond(dataArg){ *
*/
dispatch(){
this.originSocketConnection.socket.emit("function",this.requestData);
return this.done.promise;
};
handleResponse(responseDataArg:ISocketRequestDataObject){
this.done.resolve(responseDataArg);
}
createResponse(){
} }
// private functions
private _sendRequest(dataArg:ISocketRequestDataObject){
};
private _receiveRequest(dataArg:ISocketRequestDataObject){
};
private _sendResponse(dataArg:ISocketRequestDataObject){
}
private _receiveResponse(dataArg:ISocketRequestDataObject){
};
private _dispatch(dataArg:ISocketRequestDataObject){ // note: dispatch is private as it will be fired from the constructor
};
}; };