2016-08-07 13:37:52 +00:00
|
|
|
import * as plugins from "./smartsocket.plugins";
|
|
|
|
|
|
|
|
// import classes
|
2016-08-07 16:59:39 +00:00
|
|
|
import { Stringmap } from "lik";
|
2016-08-07 13:37:52 +00:00
|
|
|
import { SocketRole } from "./smartsocket.classes.socketrole";
|
|
|
|
|
2016-08-09 09:42:21 +00:00
|
|
|
// export interfaces
|
|
|
|
|
|
|
|
export interface ISocketFunctionRequestObject {
|
2016-08-08 16:20:00 +00:00
|
|
|
functionName:string,
|
2016-08-09 09:42:21 +00:00
|
|
|
argumentObject:any,
|
|
|
|
shortId:string,
|
2016-08-08 16:20:00 +00:00
|
|
|
responseTimeout?:number
|
|
|
|
};
|
2016-08-07 13:37:52 +00:00
|
|
|
|
2016-08-09 09:42:21 +00:00
|
|
|
export interface ISocketFunctionResponseObject {
|
|
|
|
shortId:string;
|
|
|
|
argumentObject:any;
|
|
|
|
};
|
|
|
|
|
2016-08-07 13:37:52 +00:00
|
|
|
export interface SocketFunctionOptions {
|
|
|
|
name: string;
|
|
|
|
func: any;
|
|
|
|
roles: SocketRole[]; // all roles that are allowed to execute a SocketFunction
|
|
|
|
};
|
|
|
|
|
2016-08-09 09:42:21 +00:00
|
|
|
// export classes
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class SocketFunction respresents a function that can be transparently called using a SocketConnection
|
|
|
|
*/
|
2016-08-07 13:37:52 +00:00
|
|
|
export class SocketFunction {
|
|
|
|
name: string;
|
|
|
|
func: any;
|
|
|
|
roles: SocketRole[];
|
2016-08-08 16:20:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the constructor for SocketFunction
|
|
|
|
*/
|
2016-08-07 13:37:52 +00:00
|
|
|
constructor(optionsArg: SocketFunctionOptions) {
|
|
|
|
this.name = optionsArg.name;
|
|
|
|
this.func = optionsArg.func;
|
|
|
|
this.roles = optionsArg.roles;
|
2016-08-08 16:20:00 +00:00
|
|
|
for (let socketRoleArg of this.roles){
|
|
|
|
this._notifyRole(socketRoleArg);
|
|
|
|
}
|
2016-08-07 13:37:52 +00:00
|
|
|
};
|
2016-08-08 16:20:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* notifies a role about access to this SocketFunction
|
|
|
|
*/
|
|
|
|
private _notifyRole(socketRoleArg:SocketRole){
|
|
|
|
socketRoleArg.addSocketFunction(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-09 09:42:21 +00:00
|
|
|
* invokes the function of this SocketFunction
|
2016-08-08 16:20:00 +00:00
|
|
|
*/
|
2016-08-09 09:42:21 +00:00
|
|
|
invoke(dataArg:ISocketFunctionRequestObject){
|
2016-08-08 16:20:00 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-08-07 13:37:52 +00:00
|
|
|
}
|