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}`);
|
2016-08-12 03:56: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;
|
2017-10-09 01:06:09 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXR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