smartsocket/dist/smartsocket.classes.socketfunction.js

52 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-08-07 16:59:39 +00:00
"use strict";
2017-07-07 20:02:19 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-08-09 21:37:25 +00:00
const plugins = require("./smartsocket.plugins");
// import classes
const lik_1 = require("lik");
// 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
/**
* invokes the function of this SocketFunction
*/
invoke(dataArg) {
2017-07-07 20:02:19 +00:00
let done = plugins.smartq.defer();
if (dataArg.funcName === this.name) {
2018-03-15 01:29:40 +00:00
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!");
}
2016-08-09 21:37:25 +00:00
return done.promise;
2016-08-08 16:20:00 +00:00
}
2017-07-07 20:02:19 +00:00
/**
* notifies a role about access to this SocketFunction
*/
_notifyRole(socketRoleArg) {
socketRoleArg.addSocketFunction(this);
}
2016-08-07 16:59:39 +00:00
}
exports.SocketFunction = SocketFunction;
2018-03-15 01:29:40 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz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