64 lines
4.4 KiB
JavaScript
64 lines
4.4 KiB
JavaScript
"use strict";
|
|
const plugins = require("./smartsocket.plugins");
|
|
const helpers = require("./smartsocket.helpers");
|
|
// import classes
|
|
const lik_1 = require("lik");
|
|
;
|
|
;
|
|
//export objects
|
|
exports.allSocketRequests = new lik_1.Objectmap();
|
|
// export classes
|
|
class SocketRequest {
|
|
constructor(optionsArg) {
|
|
this.status = "new";
|
|
this.done = plugins.q.defer();
|
|
this.side = optionsArg.side;
|
|
this.shortid = optionsArg.shortId;
|
|
this.funcCallData = optionsArg.funcCallData;
|
|
this.originSocketConnection = optionsArg.originSocketConnection;
|
|
exports.allSocketRequests.add(this);
|
|
}
|
|
;
|
|
// requesting --------------------------
|
|
/**
|
|
* dispatches a socketrequest from the requesting to the receiving side
|
|
*/
|
|
dispatch() {
|
|
let requestData = {
|
|
funcCallData: this.funcCallData,
|
|
shortId: this.shortid
|
|
};
|
|
this.originSocketConnection.socket.emit("function", requestData);
|
|
return this.done.promise;
|
|
}
|
|
;
|
|
/**
|
|
* handles the response that is received by the requesting side
|
|
*/
|
|
handleResponse(responseDataArg) {
|
|
plugins.beautylog.log("handling response!");
|
|
this.done.resolve(responseDataArg.funcCallData);
|
|
exports.allSocketRequests.remove(this);
|
|
}
|
|
// responding --------------------------
|
|
/**
|
|
* creates the response on the responding side
|
|
*/
|
|
createResponse() {
|
|
let targetSocketFunction = helpers.getSocketFunctionByName(this.funcCallData.funcName);
|
|
plugins.beautylog.info(`invoking ${targetSocketFunction.name}`);
|
|
targetSocketFunction.invoke(this.funcCallData)
|
|
.then((resultData) => {
|
|
plugins.beautylog.log("got resultData. Sending it to requesting party.");
|
|
let requestData = {
|
|
funcCallData: resultData,
|
|
shortId: this.shortid
|
|
};
|
|
this.originSocketConnection.socket.emit("functionResponse", requestData);
|
|
exports.allSocketRequests.remove(this);
|
|
});
|
|
}
|
|
}
|
|
exports.SocketRequest = SocketRequest;
|
|
;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ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