smartsocket/dist/smartsocket.classes.socketrequest.js

60 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-08-09 09:42:21 +00:00
"use strict";
2016-08-09 21:37:25 +00:00
const plugins = require("./smartsocket.plugins");
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
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;
this.funcCallData = optionsArg.funcCallData;
exports.allSocketRequests.add(this);
2016-08-09 09:42:21 +00:00
}
;
// requesting --------------------------
/**
* dispatches a socketrequest from the requesting to the receiving side
*/
2016-08-09 21:37:25 +00:00
dispatch() {
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;
}
;
/**
* handles the response that is received by the requesting side
*/
2016-08-09 21:37:25 +00:00
handleResponse(responseDataArg) {
this.done.resolve(responseDataArg);
exports.allSocketRequests.remove(this);
}
// responding --------------------------
/**
* creates the response on the responding side
*/
createResponse() {
let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
targetSocketFunction.invoke(this.funcCallData)
.then((resultData) => {
let requestData = {
funcCallData: resultData,
shortId: this.shortid
};
this.originSocketConnection.socket.emit("functionResponse", requestData);
exports.allSocketRequests.remove(this);
});
}
2016-08-09 09:42:21 +00:00
}
exports.SocketRequest = SocketRequest;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6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