53 lines
3.3 KiB
JavaScript
53 lines
3.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
|
}
|
|
/**
|
|
* invokes the function of this SocketFunction
|
|
*/
|
|
invoke(dataArg) {
|
|
let done = plugins.smartq.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;
|
|
}
|
|
/**
|
|
* notifies a role about access to this SocketFunction
|
|
*/
|
|
_notifyRole(socketRoleArg) {
|
|
socketRoleArg.addSocketFunction(this);
|
|
}
|
|
}
|
|
exports.SocketFunction = SocketFunction;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5nc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