2016-08-07 16:59:39 +00:00
|
|
|
"use strict";
|
2016-08-09 21:37:25 +00:00
|
|
|
const plugins = require("./smartsocket.plugins");
|
2016-08-12 03:56:40 +00:00
|
|
|
// import classes
|
|
|
|
const lik_1 = require("lik");
|
2016-08-09 09:42:21 +00:00
|
|
|
;
|
2016-08-12 03:56:40 +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;
|
2016-08-12 03:56:40 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-08-12 03:56:40 +00:00
|
|
|
;
|
|
|
|
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();
|
2016-08-12 03:56:40 +00:00
|
|
|
if (dataArg.funcName === this.name) {
|
|
|
|
this.funcDef(dataArg.funcDataArg)
|
|
|
|
.then((resultData) => {
|
2016-08-14 23:38:28 +00:00
|
|
|
let funcResponseData = {
|
|
|
|
funcName: this.name,
|
|
|
|
funcDataArg: resultData
|
|
|
|
};
|
|
|
|
done.resolve(funcResponseData);
|
2016-08-12 03:56:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
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;
|
2016-08-14 23:38:28 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsaUJBQWlCO0FBQ2pCLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQVkvQixDQUFDO0FBUUQsQ0FBQztBQVNGLGlCQUFpQjtBQUNOLDBCQUFrQixHQUFHLElBQUksZUFBUyxFQUFrQixDQUFDO0FBRWhFLGlCQUFpQjtBQUVqQjs7R0FFRztBQUNIO0lBS0k7O09BRUc7SUFDSCxZQUFZLFVBQTZDO1FBQ3JELElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSx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