botframework-streaming
Version:
Streaming library for the Microsoft Bot Framework
58 lines • 2.02 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingResponse = void 0;
/**
* @module botframework-streaming
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const httpContentStream_1 = require("./httpContentStream");
const subscribableStream_1 = require("./subscribableStream");
/**
* The basic response type sent over Bot Framework Protocol 3 with Streaming Extensions transports, equivalent to HTTP response messages.
*/
class StreamingResponse {
constructor() {
this.streams = [];
}
/**
* Creates a streaming response with the passed in method, path, and body.
*
* @param statusCode The HTTP verb to use for this request.
* @param body Optional body containing additional information.
* @returns A streaming response with the appropriate statuscode and passed in body.
*/
static create(statusCode, body) {
const response = new StreamingResponse();
response.statusCode = statusCode;
if (body) {
response.addStream(body);
}
return response;
}
/**
* Adds a new stream attachment to this streaming request.
*
* @param content The Http content to include in the new stream attachment.
*/
addStream(content) {
this.streams.push(new httpContentStream_1.HttpContentStream(content));
}
/**
* Sets the contents of the body of this streaming response.
*
* @param body The JSON text to write to the body of the streaming response.
*/
setBody(body) {
const stream = new subscribableStream_1.SubscribableStream();
stream.write(JSON.stringify(body), 'utf8');
this.addStream(new httpContentStream_1.HttpContent({
type: 'application/json; charset=utf-8',
contentLength: stream.length,
}, stream));
}
}
exports.StreamingResponse = StreamingResponse;
//# sourceMappingURL=streamingResponse.js.map
;