Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streaming] Pull out streaming bits from botbuilder and move to botframework-streaming #1348

Merged
merged 3 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions libraries/botbuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"dependencies": {
"@azure/ms-rest-js": "1.2.6",
"@types/node": "^10.12.18",
"botbuilder-core": "4.1.6",
"botframework-connector": "4.1.6",
"botframework-streaming": "4.1.6",
"filenamify": "^4.1.0",
"fs-extra": "^7.0.1"
},
Expand Down
286 changes: 0 additions & 286 deletions libraries/botbuilder/src/botFrameworkAdapter.ts

Large diffs are not rendered by default.

36 changes: 26 additions & 10 deletions libraries/botframework-streaming/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{
"name": "botframework-streaming",
"author": "Microsoft Corp.",
"description": "Streaming library for the Microsoft Bot Framework",
"version": "4.1.6",
"description": "",
"license": "MIT",
"keywords": [
"botbuilder",
"botframework",
"bots",
"chatbots",
"websockets",
"streaming"
],
"bugs": {
"url": "https://github.com/microsoft/botbuilder-js/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/botbuilder-js.git"
},
"main": "lib/index.js",
"typings": "lib/index.d.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@azure/ms-rest-js": "1.2.6",
"botbuilder": "4.1.6",
"botbuilder-core": "4.1.6",
"uuid": "^3.3.2",
"watershed": "^0.4.0",
"ws": "^7.1.2"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/node": "^10.12.18",
Expand All @@ -20,12 +42,6 @@
"tslint-microsoft-contrib": "^5.2.1",
"typescript": "3.1.1"
},
"dependencies": {
"promise.prototype.finally": "^3.1.0",
"uuid": "^3.3.2",
"watershed": "^0.4.0",
"ws": "^7.1.2"
},
"engines": {
"node": ">10.14"
},
Expand Down
11 changes: 11 additions & 0 deletions libraries/botframework-streaming/src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @module botframework-streaming
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

export * from './streamingAdapter';
export * from './streamingHttpClient';
export * from './tokenResolver';
656 changes: 656 additions & 0 deletions libraries/botframework-streaming/src/adapters/streamingAdapter.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { IStreamingTransportServer, StreamingRequest } from 'botframework-streaming';
import { WebResource, HttpOperationResponse, HttpClient } from '@azure/ms-rest-js';

export class StreamingHttpClient implements HttpClient {
private readonly server: IStreamingTransportServer;
/**
* Creates a new streaming Http client.
*
* @param server Transport server implementation to be used.
*/
public constructor(server: IStreamingTransportServer) {
if (!server) {
throw new Error(`StreamingHttpClient: Expected server.`);
}
this.server = server;
}
/**
* This function hides the default sendRequest of the HttpClient, replacing it
* with a version that takes the WebResource created by the BotFrameworkAdapter
* and converting it to a form that can be sent over a streaming transport.
*
* @param httpRequest The outgoing request created by the BotframeworkAdapter.
* @return The streaming transport compatible response to send back to the client.
*/
public async sendRequest(httpRequest: WebResource): Promise<HttpOperationResponse> {
if (!httpRequest) {
throw new Error('SendRequest invalid parameter: httpRequest should be provided');
}
const request = this.mapHttpRequestToProtocolRequest(httpRequest);
request.path = request.path.substring(request.path.indexOf('/v3'));
const res = await this.server.send(request);
return {
request: httpRequest,
status: res.statusCode,
headers: httpRequest.headers,
readableStreamBody: res.streams.length > 0 ? res.streams[0].getStream() : undefined
};
}
private mapHttpRequestToProtocolRequest(httpRequest: WebResource): StreamingRequest {
return StreamingRequest.create(httpRequest.method, httpRequest.url, httpRequest.body);
}
}
/**
* @module botframework-streaming
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { WebResource, HttpOperationResponse, HttpClient } from '@azure/ms-rest-js';

import { IStreamingTransportServer } from '../interfaces';
import { StreamingRequest } from '../streamingRequest';

export class StreamingHttpClient implements HttpClient {
private readonly server: IStreamingTransportServer;

/**
* Creates a new streaming Http client.
*
* @param server Transport server implementation to be used.
*/
public constructor(server: IStreamingTransportServer) {
if (!server) {
throw new Error(`StreamingHttpClient: Expected server.`);
}
this.server = server;
}

/**
* This function hides the default sendRequest of the HttpClient, replacing it
* with a version that takes the WebResource created by the BotFrameworkAdapter
* and converting it to a form that can be sent over a streaming transport.
*
* @param httpRequest The outgoing request created by the BotframeworkAdapter.
* @return The streaming transport compatible response to send back to the client.
*/
public async sendRequest(httpRequest: WebResource): Promise<HttpOperationResponse> {
if (!httpRequest) {
throw new Error('SendRequest invalid parameter: httpRequest should be provided');
}
const request = this.mapHttpRequestToProtocolRequest(httpRequest);
request.path = request.path.substring(request.path.indexOf('/v3'));
const res = await this.server.send(request);
return {
request: httpRequest,
status: res.statusCode,
headers: httpRequest.headers,
readableStreamBody: res.streams.length > 0 ? res.streams[0].getStream() : undefined
};
}

private mapHttpRequestToProtocolRequest(httpRequest: WebResource): StreamingRequest {
return StreamingRequest.create(httpRequest.method, httpRequest.url, httpRequest.body);
}
}
Loading