smartsocket/dist/smartsocket.classes.socketfunction.js

57 lines
3.3 KiB
JavaScript

"use strict";
const plugins = require("./smartsocket.plugins");
// import classes
const lik_1 = require("lik");
;
;
// export objects
exports.allSocketFunctions = new lik_1.Objectmap();
// export classes
/**
* class that respresents a function that can be transparently called using a SocketConnection
*/
class SocketFunction {
/**
* the constructor for SocketFunction
*/
constructor(optionsArg) {
this.name = optionsArg.funcName;
this.funcDef = optionsArg.funcDef;
this.roles = optionsArg.allowedRoles;
for (let socketRoleArg of this.roles) {
this._notifyRole(socketRoleArg);
}
;
exports.allSocketFunctions.add(this); // map instance with Objectmap
}
;
/**
* notifies a role about access to this SocketFunction
*/
_notifyRole(socketRoleArg) {
socketRoleArg.addSocketFunction(this);
}
/**
* invokes the function of this SocketFunction
*/
invoke(dataArg) {
let done = plugins.q.defer();
if (dataArg.funcName === this.name) {
this.funcDef(dataArg.funcDataArg)
.then((resultData) => {
let funcResponseData = {
funcName: this.name,
funcDataArg: resultData
};
done.resolve(funcResponseData);
});
}
else {
throw new Error("SocketFunction.name does not match the data argument's .name!");
}
return done.promise;
}
;
}
exports.SocketFunction = SocketFunction;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQVkvQixDQUFDO0FBUUQsQ0FBQztBQVNGLGlCQUFpQjtBQUNOLDBCQUFrQixHQUFHLElBQUksZUFBUyxFQUFrQixDQUFDO0FBRWhFLGlCQUFpQjtBQUV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