some more logic

request/response abstraction to make transparent function calls happen
This commit is contained in:
2016-08-09 16:33:56 +02:00
parent f670cae1f8
commit 5109964247
5 changed files with 61 additions and 12 deletions

View File

@ -78,10 +78,17 @@ export class SocketConnection {
return socketFunctionArg.name === dataArg.functionName
});
if(referencedFunction !== undefined){
referencedFunction.invoke(dataArg);
let localSocketRequest = new SocketRequest({
side:"responding",
shortid:dataArg.shortId,
requestData:dataArg
});
} else {
plugins.beautylog.warn("function not existent or out of access scope");
};
});
this.socket.on("functionResponse", (dataArg:ISocketFunctionRequestObject) => {
})
} else {
done.reject("socket needs to be authenticated first");

View File

@ -14,6 +14,8 @@ export type TSocketRequestSide = "requesting" | "responding";
export interface SocketRequestConstructorOptions {
side: TSocketRequestSide;
shortid: string;
requestData?: ISocketFunctionRequestObject;
responseData?:ISocketFunctionResponseObject;
};
//export objects
@ -25,19 +27,33 @@ export class SocketRequest {
status: TSocketRequestStatus = "new";
side: TSocketRequestSide;
shortid: string;
requestData: ISocketFunctionRequestObject;
responseData: ISocketFunctionResponseObject;
constructor(optionsArg: SocketRequestConstructorOptions) {
this.side = optionsArg.side;
this.shortid = optionsArg.shortid;
this.requestData = optionsArg.requestData;
this.responseData = optionsArg.responseData;
if(this.side === "requesting"){
allRequestingSocketRequests.add(this);
} else {
allRespondingSocketRequests.add(this);
};
};
respond(dataArg:ISocketFunctionResponseObject){
private _sendRequest(dataArg:ISocketFunctionRequestObject){
};
private _receiveRequest(dataArg:ISocketFunctionRequestObject){
};
private _sendResponse(dataArg:ISocketFunctionResponseObject){
}
private _dispatch(){ // note: dispatch is private as it will be fired from the constructor
private _receiveResponse(dataArg:ISocketFunctionResponseObject){
}
};
private _dispatch(dataArg:ISocketFunctionRequestObject){ // note: dispatch is private as it will be fired from the constructor
};
};