smartsocket/dist/smartsocket.classes.socketfunction.js

53 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) {
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;
2017-07-07 20:02:19 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcn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