69 lines
No EOL
3 KiB
JavaScript
69 lines
No EOL
3 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.PayloadDisassembler = void 0;
|
|
const subscribableStream_1 = require("../subscribableStream");
|
|
/**
|
|
* Base class streaming payload disassembling.
|
|
*/
|
|
class PayloadDisassembler {
|
|
/**
|
|
* Initializes a new instance of the [PayloadDisassembler](xref:botframework-streaming.PayloadDisassembler) class.
|
|
*
|
|
* @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) used to send the disassembled payload chunks.
|
|
* @param id The ID of this disassembler.
|
|
*/
|
|
constructor(sender, id) {
|
|
this.sender = sender;
|
|
this.id = id;
|
|
}
|
|
/**
|
|
* Serializes the item into the [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) that exposes the stream and length of the result.
|
|
*
|
|
* @param item The item to be serialized.
|
|
* @returns The stream containing the serialized item and the length of the stream.
|
|
*/
|
|
static serialize(item) {
|
|
const stream = new subscribableStream_1.SubscribableStream();
|
|
stream.write(JSON.stringify(item));
|
|
stream.end();
|
|
return { stream, streamLength: stream.length };
|
|
}
|
|
/**
|
|
* Begins the process of disassembling a payload and sending the resulting chunks to the [PayloadSender](xref:botframework-streaming.PayloadSender) to dispatch over the transport.
|
|
*
|
|
* @returns A completed Promise after the disassembled payload has been sent.
|
|
*/
|
|
disassemble() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const { stream, streamLength } = yield this.getStream();
|
|
this.stream = stream;
|
|
this.streamLength = streamLength;
|
|
return this.send();
|
|
});
|
|
}
|
|
/**
|
|
* Begins the process of disassembling a payload and signals the [PayloadSender](xref:botframework-streaming.PayloadSender).
|
|
*/
|
|
send() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const header = {
|
|
payloadType: this.payloadType,
|
|
payloadLength: this.streamLength,
|
|
id: this.id,
|
|
end: true,
|
|
};
|
|
this.sender.sendPayload(header, this.stream);
|
|
});
|
|
}
|
|
}
|
|
exports.PayloadDisassembler = PayloadDisassembler;
|
|
//# sourceMappingURL=payloadDisassembler.js.map
|