structure update
This commit is contained in:
@ -19,8 +19,8 @@ export interface ISmartsocketClientOptions {
|
||||
|
||||
export class SmartsocketClient {
|
||||
socketConnection:SocketConnection;
|
||||
constructor(){
|
||||
|
||||
constructor(optionsArg:ISmartsocketClientOptions){
|
||||
// TODO: implement Socket init
|
||||
};
|
||||
serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){
|
||||
let socketRequest = new SocketRequest({
|
||||
@ -30,9 +30,9 @@ export class SmartsocketClient {
|
||||
funcCallData:{
|
||||
funcName: functionNameArg,
|
||||
funcDataArg:dataArg
|
||||
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch();
|
||||
}
|
||||
|
||||
}
|
@ -74,16 +74,18 @@ export class SocketConnection {
|
||||
let done = plugins.q.defer();
|
||||
if(this.authenticated){
|
||||
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) => {
|
||||
return socketFunctionArg.name === dataArg.funcName
|
||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||
});
|
||||
if(referencedFunction !== undefined){
|
||||
let localSocketRequest = new SocketRequest({
|
||||
side:"responding",
|
||||
originSocketConnection:this,
|
||||
shortId:dataArg.shortId,
|
||||
requestData:dataArg
|
||||
funcCallData:dataArg.funcCallData
|
||||
});
|
||||
localSocketRequest
|
||||
} else {
|
||||
plugins.beautylog.warn("function not existent or out of access scope");
|
||||
};
|
||||
|
@ -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
|
||||
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user