var Stormancer;
(function (Stormancer) {
var RequestContext = (function () {
/**
@class RequestContext
@classdesc Context object that provides informations about a running request.
@memberof Stormancer
@param {Stormancer.Packet} packet The Packet on which we create the RequestContext.
*/
function RequestContext(packet) {
this._didSendValues = false;
this.isComplete = false;
this._packet = packet;
this._requestId = packet.data.subarray(0, 2);
this.inputData = packet.data.subarray(2);
}
/**
Sends a partial response to the client through the request channel
@method Stormancer.RequestContext#send
@param {Uint8Array} data The data to send.
*/
RequestContext.prototype.send = function (data) {
if (this.isComplete) {
throw new Error("The request is already completed.");
}
this._didSendValues = true;
var dataToSend = new Uint8Array(2 + data.length);
dataToSend.set(this._requestId);
dataToSend.set(data, 2);
this._packet.connection.sendSystem(Stormancer.MessageIDTypes.ID_REQUEST_RESPONSE_MSG, dataToSend);
};
/**
Completes the request.
@method Stormancer.RequestContext#complete
*/
RequestContext.prototype.complete = function () {
var dataToSend = new Uint8Array(3);
dataToSend.set(this._requestId);
dataToSend.set(2, this._didSendValues ? 1 : 0);
this._packet.connection.sendSystem(Stormancer.MessageIDTypes.ID_REQUEST_RESPONSE_COMPLETE, dataToSend);
};
/**
Error on the request.
@method Stormancer.RequestContext#error
@param {Uint8Array} data The received data error.
*/
RequestContext.prototype.error = function (data) {
var dataToSend = new Uint8Array(2 + data.length);
dataToSend.set(this._requestId);
dataToSend.set(data, 2);
this._packet.connection.sendSystem(Stormancer.MessageIDTypes.ID_REQUEST_RESPONSE_ERROR, dataToSend);
};
return RequestContext;
})();
Stormancer.RequestContext = RequestContext;
})(Stormancer || (Stormancer = {}));
//# sourceMappingURL=RequestContext.js.map