52 lines
3.3 KiB
JavaScript
52 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ij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