UNPKG

botframework-streaming

Version:

Streaming library for the Microsoft Bot Framework

978 lines (968 loc) 350 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BFSE = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict"; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayloadAssembler = void 0; var subscribableStream_1 = require("../subscribableStream"); var payloads_1 = require("../payloads"); var contentStream_1 = require("../contentStream"); /** * Assembles payloads for streaming library. * * @internal */ var PayloadAssembler = /** @class */ (function () { /** * Initializes a new instance of the [PayloadAssembler](xref:botframework-streaming.PayloadAssembler) class. * * @param streamManager The [StreamManager](xref:botframework-streaming.StreamManager) managing the stream being assembled. * @param params Parameters for a streaming assembler. */ function PayloadAssembler(streamManager, params) { this.streamManager = streamManager; this._byteOrderMark = 0xfeff; this._utf = 'utf8'; if (params.header) { this.id = params.header.id; this.payloadType = params.header.payloadType; this.contentLength = params.header.payloadLength; this.end = params.header.end; } else { this.id = params.id; } if (!this.id) { throw Error('An ID must be supplied when creating an assembler.'); } this._onCompleted = params.onCompleted; } /** * Retrieves the assembler's payload as a stream. * * @returns A [SubscribableStream](xref:botframework-streaming.SubscribableStream) of the assembler's payload. */ PayloadAssembler.prototype.getPayloadStream = function () { if (!this.stream) { this.stream = this.createPayloadStream(); } return this.stream; }; /** * The action the assembler executes when new bytes are received on the incoming stream. * * @param header The stream's Header. * @param stream The incoming stream being assembled. * @param _contentLength The length of the stream, if finite. */ PayloadAssembler.prototype.onReceive = function (header, stream, _contentLength) { this.end = header.end; if (header.payloadType === payloads_1.PayloadTypes.response || header.payloadType === payloads_1.PayloadTypes.request) { this.process(stream).then().catch(); } else if (header.end) { stream.end(); } }; /** * Closes the assembler. */ PayloadAssembler.prototype.close = function () { this.streamManager.closeStream(this.id); }; /** * Creates a new [SubscribableStream](xref:botframework-streaming.SubscribableStream) instance. * * @returns The new stream ready for consumption. */ PayloadAssembler.prototype.createPayloadStream = function () { return new subscribableStream_1.SubscribableStream(); }; PayloadAssembler.prototype.payloadFromJson = function (json) { return JSON.parse(json.charCodeAt(0) === this._byteOrderMark ? json.slice(1) : json); }; PayloadAssembler.prototype.stripBOM = function (input) { return input.charCodeAt(0) === this._byteOrderMark ? input.slice(1) : input; }; PayloadAssembler.prototype.process = function (stream) { return __awaiter(this, void 0, void 0, function () { var streamData, streamDataAsString; return __generator(this, function (_a) { switch (_a.label) { case 0: streamData = stream.read(stream.length); if (!streamData) { return [2 /*return*/]; } streamDataAsString = streamData.toString(this._utf); if (!(this.payloadType === payloads_1.PayloadTypes.request)) return [3 /*break*/, 2]; return [4 /*yield*/, this.processRequest(streamDataAsString)]; case 1: _a.sent(); return [3 /*break*/, 4]; case 2: if (!(this.payloadType === payloads_1.PayloadTypes.response)) return [3 /*break*/, 4]; return [4 /*yield*/, this.processResponse(streamDataAsString)]; case 3: _a.sent(); _a.label = 4; case 4: return [2 /*return*/]; } }); }); }; PayloadAssembler.prototype.processResponse = function (streamDataAsString) { return __awaiter(this, void 0, void 0, function () { var responsePayload, receiveResponse; return __generator(this, function (_a) { switch (_a.label) { case 0: responsePayload = this.payloadFromJson(this.stripBOM(streamDataAsString)); receiveResponse = { streams: [], statusCode: responsePayload.statusCode }; return [4 /*yield*/, this.processStreams(responsePayload, receiveResponse)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; PayloadAssembler.prototype.processRequest = function (streamDataAsString) { return __awaiter(this, void 0, void 0, function () { var requestPayload, receiveRequest; return __generator(this, function (_a) { switch (_a.label) { case 0: requestPayload = this.payloadFromJson(streamDataAsString); receiveRequest = { streams: [], path: requestPayload.path, verb: requestPayload.verb }; return [4 /*yield*/, this.processStreams(requestPayload, receiveRequest)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; PayloadAssembler.prototype.processStreams = function (responsePayload, receiveResponse) { var _a; return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_b) { switch (_b.label) { case 0: (_a = responsePayload.streams) === null || _a === void 0 ? void 0 : _a.forEach(function (responseStream) { var _a; // There was a bug in how streams were handled. In .NET, the StreamDescription definiton mapped the // "type" JSON property to `contentType`, but in Typescript there was no mapping. This is a workaround // to resolve this inconsistency. // // .NET code: // https://github.com/microsoft/botbuilder-dotnet/blob/a79036ddf6625ec3fd68a6f7295886eb7831bc1c/libraries/Microsoft.Bot.Streaming/Payloads/Models/StreamDescription.cs#L28-L29 var contentType = (_a = responseStream.type) !== null && _a !== void 0 ? _a : responseStream.contentType; var contentAssembler = _this.streamManager.getPayloadAssembler(responseStream.id); contentAssembler.payloadType = contentType; contentAssembler.contentLength = responseStream.length; receiveResponse.streams.push(new contentStream_1.ContentStream(responseStream.id, contentAssembler)); }); return [4 /*yield*/, this._onCompleted(this.id, receiveResponse)]; case 1: _b.sent(); return [2 /*return*/]; } }); }); }; return PayloadAssembler; }()); exports.PayloadAssembler = PayloadAssembler; },{"../contentStream":2,"../payloads":16,"../subscribableStream":27}],2:[function(require,module,exports){ "use strict"; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContentStream = void 0; /** * A stream of fixed or infinite length containing content to be decoded. */ var ContentStream = /** @class */ (function () { /** * Initializes a new instance of the [ContentStream](xref:botframework-streaming.ContentStream) class. * * @param id The ID assigned to this instance. * @param assembler The [PayloadAssembler](xref:botframework-streaming.PayloadAssembler) assigned to this instance. */ function ContentStream(id, assembler) { if (!assembler) { throw Error('Null Argument Exception'); } this.id = id; this.assembler = assembler; } Object.defineProperty(ContentStream.prototype, "contentType", { /** * Gets the name of the type of the object contained within this [ContentStream](xref:botframework-streaming.ContentStream). * * @returns The [PayloadType](xref:botframework-streaming.PayloadType) of this [ContentStream](xref:botframework-streaming.ContentStream). */ get: function () { return this.assembler.payloadType; }, enumerable: false, configurable: true }); Object.defineProperty(ContentStream.prototype, "length", { /** * Gets the length of this [ContentStream](xref:botframework-streaming.ContentStream). * * @returns A number representing the length of this [ContentStream](xref:botframework-streaming.ContentStream). */ get: function () { return this.assembler.contentLength; }, enumerable: false, configurable: true }); /** * Gets the data contained within this [ContentStream](xref:botframework-streaming.ContentStream). * * @returns This [ContentStream's](xref:botframework-streaming.ContentStream) [SubscribableStream](xref:botframework-streaming.SubscribableStream). */ ContentStream.prototype.getStream = function () { if (!this.stream) { this.stream = this.assembler.getPayloadStream(); } return this.stream; }; /** * Closes the assembler. */ ContentStream.prototype.cancel = function () { this.assembler.close(); }; /** * Gets the [SubscribableStream](xref:botframework-streaming.SubscribableStream) content as a string. * * @returns A string Promise with [SubscribableStream](xref:botframework-streaming.SubscribableStream) content. */ ContentStream.prototype.readAsString = function () { return __awaiter(this, void 0, void 0, function () { var bufferArray; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.readAll()]; case 1: bufferArray = (_a.sent()).bufferArray; return [2 /*return*/, (bufferArray || []).map(function (result) { return result.toString('utf8'); }).join('')]; } }); }); }; /** * Gets the [SubscribableStream](xref:botframework-streaming.SubscribableStream) content as a typed JSON object. * * @returns A typed object Promise with `SubscribableStream` content. */ ContentStream.prototype.readAsJson = function () { return __awaiter(this, void 0, void 0, function () { var stringToParse; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.readAsString()]; case 1: stringToParse = _a.sent(); return [2 /*return*/, JSON.parse(stringToParse)]; } }); }); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any ContentStream.prototype.readAll = function () { return __awaiter(this, void 0, void 0, function () { var allData, count, stream, chunk, readToEnd; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: allData = []; count = 0; stream = this.getStream(); // populate the array with any existing buffers while (count < stream.length) { chunk = stream.read(stream.length); allData.push(chunk); count += chunk.length; } if (!(count < this.length)) return [3 /*break*/, 2]; readToEnd = new Promise(function (resolve) { // eslint-disable-next-line @typescript-eslint/no-explicit-any var callback = function (cs) { return function (chunk) { allData.push(chunk); count += chunk.length; if (count === cs.length) { resolve(true); } }; }; stream.subscribe(callback(_this)); }); return [4 /*yield*/, readToEnd]; case 1: _a.sent(); _a.label = 2; case 2: return [2 /*return*/, { bufferArray: allData, size: count }]; } }); }); }; return ContentStream; }()); exports.ContentStream = ContentStream; },{}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CancelDisassembler = void 0; /** * Streaming cancel disassembler. */ var CancelDisassembler = /** @class */ (function () { /** * Initializes a new instance of the [CancelDisassembler](xref:botframework-streaming.CancelDisassembler) class. * * @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) that this Cancel request will be sent by. * @param id The ID of the Stream to cancel. * @param payloadType The type of the Stream that is being cancelled. */ function CancelDisassembler(sender, id, payloadType) { this.sender = sender; this.id = id; this.payloadType = payloadType; } /** * Initiates the process of disassembling the request and signals the [PayloadSender](xref:botframework-streaming.PayloadSender) to begin sending. */ CancelDisassembler.prototype.disassemble = function () { var header = { payloadType: this.payloadType, payloadLength: 0, id: this.id, end: true, }; this.sender.sendPayload(header); }; return CancelDisassembler; }()); exports.CancelDisassembler = CancelDisassembler; },{}],4:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpContentStreamDisassembler = void 0; var payloadDisassembler_1 = require("./payloadDisassembler"); var payloads_1 = require("../payloads"); /** * Disassembler for Http content stream */ var HttpContentStreamDisassembler = /** @class */ (function (_super) { __extends(HttpContentStreamDisassembler, _super); /** * Initializes a new instance of the [HttpContentStreamDisassembler](xref:botframework-streaming.HttpContentStreamDisassembler) class. * * @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) to send the disassembled data to. * @param contentStream The [HttpContentStream](xref:botframework-streaming.HttpContentStream) to be disassembled. */ function HttpContentStreamDisassembler(sender, contentStream) { var _this = _super.call(this, sender, contentStream.id) || this; _this.payloadType = payloads_1.PayloadTypes.stream; _this.contentStream = contentStream; return _this; } /** * Gets the stream this disassembler is operating on. * * @returns An [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) with a Subscribable Strea. */ HttpContentStreamDisassembler.prototype.getStream = function () { return __awaiter(this, void 0, void 0, function () { var stream; return __generator(this, function (_a) { stream = this.contentStream.content.getStream(); return [2 /*return*/, { stream: stream, streamLength: stream.length }]; }); }); }; return HttpContentStreamDisassembler; }(payloadDisassembler_1.PayloadDisassembler)); exports.HttpContentStreamDisassembler = HttpContentStreamDisassembler; },{"../payloads":16,"./payloadDisassembler":5}],5:[function(require,module,exports){ "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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayloadDisassembler = void 0; var subscribableStream_1 = require("../subscribableStream"); /** * Base class streaming payload disassembling. */ var PayloadDisassembler = /** @class */ (function () { /** * 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. */ function PayloadDisassembler(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. */ PayloadDisassembler.serialize = function (item) { var stream = new subscribableStream_1.SubscribableStream(); stream.write(JSON.stringify(item)); stream.end(); return { stream: 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. */ PayloadDisassembler.prototype.disassemble = function () { return __awaiter(this, void 0, void 0, function () { var _a, stream, streamLength; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, this.getStream()]; case 1: _a = _b.sent(), stream = _a.stream, streamLength = _a.streamLength; this.stream = stream; this.streamLength = streamLength; return [2 /*return*/, this.send()]; } }); }); }; /** * Begins the process of disassembling a payload and signals the [PayloadSender](xref:botframework-streaming.PayloadSender). */ PayloadDisassembler.prototype.send = function () { return __awaiter(this, void 0, void 0, function () { var header; return __generator(this, function (_a) { header = { payloadType: this.payloadType, payloadLength: this.streamLength, id: this.id, end: true, }; this.sender.sendPayload(header, this.stream); return [2 /*return*/]; }); }); }; return PayloadDisassembler; }()); exports.PayloadDisassembler = PayloadDisassembler; },{"../subscribableStream":27}],6:[function(require,module,exports){ "use strict"; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestDisassembler = void 0; var payloadTypes_1 = require("../payloads/payloadTypes"); var payloadDisassembler_1 = require("./payloadDisassembler"); /** * Streaming request disassembler. */ var RequestDisassembler = /** @class */ (function (_super) { __extends(RequestDisassembler, _super); /** * Initializes a new instance of the [RequestDisassembler](xref:botframework-streaming.RequestDisassembler) class. * * @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) to send the disassembled data to. * @param id The ID of this disassembler. * @param request The request to be disassembled. */ function RequestDisassembler(sender, id, request) { var _this = _super.call(this, sender, id) || this; _this.request = request; _this.payloadType = payloadTypes_1.PayloadTypes.request; return _this; } /** * Gets the stream this disassembler is operating on. * * @returns An [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) with a Subscribable Stream. */ RequestDisassembler.prototype.getStream = function () { var _a, _b, _c, _d; return __awaiter(this, void 0, void 0, function () { var payload; return __generator(this, function (_e) { payload = { verb: (_a = this.request) === null || _a === void 0 ? void 0 : _a.verb, path: (_b = this.request) === null || _b === void 0 ? void 0 : _b.path, streams: [] }; (_d = (_c = this.request) === null || _c === void 0 ? void 0 : _c.streams) === null || _d === void 0 ? void 0 : _d.forEach(function (stream) { payload.streams.push(stream.description); }); return [2 /*return*/, payloadDisassembler_1.PayloadDisassembler.serialize(payload)]; }); }); }; return RequestDisassembler; }(payloadDisassembler_1.PayloadDisassembler)); exports.RequestDisassembler = RequestDisassembler; },{"../payloads/payloadTypes":19,"./payloadDisassembler":5}],7:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResponseDisassembler = void 0; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var payloadTypes_1 = require("../payloads/payloadTypes"); var payloadDisassembler_1 = require("./payloadDisassembler"); /** * Streaming response disassembler. */ var ResponseDisassembler = /** @class */ (function (_super) { __extends(ResponseDisassembler, _super); /** * Initializes a new instance of the [ResponseDisassembler](xref:botframework-streaming.ResponseDisassembler) class. * * @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) to send the disassembled data to. * @param id The ID of this disassembler. * @param response The response to be disassembled. */ function ResponseDisassembler(sender, id, response) { var _this = _super.call(this, sender, id) || this; _this.payloadType = payloadTypes_1.PayloadTypes.response; _this.response = response; return _this; } /** * Gets the stream this disassembler is operating on. * * @returns An [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) with a Subscribable Stream. */ ResponseDisassembler.prototype.getStream = function () { var _a; return __awaiter(this, void 0, void 0, function () { var payload; return __generator(this, function (_b) { payload = { statusCode: this.response.statusCode, streams: [] }; (_a = this.response.streams) === null || _a === void 0 ? void 0 : _a.forEach(function (_a) { var description = _a.description; payload.streams.push({ id: description.id, contentType: description.type, length: description.length, }); }); return [2 /*return*/, payloadDisassembler_1.PayloadDisassembler.serialize(payload)]; }); }); }; return ResponseDisassembler; }(payloadDisassembler_1.PayloadDisassembler)); exports.ResponseDisassembler = ResponseDisassembler; },{"../payloads/payloadTypes":19,"./payloadDisassembler":5}],8:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpContent = exports.HttpContentStream = void 0; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var protocol_base_1 = require("./utilities/protocol-base"); /** * An attachment contained within a StreamingRequest's stream collection, which itself contains any form of media item. */ var HttpContentStream = /** @class */ (function () { /** * Initializes a new instance of the [HttpContentStream](xref:botframework-streaming.HttpContentStream) class. * * @param content The [HttpContent](xref:botframework-streaming.HttpContent) to assign to the [HttpContentStream](xref:botframework-streaming.HttpContentStream). */ function HttpContentStream(content) { var _a, _b, _c, _d, _e, _f; this.content = content; this.id = protocol_base_1.generateGuid(); this.description = { id: this.id, type: (_c = (_b = (_a = this.content) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'unknown', length: (_f = (_e = (_d = this.content) === null || _d === void 0 ? void 0 : _d.headers) === null || _e === void 0 ? void 0 : _e.contentLength) !== null && _f !== void 0 ? _f : 0, }; } return HttpContentStream; }()); exports.HttpContentStream = HttpContentStream; /** * The HttpContent class that contains a [SubscribableStream](xref:botframework-streaming.SubscribableStream). */ var HttpContent = /** @class */ (function () { /** * Initializes a new instance of the [HttpContent](xref:botframework-streaming.HttpContent) class. * * @param headers The Streaming Http content header definition. * @param stream The stream of buffered data. */ function HttpContent(headers, stream) { this.headers = headers; this.stream = stream; } /** * Gets the data contained within this [HttpContent](xref:botframework-streaming.HttpContent). * * @returns This [HttpContent's](xref:botframework-streaming.HttpContent) [SubscribableStream](xref:botframework-streaming.SubscribableStream) member. */ HttpContent.prototype.getStream = function () { return this.stream; }; return HttpContent; }()); exports.HttpContent = HttpContent; },{"./utilities/protocol-base":28}],9:[function(require,module,exports){ "use strict"; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.WebSocketClient = exports.BrowserWebSocket = exports.SubscribableStream = exports.StreamingResponse = exports.StreamingRequest = exports.RequestHandler = exports.HttpContent = exports.ContentStream = void 0; var contentStream_1 = require("./contentStream"); Object.defineProperty(exports, "ContentStream", { enumerable: true, get: function () { return contentStream_1.ContentStream; } }); var httpContentStream_1 = require("./httpContentStream"); Object.defineProperty(exports, "HttpContent", { enumerable: true, get: function () { return httpContentStream_1.HttpContent; } }); var requestHandler_1 = require("./requestHandler"); Object.defineProperty(exports, "RequestHandler", { enumerable: true, get: function () { return requestHandler_1.RequestHandler; } }); var streamingRequest_1 = require("./streamingRequest"); Object.defineProperty(exports, "StreamingRequest", { enumerable: true, get: function () { return streamingRequest_1.StreamingRequest; } }); var streamingResponse_1 = require("./streamingResponse"); Object.defineProperty(exports, "StreamingResponse", { enumerable: true, get: function () { return streamingResponse_1.StreamingResponse; } }); var subscribableStream_1 = require("./subscribableStream"); Object.defineProperty(exports, "SubscribableStream", { enumerable: true, get: function () { return subscribableStream_1.SubscribableStream; } }); var index_browser_1 = require("./webSocket/index-browser"); Object.defineProperty(exports, "BrowserWebSocket", { enumerable: true, get: function () { return index_browser_1.BrowserWebSocket; } }); Object.defineProperty(exports, "WebSocketClient", { enumerable: true, get: function () { return index_browser_1.WebSocketClient; } }); },{"./contentStream":2,"./httpContentStream":8,"./requestHandler":24,"./streamingRequest":25,"./streamingResponse":26,"./subscribableStream":27,"./webSocket/index-browser":31}],10:[function(require,module,exports){ "use strict"; /** * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./payloadReceiver"), exports); __exportStar(require("./payloadSender"), exports); __exportStar(require("./transportDisconnectedEvent"), exports); __exportStar(require("./transportDisconnectedEventHandler"), exports); },{"./payloadReceiver":11,"./payloadSender":12,"./transportDisconnectedEvent":13,"./transportDisconnectedEventHandler":14}],11:[function(require,module,exports){ "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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y =