structure update

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

View File

@@ -13,15 +13,8 @@ export type TSocketRequestStatus = "new" | "pending" | "finished";
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 {
side: TSocketRequestSide;
originSocketConnection:SocketConnection;
@@ -29,6 +22,15 @@ export interface SocketRequestConstructorOptions {
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 let allRequestingSocketRequests = new Objectmap<SocketRequest>();
export let allRespondingSocketRequests = new Objectmap<SocketRequest>();
@@ -40,7 +42,7 @@ export class SocketRequest {
shortid: string;
originSocketConnection:SocketConnection;
requestData: ISocketRequestDataObject;
responseData: ISocketRequestDataObject;
done = plugins.q.defer();
constructor(optionsArg: SocketRequestConstructorOptions) {
this.side = optionsArg.side;
this.shortid = optionsArg.shortId;
@@ -49,25 +51,23 @@ export class SocketRequest {
} else {
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
};
};