botframework-streaming
Version:
Streaming library for the Microsoft Bot Framework
71 lines • 2.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamingRequest = 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 request type sent over Bot Framework Protocol 3 with Streaming Extensions transports, equivalent to HTTP request messages.
*/
class StreamingRequest {
constructor() {
/**
* List of associated streams.
*/
this.streams = [];
}
/**
* Creates a streaming request with the passed in method, path, and body.
*
* @param method The HTTP verb to use for this request.
* @param path Optional path where the resource can be found on the remote server.
* @param body Optional body to send to the remote server.
* @returns On success returns a streaming request with appropriate status code and body.
*/
static create(method, path, body) {
const request = new StreamingRequest();
request.verb = method;
request.path = path;
if (body) {
request.setBody(body);
}
return request;
}
/**
* Adds a new stream attachment to this streaming request.
*
* @param content The Http content to include in the new stream attachment.
*/
addStream(content) {
if (!content) {
throw new Error('Argument Undefined Exception: content undefined.');
}
this.streams.push(new httpContentStream_1.HttpContentStream(content));
}
/**
* Sets the contents of the body of this streamingRequest.
*
* @param body The JSON text to write to the body of the streamingRequest.
*/
setBody(body) {
if (typeof body === 'string') {
const stream = new subscribableStream_1.SubscribableStream();
stream.write(body, 'utf8');
this.addStream(new httpContentStream_1.HttpContent({
type: 'application/json; charset=utf-8',
contentLength: stream.length,
}, stream));
}
else if (typeof body === 'object') {
this.addStream(body);
}
}
}
exports.StreamingRequest = StreamingRequest;
//# sourceMappingURL=streamingRequest.js.map
;