2016-08-09 09:42:21 +00:00
|
|
|
"use strict";
|
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");
|
|
|
|
;
|
2016-08-09 21:37:25 +00:00
|
|
|
;
|
2016-08-09 09:42:21 +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) {
|
|
|
|
this.status = "new";
|
2016-08-09 21:37:25 +00:00
|
|
|
this.done = plugins.q.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
|
|
|
|
};
|
|
|
|
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) {
|
2016-08-14 23:38:28 +00:00
|
|
|
plugins.beautylog.log("handling response!");
|
|
|
|
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) => {
|
2016-08-14 23:38:28 +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
|
|
|
|
};
|
|
|
|
this.originSocketConnection.socket.emit("functionResponse", requestData);
|
|
|
|
exports.allSocketRequests.remove(this);
|
|
|
|
});
|
2016-08-09 14:33:56 +00:00
|
|
|
}
|
2016-08-09 09:42:21 +00:00
|
|
|
}
|
|
|
|
exports.SocketRequest = SocketRequest;
|
|
|
|
;
|
2016-08-14 23:38:28 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxN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