2016-08-09 09:42:21 +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");
|
2016-08-12 03:56:40 +00:00
|
|
|
const helpers = require("./smartsocket.helpers");
|
2016-08-09 09:42:21 +00:00
|
|
|
// import classes
|
|
|
|
const lik_1 = require("lik");
|
2017-07-07 20:02:19 +00:00
|
|
|
// export objects
|
2016-08-12 03:56:40 +00:00
|
|
|
exports.allSocketRequests = new lik_1.Objectmap();
|
2016-08-09 09:42:21 +00:00
|
|
|
// export classes
|
|
|
|
class SocketRequest {
|
|
|
|
constructor(optionsArg) {
|
2017-07-07 20:02:19 +00:00
|
|
|
this.status = 'new';
|
|
|
|
this.done = plugins.smartq.defer();
|
2016-08-09 09:42:21 +00:00
|
|
|
this.side = optionsArg.side;
|
2016-08-09 21:37:25 +00:00
|
|
|
this.shortid = optionsArg.shortId;
|
2016-08-12 03:56:40 +00:00
|
|
|
this.funcCallData = optionsArg.funcCallData;
|
2016-08-14 23:38:28 +00:00
|
|
|
this.originSocketConnection = optionsArg.originSocketConnection;
|
2016-08-12 03:56:40 +00:00
|
|
|
exports.allSocketRequests.add(this);
|
2016-08-09 09:42:21 +00:00
|
|
|
}
|
2016-08-12 03:56:40 +00:00
|
|
|
// requesting --------------------------
|
|
|
|
/**
|
|
|
|
* dispatches a socketrequest from the requesting to the receiving side
|
|
|
|
*/
|
2016-08-09 21:37:25 +00:00
|
|
|
dispatch() {
|
2016-08-12 03:56:40 +00:00
|
|
|
let requestData = {
|
|
|
|
funcCallData: this.funcCallData,
|
|
|
|
shortId: this.shortid
|
|
|
|
};
|
2017-07-07 20:02:19 +00:00
|
|
|
this.originSocketConnection.socket.emit('function', requestData);
|
2016-08-09 21:37:25 +00:00
|
|
|
return this.done.promise;
|
2016-08-09 14:33:56 +00:00
|
|
|
}
|
2016-08-12 03:56:40 +00:00
|
|
|
/**
|
|
|
|
* handles the response that is received by the requesting side
|
|
|
|
*/
|
2016-08-09 21:37:25 +00:00
|
|
|
handleResponse(responseDataArg) {
|
2017-07-07 20:02:19 +00:00
|
|
|
plugins.beautylog.log('handling response!');
|
2016-08-14 23:38:28 +00:00
|
|
|
this.done.resolve(responseDataArg.funcCallData);
|
2016-08-12 03:56:40 +00:00
|
|
|
exports.allSocketRequests.remove(this);
|
2016-08-09 14:33:56 +00:00
|
|
|
}
|
2016-08-12 03:56:40 +00:00
|
|
|
// responding --------------------------
|
|
|
|
/**
|
|
|
|
* creates the response on the responding side
|
|
|
|
*/
|
|
|
|
createResponse() {
|
|
|
|
let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
|
2016-08-14 23:38:28 +00:00
|
|
|
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
|
2018-03-15 01:29:40 +00:00
|
|
|
targetSocketFunction.invoke(this.funcCallData).then(resultData => {
|
2017-07-07 20:02:19 +00:00
|
|
|
plugins.beautylog.log('got resultData. Sending it to requesting party.');
|
2016-08-12 03:56:40 +00:00
|
|
|
let requestData = {
|
|
|
|
funcCallData: resultData,
|
|
|
|
shortId: this.shortid
|
|
|
|
};
|
2017-07-07 20:02:19 +00:00
|
|
|
this.originSocketConnection.socket.emit('functionResponse', requestData);
|
2016-08-12 03:56:40 +00:00
|
|
|
exports.allSocketRequests.remove(this);
|
|
|
|
});
|
2016-08-09 14:33:56 +00:00
|
|
|
}
|
2016-08-09 09:42:21 +00:00
|
|
|
}
|
|
|
|
exports.SocketRequest = SocketRequest;
|
2018-03-15 01:29:40 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0L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