smartsocket/dist/smartsocket.classes.socketfunction.js

53 lines
3.1 KiB
JavaScript
Raw Normal View History

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