49 lines
3.0 KiB
JavaScript
49 lines
3.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.SocketFunction = void 0;
|
|
// 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 (const socketRoleArg of this.roles) {
|
|
this._notifyRole(socketRoleArg);
|
|
}
|
|
}
|
|
// STATIC
|
|
static getSocketFunctionByName(smartsocketRefArg, functionNameArg) {
|
|
return smartsocketRefArg.socketFunctions.find(socketFunctionArg => {
|
|
return socketFunctionArg.name === functionNameArg;
|
|
});
|
|
}
|
|
/**
|
|
* invokes the function of this SocketFunction
|
|
*/
|
|
async invoke(dataArg, socketConnectionArg) {
|
|
if (dataArg.funcName === this.name) {
|
|
const funcResponseData = {
|
|
funcName: this.name,
|
|
funcDataArg: await this.funcDef(dataArg.funcDataArg, socketConnectionArg)
|
|
};
|
|
return funcResponseData;
|
|
}
|
|
else {
|
|
throw new Error("SocketFunction.name does not match the data argument's .name!");
|
|
}
|
|
}
|
|
/**
|
|
* notifies a role about access to this SocketFunction
|
|
*/
|
|
_notifyRole(socketRoleArg) {
|
|
socketRoleArg.addSocketFunction(this);
|
|
}
|
|
}
|
|
exports.SocketFunction = SocketFunction;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRmdW5jdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc29ja2V0ZnVuY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBd0NBLGlCQUFpQj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