smartsocket/dist/smartsocket.classes.socketrequest.js

59 lines
4.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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.smartq.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsaURBQWlEO0FBQ2pELGlEQU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