From 2274a3fb0229204ccb9cb950c468249e494e5bcb Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Sat, 12 Oct 2019 15:42:47 -0700 Subject: [PATCH 01/32] Streaming: Rename botframework-streaming-extensions -> botframework-streaming --- lerna.json | 2 +- libraries/botbuilder-streaming-extensions/package.json | 2 +- .../src/BotFrameworkStreamingAdapter.ts | 2 +- .../.gitignore | 0 .../.nycrc | 0 .../README.md | 2 +- .../package.json | 4 ++-- .../src/Assemblers/PayloadAssembler.ts | 2 +- .../src/Assemblers/index.ts | 2 +- .../src/ContentStream.ts | 2 +- .../src/Disassemblers/CancelDisassembler.ts | 2 +- .../src/Disassemblers/HttpContentStreamDisassembler.ts | 2 +- .../src/Disassemblers/PayloadDisassembler.ts | 2 +- .../src/Disassemblers/RequestDisassembler.ts | 2 +- .../src/Disassemblers/ResponseDisassembler.ts | 2 +- .../src/Disassemblers/index.ts | 2 +- .../src/HttpContentStream.ts | 2 +- .../src/Interfaces/IAssemblerParams.ts | 2 +- .../src/Interfaces/IHeader.ts | 2 +- .../src/Interfaces/IHttpContentHeaders.ts | 2 +- .../src/Interfaces/IReceiveRequest.ts | 2 +- .../src/Interfaces/IReceiveResponse.ts | 2 +- .../src/Interfaces/IRequestPayload.ts | 2 +- .../src/Interfaces/IResponsePayload.ts | 2 +- .../src/Interfaces/ISendPacket.ts | 2 +- .../src/Interfaces/ISocket.ts | 2 +- .../src/Interfaces/IStreamDescription.ts | 2 +- .../src/Interfaces/IStreamWrapper.ts | 2 +- .../src/Interfaces/IStreamingTransportClient.ts | 2 +- .../src/Interfaces/IStreamingTransportServer.ts | 2 +- .../src/Interfaces/ITransport.ts | 2 +- .../src/Interfaces/ITransportReceiver.ts | 2 +- .../src/Interfaces/ITransportSender.ts | 2 +- .../src/Interfaces/index.ts | 2 +- .../src/NamedPipe/NamedPipeClient.ts | 2 +- .../src/NamedPipe/NamedPipeServer.ts | 2 +- .../src/NamedPipe/NamedPipeTransport.ts | 2 +- .../src/NamedPipe/index.ts | 2 +- .../src/PayloadTransport/PayloadReceiver.ts | 2 +- .../src/PayloadTransport/PayloadSender.ts | 2 +- .../src/PayloadTransport/TransportDisconnectedEventArgs.ts | 2 +- .../src/PayloadTransport/TransportDisconnectedEventHandler.ts | 2 +- .../src/PayloadTransport/index.ts | 2 +- .../src/Payloads/HeaderSerializer.ts | 2 +- .../src/Payloads/PayloadAssemblerManager.ts | 2 +- .../src/Payloads/PayloadConstants.ts | 2 +- .../src/Payloads/PayloadTypes.ts | 2 +- .../src/Payloads/RequestManager.ts | 2 +- .../src/Payloads/SendOperations.ts | 2 +- .../src/Payloads/StreamManager.ts | 2 +- .../src/Payloads/index.ts | 2 +- .../src/ProtocolAdapter.ts | 2 +- .../src/RequestHandler.ts | 2 +- .../src/StreamingRequest.ts | 2 +- .../src/StreamingResponse.ts | 2 +- .../src/SubscribableStream.ts | 2 +- .../src/Utilities/index.ts | 2 +- .../src/Utilities/protocol-base.ts | 2 +- .../src/WebSocket/BrowserWebSocket.ts | 2 +- .../src/WebSocket/NodeWebSocket.ts | 2 +- .../src/WebSocket/WebSocketClient.ts | 2 +- .../src/WebSocket/WebSocketServer.ts | 2 +- .../src/WebSocket/WebSocketTransport.ts | 2 +- .../src/WebSocket/index.ts | 2 +- .../src/index.ts | 2 +- .../tests/Assembler.test.js | 0 .../tests/ContentStream.test.js | 0 .../tests/Disassembler.test.js | 0 .../tests/HeaderSerializer.test.js | 0 .../tests/NamedPipe.test.js | 0 .../tests/PayloadSender.test.js | 0 .../tests/ProtocolAdapter.test.js | 0 .../tests/RequestManager.test.js | 0 .../tests/SendOperations.test.js | 0 .../tests/StreamManager.test.js | 0 .../tests/StreamingRequest.test.js | 0 .../tests/StreamingResponse.test.js | 0 .../tests/SubscribableStream.test.js | 0 .../tests/TransportConstants.test.js | 0 .../tests/WebSocket.test.js | 0 .../tests/mocha.opts | 0 .../tsconfig.json | 0 82 files changed, 64 insertions(+), 64 deletions(-) rename libraries/{botframework-streaming-extensions => botframework-streaming}/.gitignore (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/.nycrc (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/README.md (92%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/package.json (92%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Assemblers/PayloadAssembler.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Assemblers/index.ts (73%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/ContentStream.ts (94%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/CancelDisassembler.ts (91%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/HttpContentStreamDisassembler.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/PayloadDisassembler.ts (94%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/RequestDisassembler.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/ResponseDisassembler.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Disassemblers/index.ts (84%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/HttpContentStream.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IAssemblerParams.ts (81%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IHeader.ts (79%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IHttpContentHeaders.ts (78%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IReceiveRequest.ts (88%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IReceiveResponse.ts (81%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IRequestPayload.ts (82%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IResponsePayload.ts (82%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/ISendPacket.ts (84%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/ISocket.ts (89%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IStreamDescription.ts (78%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IStreamWrapper.ts (82%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IStreamingTransportClient.ts (88%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/IStreamingTransportServer.ts (88%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/ITransport.ts (76%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/ITransportReceiver.ts (82%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/ITransportSender.ts (81%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Interfaces/index.ts (84%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/NamedPipe/NamedPipeClient.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/NamedPipe/NamedPipeServer.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/NamedPipe/NamedPipeTransport.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/NamedPipe/index.ts (79%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/PayloadTransport/PayloadReceiver.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/PayloadTransport/PayloadSender.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/PayloadTransport/TransportDisconnectedEventArgs.ts (85%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/PayloadTransport/TransportDisconnectedEventHandler.ts (84%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/PayloadTransport/index.ts (85%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/HeaderSerializer.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/PayloadAssemblerManager.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/PayloadConstants.ts (80%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/PayloadTypes.ts (80%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/RequestManager.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/SendOperations.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/StreamManager.ts (94%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Payloads/index.ts (85%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/ProtocolAdapter.ts (97%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/RequestHandler.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/StreamingRequest.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/StreamingResponse.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/SubscribableStream.ts (93%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Utilities/index.ts (73%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/Utilities/protocol-base.ts (78%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/BrowserWebSocket.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/NodeWebSocket.ts (95%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/WebSocketClient.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/WebSocketServer.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/WebSocketTransport.ts (96%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/WebSocket/index.ts (84%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/src/index.ts (92%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/Assembler.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/ContentStream.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/Disassembler.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/HeaderSerializer.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/NamedPipe.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/PayloadSender.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/ProtocolAdapter.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/RequestManager.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/SendOperations.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/StreamManager.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/StreamingRequest.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/StreamingResponse.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/SubscribableStream.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/TransportConstants.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/WebSocket.test.js (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tests/mocha.opts (100%) rename libraries/{botframework-streaming-extensions => botframework-streaming}/tsconfig.json (100%) diff --git a/lerna.json b/lerna.json index 099e53bfe3..990d50ae59 100644 --- a/lerna.json +++ b/lerna.json @@ -13,7 +13,7 @@ "libraries/botframework-schema", "libraries/functional-tests", "libraries/testbot", - "libraries/botframework-streaming-extensions", + "libraries/botframework-streaming", "libraries/botbuilder-streaming-extensions", "transcripts" ], diff --git a/libraries/botbuilder-streaming-extensions/package.json b/libraries/botbuilder-streaming-extensions/package.json index 2057c0d3f2..caae677b5e 100644 --- a/libraries/botbuilder-streaming-extensions/package.json +++ b/libraries/botbuilder-streaming-extensions/package.json @@ -23,7 +23,7 @@ "botbuilder-core": "~4.5.1", "botframework-connector": "~4.5.1", "botframework-schema": "~4.5.1", - "botframework-streaming-extensions": "0.0.1", + "botframework-streaming": "~4.6.1", "promise.prototype.finally": "^3.1.0", "uuid": "^3.3.2", "watershed": "^0.4.0" diff --git a/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts b/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts index 74f9aa9ad1..298fe3cb1c 100644 --- a/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts +++ b/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts @@ -11,7 +11,7 @@ import { ConnectorClient, JwtTokenValidation, MicrosoftAppCredentials, SimpleCre import { Activity, ActivityTypes } from 'botframework-schema'; import * as os from 'os'; import { ISocket, IStreamingTransportServer, IReceiveRequest, NamedPipeServer, NodeWebSocket, - RequestHandler, StreamingResponse, WebSocketServer, StreamingRequest } from 'botframework-streaming-extensions'; //TODO: When integration layer is moved this will need to reference the external library. + RequestHandler, StreamingResponse, WebSocketServer, StreamingRequest } from 'botframework-streaming'; //TODO: When integration layer is moved this will need to reference the external library. import { HttpClient, HttpOperationResponse, WebResource } from '@azure/ms-rest-js'; import { Watershed } from 'watershed'; import { Request, ServerUpgradeResponse } from 'restify'; diff --git a/libraries/botframework-streaming-extensions/.gitignore b/libraries/botframework-streaming/.gitignore similarity index 100% rename from libraries/botframework-streaming-extensions/.gitignore rename to libraries/botframework-streaming/.gitignore diff --git a/libraries/botframework-streaming-extensions/.nycrc b/libraries/botframework-streaming/.nycrc similarity index 100% rename from libraries/botframework-streaming-extensions/.nycrc rename to libraries/botframework-streaming/.nycrc diff --git a/libraries/botframework-streaming-extensions/README.md b/libraries/botframework-streaming/README.md similarity index 92% rename from libraries/botframework-streaming-extensions/README.md rename to libraries/botframework-streaming/README.md index d1ed670bb1..01c561faaf 100644 --- a/libraries/botframework-streaming-extensions/README.md +++ b/libraries/botframework-streaming/README.md @@ -9,7 +9,7 @@ This library contains the core of Bot Framework Streaming Extensions, which exte To add the latest published version of this package to your bot: ```bash -npm install --save botframework-streaming-extensions +npm install --save botframework-streaming ``` #### Use the Daily Build diff --git a/libraries/botframework-streaming-extensions/package.json b/libraries/botframework-streaming/package.json similarity index 92% rename from libraries/botframework-streaming-extensions/package.json rename to libraries/botframework-streaming/package.json index edc625c4be..30267b65aa 100644 --- a/libraries/botframework-streaming-extensions/package.json +++ b/libraries/botframework-streaming/package.json @@ -1,6 +1,6 @@ { - "name": "botframework-streaming-extensions", - "version": "0.0.1", + "name": "botframework-streaming", + "version": "4.6.1", "description": "", "main": "lib/index.js", "typings": "lib/index.d.js", diff --git a/libraries/botframework-streaming-extensions/src/Assemblers/PayloadAssembler.ts b/libraries/botframework-streaming/src/Assemblers/PayloadAssembler.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/Assemblers/PayloadAssembler.ts rename to libraries/botframework-streaming/src/Assemblers/PayloadAssembler.ts index 64796906bf..db5873f1e8 100644 --- a/libraries/botframework-streaming-extensions/src/Assemblers/PayloadAssembler.ts +++ b/libraries/botframework-streaming/src/Assemblers/PayloadAssembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Assemblers/index.ts b/libraries/botframework-streaming/src/Assemblers/index.ts similarity index 73% rename from libraries/botframework-streaming-extensions/src/Assemblers/index.ts rename to libraries/botframework-streaming/src/Assemblers/index.ts index f72e965063..f892ea9f65 100644 --- a/libraries/botframework-streaming-extensions/src/Assemblers/index.ts +++ b/libraries/botframework-streaming/src/Assemblers/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/ContentStream.ts b/libraries/botframework-streaming/src/ContentStream.ts similarity index 94% rename from libraries/botframework-streaming-extensions/src/ContentStream.ts rename to libraries/botframework-streaming/src/ContentStream.ts index a3ced78805..2b1d96d742 100644 --- a/libraries/botframework-streaming-extensions/src/ContentStream.ts +++ b/libraries/botframework-streaming/src/ContentStream.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/CancelDisassembler.ts b/libraries/botframework-streaming/src/Disassemblers/CancelDisassembler.ts similarity index 91% rename from libraries/botframework-streaming-extensions/src/Disassemblers/CancelDisassembler.ts rename to libraries/botframework-streaming/src/Disassemblers/CancelDisassembler.ts index 2480579253..69473a2e96 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/CancelDisassembler.ts +++ b/libraries/botframework-streaming/src/Disassemblers/CancelDisassembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/HttpContentStreamDisassembler.ts b/libraries/botframework-streaming/src/Disassemblers/HttpContentStreamDisassembler.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/Disassemblers/HttpContentStreamDisassembler.ts rename to libraries/botframework-streaming/src/Disassemblers/HttpContentStreamDisassembler.ts index 03831046b7..03c5cecddc 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/HttpContentStreamDisassembler.ts +++ b/libraries/botframework-streaming/src/Disassemblers/HttpContentStreamDisassembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/PayloadDisassembler.ts b/libraries/botframework-streaming/src/Disassemblers/PayloadDisassembler.ts similarity index 94% rename from libraries/botframework-streaming-extensions/src/Disassemblers/PayloadDisassembler.ts rename to libraries/botframework-streaming/src/Disassemblers/PayloadDisassembler.ts index 774c4a73a4..c4302cf006 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/PayloadDisassembler.ts +++ b/libraries/botframework-streaming/src/Disassemblers/PayloadDisassembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/RequestDisassembler.ts b/libraries/botframework-streaming/src/Disassemblers/RequestDisassembler.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/Disassemblers/RequestDisassembler.ts rename to libraries/botframework-streaming/src/Disassemblers/RequestDisassembler.ts index 33e466e42c..5c358a7a20 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/RequestDisassembler.ts +++ b/libraries/botframework-streaming/src/Disassemblers/RequestDisassembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/ResponseDisassembler.ts b/libraries/botframework-streaming/src/Disassemblers/ResponseDisassembler.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/Disassemblers/ResponseDisassembler.ts rename to libraries/botframework-streaming/src/Disassemblers/ResponseDisassembler.ts index 254d9a9229..ac7f846bc3 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/ResponseDisassembler.ts +++ b/libraries/botframework-streaming/src/Disassemblers/ResponseDisassembler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Disassemblers/index.ts b/libraries/botframework-streaming/src/Disassemblers/index.ts similarity index 84% rename from libraries/botframework-streaming-extensions/src/Disassemblers/index.ts rename to libraries/botframework-streaming/src/Disassemblers/index.ts index c841b12c53..da0b60e3f1 100644 --- a/libraries/botframework-streaming-extensions/src/Disassemblers/index.ts +++ b/libraries/botframework-streaming/src/Disassemblers/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/HttpContentStream.ts b/libraries/botframework-streaming/src/HttpContentStream.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/HttpContentStream.ts rename to libraries/botframework-streaming/src/HttpContentStream.ts index 03c1fb5c6b..6ec27ce61e 100644 --- a/libraries/botframework-streaming-extensions/src/HttpContentStream.ts +++ b/libraries/botframework-streaming/src/HttpContentStream.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IAssemblerParams.ts b/libraries/botframework-streaming/src/Interfaces/IAssemblerParams.ts similarity index 81% rename from libraries/botframework-streaming-extensions/src/Interfaces/IAssemblerParams.ts rename to libraries/botframework-streaming/src/Interfaces/IAssemblerParams.ts index c98f19b6f2..4fbc4e3b15 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IAssemblerParams.ts +++ b/libraries/botframework-streaming/src/Interfaces/IAssemblerParams.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IHeader.ts b/libraries/botframework-streaming/src/Interfaces/IHeader.ts similarity index 79% rename from libraries/botframework-streaming-extensions/src/Interfaces/IHeader.ts rename to libraries/botframework-streaming/src/Interfaces/IHeader.ts index d8eb2cca55..c41410dd00 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IHeader.ts +++ b/libraries/botframework-streaming/src/Interfaces/IHeader.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IHttpContentHeaders.ts b/libraries/botframework-streaming/src/Interfaces/IHttpContentHeaders.ts similarity index 78% rename from libraries/botframework-streaming-extensions/src/Interfaces/IHttpContentHeaders.ts rename to libraries/botframework-streaming/src/Interfaces/IHttpContentHeaders.ts index bbe4531d15..14b9a9a637 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IHttpContentHeaders.ts +++ b/libraries/botframework-streaming/src/Interfaces/IHttpContentHeaders.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IReceiveRequest.ts b/libraries/botframework-streaming/src/Interfaces/IReceiveRequest.ts similarity index 88% rename from libraries/botframework-streaming-extensions/src/Interfaces/IReceiveRequest.ts rename to libraries/botframework-streaming/src/Interfaces/IReceiveRequest.ts index 01382d3e19..5bcec8463e 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IReceiveRequest.ts +++ b/libraries/botframework-streaming/src/Interfaces/IReceiveRequest.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IReceiveResponse.ts b/libraries/botframework-streaming/src/Interfaces/IReceiveResponse.ts similarity index 81% rename from libraries/botframework-streaming-extensions/src/Interfaces/IReceiveResponse.ts rename to libraries/botframework-streaming/src/Interfaces/IReceiveResponse.ts index e7a01046eb..c051b217db 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IReceiveResponse.ts +++ b/libraries/botframework-streaming/src/Interfaces/IReceiveResponse.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IRequestPayload.ts b/libraries/botframework-streaming/src/Interfaces/IRequestPayload.ts similarity index 82% rename from libraries/botframework-streaming-extensions/src/Interfaces/IRequestPayload.ts rename to libraries/botframework-streaming/src/Interfaces/IRequestPayload.ts index a502a61e07..b61df546f9 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IRequestPayload.ts +++ b/libraries/botframework-streaming/src/Interfaces/IRequestPayload.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IResponsePayload.ts b/libraries/botframework-streaming/src/Interfaces/IResponsePayload.ts similarity index 82% rename from libraries/botframework-streaming-extensions/src/Interfaces/IResponsePayload.ts rename to libraries/botframework-streaming/src/Interfaces/IResponsePayload.ts index 2c1ea06a07..386622f086 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IResponsePayload.ts +++ b/libraries/botframework-streaming/src/Interfaces/IResponsePayload.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/ISendPacket.ts b/libraries/botframework-streaming/src/Interfaces/ISendPacket.ts similarity index 84% rename from libraries/botframework-streaming-extensions/src/Interfaces/ISendPacket.ts rename to libraries/botframework-streaming/src/Interfaces/ISendPacket.ts index eaa657a05b..73632be3b3 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/ISendPacket.ts +++ b/libraries/botframework-streaming/src/Interfaces/ISendPacket.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/ISocket.ts b/libraries/botframework-streaming/src/Interfaces/ISocket.ts similarity index 89% rename from libraries/botframework-streaming-extensions/src/Interfaces/ISocket.ts rename to libraries/botframework-streaming/src/Interfaces/ISocket.ts index 8de3cc92ce..15e307ed3c 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/ISocket.ts +++ b/libraries/botframework-streaming/src/Interfaces/ISocket.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamDescription.ts b/libraries/botframework-streaming/src/Interfaces/IStreamDescription.ts similarity index 78% rename from libraries/botframework-streaming-extensions/src/Interfaces/IStreamDescription.ts rename to libraries/botframework-streaming/src/Interfaces/IStreamDescription.ts index e43aa4dca4..a91a26a85c 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamDescription.ts +++ b/libraries/botframework-streaming/src/Interfaces/IStreamDescription.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamWrapper.ts b/libraries/botframework-streaming/src/Interfaces/IStreamWrapper.ts similarity index 82% rename from libraries/botframework-streaming-extensions/src/Interfaces/IStreamWrapper.ts rename to libraries/botframework-streaming/src/Interfaces/IStreamWrapper.ts index a0efd835f2..5ff893cc75 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamWrapper.ts +++ b/libraries/botframework-streaming/src/Interfaces/IStreamWrapper.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportClient.ts b/libraries/botframework-streaming/src/Interfaces/IStreamingTransportClient.ts similarity index 88% rename from libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportClient.ts rename to libraries/botframework-streaming/src/Interfaces/IStreamingTransportClient.ts index aff1e8d9dc..f767e29ae2 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportClient.ts +++ b/libraries/botframework-streaming/src/Interfaces/IStreamingTransportClient.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportServer.ts b/libraries/botframework-streaming/src/Interfaces/IStreamingTransportServer.ts similarity index 88% rename from libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportServer.ts rename to libraries/botframework-streaming/src/Interfaces/IStreamingTransportServer.ts index ee2e1d057b..2b105c1092 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/IStreamingTransportServer.ts +++ b/libraries/botframework-streaming/src/Interfaces/IStreamingTransportServer.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/ITransport.ts b/libraries/botframework-streaming/src/Interfaces/ITransport.ts similarity index 76% rename from libraries/botframework-streaming-extensions/src/Interfaces/ITransport.ts rename to libraries/botframework-streaming/src/Interfaces/ITransport.ts index 451c724e62..c0c59750d2 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/ITransport.ts +++ b/libraries/botframework-streaming/src/Interfaces/ITransport.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/ITransportReceiver.ts b/libraries/botframework-streaming/src/Interfaces/ITransportReceiver.ts similarity index 82% rename from libraries/botframework-streaming-extensions/src/Interfaces/ITransportReceiver.ts rename to libraries/botframework-streaming/src/Interfaces/ITransportReceiver.ts index 92d13e8300..bb174781fe 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/ITransportReceiver.ts +++ b/libraries/botframework-streaming/src/Interfaces/ITransportReceiver.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/ITransportSender.ts b/libraries/botframework-streaming/src/Interfaces/ITransportSender.ts similarity index 81% rename from libraries/botframework-streaming-extensions/src/Interfaces/ITransportSender.ts rename to libraries/botframework-streaming/src/Interfaces/ITransportSender.ts index c88a24ce0d..d84ac9f8d7 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/ITransportSender.ts +++ b/libraries/botframework-streaming/src/Interfaces/ITransportSender.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Interfaces/index.ts b/libraries/botframework-streaming/src/Interfaces/index.ts similarity index 84% rename from libraries/botframework-streaming-extensions/src/Interfaces/index.ts rename to libraries/botframework-streaming/src/Interfaces/index.ts index 481836aa84..df6b74c679 100644 --- a/libraries/botframework-streaming-extensions/src/Interfaces/index.ts +++ b/libraries/botframework-streaming/src/Interfaces/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeClient.ts b/libraries/botframework-streaming/src/NamedPipe/NamedPipeClient.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeClient.ts rename to libraries/botframework-streaming/src/NamedPipe/NamedPipeClient.ts index 35d981d6d3..177bde674e 100644 --- a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeClient.ts +++ b/libraries/botframework-streaming/src/NamedPipe/NamedPipeClient.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeServer.ts b/libraries/botframework-streaming/src/NamedPipe/NamedPipeServer.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeServer.ts rename to libraries/botframework-streaming/src/NamedPipe/NamedPipeServer.ts index ac43792cbb..559fbda3ee 100644 --- a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeServer.ts +++ b/libraries/botframework-streaming/src/NamedPipe/NamedPipeServer.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeTransport.ts b/libraries/botframework-streaming/src/NamedPipe/NamedPipeTransport.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeTransport.ts rename to libraries/botframework-streaming/src/NamedPipe/NamedPipeTransport.ts index 05bbf5765d..59077ee291 100644 --- a/libraries/botframework-streaming-extensions/src/NamedPipe/NamedPipeTransport.ts +++ b/libraries/botframework-streaming/src/NamedPipe/NamedPipeTransport.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/NamedPipe/index.ts b/libraries/botframework-streaming/src/NamedPipe/index.ts similarity index 79% rename from libraries/botframework-streaming-extensions/src/NamedPipe/index.ts rename to libraries/botframework-streaming/src/NamedPipe/index.ts index 16d3b7350c..61967f4c27 100644 --- a/libraries/botframework-streaming-extensions/src/NamedPipe/index.ts +++ b/libraries/botframework-streaming/src/NamedPipe/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadReceiver.ts b/libraries/botframework-streaming/src/PayloadTransport/PayloadReceiver.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadReceiver.ts rename to libraries/botframework-streaming/src/PayloadTransport/PayloadReceiver.ts index b5ca55231c..ec97e48a3a 100644 --- a/libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadReceiver.ts +++ b/libraries/botframework-streaming/src/PayloadTransport/PayloadReceiver.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadSender.ts b/libraries/botframework-streaming/src/PayloadTransport/PayloadSender.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadSender.ts rename to libraries/botframework-streaming/src/PayloadTransport/PayloadSender.ts index 5f4fa9e59f..2c7f12a2ee 100644 --- a/libraries/botframework-streaming-extensions/src/PayloadTransport/PayloadSender.ts +++ b/libraries/botframework-streaming/src/PayloadTransport/PayloadSender.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventArgs.ts b/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventArgs.ts similarity index 85% rename from libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventArgs.ts rename to libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventArgs.ts index 59846b3608..11487cb676 100644 --- a/libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventArgs.ts +++ b/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventArgs.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventHandler.ts b/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventHandler.ts similarity index 84% rename from libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventHandler.ts rename to libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventHandler.ts index 491fca220a..7b43ba9d99 100644 --- a/libraries/botframework-streaming-extensions/src/PayloadTransport/TransportDisconnectedEventHandler.ts +++ b/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventHandler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/PayloadTransport/index.ts b/libraries/botframework-streaming/src/PayloadTransport/index.ts similarity index 85% rename from libraries/botframework-streaming-extensions/src/PayloadTransport/index.ts rename to libraries/botframework-streaming/src/PayloadTransport/index.ts index 27adec8d21..3dc4b2ead9 100644 --- a/libraries/botframework-streaming-extensions/src/PayloadTransport/index.ts +++ b/libraries/botframework-streaming/src/PayloadTransport/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/HeaderSerializer.ts b/libraries/botframework-streaming/src/Payloads/HeaderSerializer.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/Payloads/HeaderSerializer.ts rename to libraries/botframework-streaming/src/Payloads/HeaderSerializer.ts index 695d103723..7b172ee97c 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/HeaderSerializer.ts +++ b/libraries/botframework-streaming/src/Payloads/HeaderSerializer.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/PayloadAssemblerManager.ts b/libraries/botframework-streaming/src/Payloads/PayloadAssemblerManager.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/Payloads/PayloadAssemblerManager.ts rename to libraries/botframework-streaming/src/Payloads/PayloadAssemblerManager.ts index 3c93956d53..7146896793 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/PayloadAssemblerManager.ts +++ b/libraries/botframework-streaming/src/Payloads/PayloadAssemblerManager.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/PayloadConstants.ts b/libraries/botframework-streaming/src/Payloads/PayloadConstants.ts similarity index 80% rename from libraries/botframework-streaming-extensions/src/Payloads/PayloadConstants.ts rename to libraries/botframework-streaming/src/Payloads/PayloadConstants.ts index 513cd7eafc..8a12645252 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/PayloadConstants.ts +++ b/libraries/botframework-streaming/src/Payloads/PayloadConstants.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/PayloadTypes.ts b/libraries/botframework-streaming/src/Payloads/PayloadTypes.ts similarity index 80% rename from libraries/botframework-streaming-extensions/src/Payloads/PayloadTypes.ts rename to libraries/botframework-streaming/src/Payloads/PayloadTypes.ts index f90f4c7a17..f389469545 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/PayloadTypes.ts +++ b/libraries/botframework-streaming/src/Payloads/PayloadTypes.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/RequestManager.ts b/libraries/botframework-streaming/src/Payloads/RequestManager.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/Payloads/RequestManager.ts rename to libraries/botframework-streaming/src/Payloads/RequestManager.ts index 28ec7d5f2e..76d5f5a021 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/RequestManager.ts +++ b/libraries/botframework-streaming/src/Payloads/RequestManager.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/SendOperations.ts b/libraries/botframework-streaming/src/Payloads/SendOperations.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/Payloads/SendOperations.ts rename to libraries/botframework-streaming/src/Payloads/SendOperations.ts index ce27d78e88..a558986304 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/SendOperations.ts +++ b/libraries/botframework-streaming/src/Payloads/SendOperations.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/StreamManager.ts b/libraries/botframework-streaming/src/Payloads/StreamManager.ts similarity index 94% rename from libraries/botframework-streaming-extensions/src/Payloads/StreamManager.ts rename to libraries/botframework-streaming/src/Payloads/StreamManager.ts index f78bee7384..dfa578aa89 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/StreamManager.ts +++ b/libraries/botframework-streaming/src/Payloads/StreamManager.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Payloads/index.ts b/libraries/botframework-streaming/src/Payloads/index.ts similarity index 85% rename from libraries/botframework-streaming-extensions/src/Payloads/index.ts rename to libraries/botframework-streaming/src/Payloads/index.ts index 83efc8f1a5..2b026bc0d6 100644 --- a/libraries/botframework-streaming-extensions/src/Payloads/index.ts +++ b/libraries/botframework-streaming/src/Payloads/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/ProtocolAdapter.ts b/libraries/botframework-streaming/src/ProtocolAdapter.ts similarity index 97% rename from libraries/botframework-streaming-extensions/src/ProtocolAdapter.ts rename to libraries/botframework-streaming/src/ProtocolAdapter.ts index 0b1bb01f8e..ef6ec5ac4a 100644 --- a/libraries/botframework-streaming-extensions/src/ProtocolAdapter.ts +++ b/libraries/botframework-streaming/src/ProtocolAdapter.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/RequestHandler.ts b/libraries/botframework-streaming/src/RequestHandler.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/RequestHandler.ts rename to libraries/botframework-streaming/src/RequestHandler.ts index 1c81e6b9a2..3c0c367fd8 100644 --- a/libraries/botframework-streaming-extensions/src/RequestHandler.ts +++ b/libraries/botframework-streaming/src/RequestHandler.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/StreamingRequest.ts b/libraries/botframework-streaming/src/StreamingRequest.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/StreamingRequest.ts rename to libraries/botframework-streaming/src/StreamingRequest.ts index 3e42779296..817327be3b 100644 --- a/libraries/botframework-streaming-extensions/src/StreamingRequest.ts +++ b/libraries/botframework-streaming/src/StreamingRequest.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/StreamingResponse.ts b/libraries/botframework-streaming/src/StreamingResponse.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/StreamingResponse.ts rename to libraries/botframework-streaming/src/StreamingResponse.ts index b3c56ac0d4..7195a49310 100644 --- a/libraries/botframework-streaming-extensions/src/StreamingResponse.ts +++ b/libraries/botframework-streaming/src/StreamingResponse.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/SubscribableStream.ts b/libraries/botframework-streaming/src/SubscribableStream.ts similarity index 93% rename from libraries/botframework-streaming-extensions/src/SubscribableStream.ts rename to libraries/botframework-streaming/src/SubscribableStream.ts index 53ec25cfab..9e8d5e773c 100644 --- a/libraries/botframework-streaming-extensions/src/SubscribableStream.ts +++ b/libraries/botframework-streaming/src/SubscribableStream.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Utilities/index.ts b/libraries/botframework-streaming/src/Utilities/index.ts similarity index 73% rename from libraries/botframework-streaming-extensions/src/Utilities/index.ts rename to libraries/botframework-streaming/src/Utilities/index.ts index b8ec67a65f..68108e31c9 100644 --- a/libraries/botframework-streaming-extensions/src/Utilities/index.ts +++ b/libraries/botframework-streaming/src/Utilities/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/Utilities/protocol-base.ts b/libraries/botframework-streaming/src/Utilities/protocol-base.ts similarity index 78% rename from libraries/botframework-streaming-extensions/src/Utilities/protocol-base.ts rename to libraries/botframework-streaming/src/Utilities/protocol-base.ts index 52fef47665..e8346af231 100644 --- a/libraries/botframework-streaming-extensions/src/Utilities/protocol-base.ts +++ b/libraries/botframework-streaming/src/Utilities/protocol-base.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/BrowserWebSocket.ts b/libraries/botframework-streaming/src/WebSocket/BrowserWebSocket.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/WebSocket/BrowserWebSocket.ts rename to libraries/botframework-streaming/src/WebSocket/BrowserWebSocket.ts index 7f48e954a3..35253afe3b 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/BrowserWebSocket.ts +++ b/libraries/botframework-streaming/src/WebSocket/BrowserWebSocket.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/NodeWebSocket.ts b/libraries/botframework-streaming/src/WebSocket/NodeWebSocket.ts similarity index 95% rename from libraries/botframework-streaming-extensions/src/WebSocket/NodeWebSocket.ts rename to libraries/botframework-streaming/src/WebSocket/NodeWebSocket.ts index 1457bcdb01..45f27e4f64 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/NodeWebSocket.ts +++ b/libraries/botframework-streaming/src/WebSocket/NodeWebSocket.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts b/libraries/botframework-streaming/src/WebSocket/WebSocketClient.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts rename to libraries/botframework-streaming/src/WebSocket/WebSocketClient.ts index 2cf43351a6..be6cf2e043 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts +++ b/libraries/botframework-streaming/src/WebSocket/WebSocketClient.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketServer.ts b/libraries/botframework-streaming/src/WebSocket/WebSocketServer.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/WebSocket/WebSocketServer.ts rename to libraries/botframework-streaming/src/WebSocket/WebSocketServer.ts index d0deba6189..dc4c9bf70c 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketServer.ts +++ b/libraries/botframework-streaming/src/WebSocket/WebSocketServer.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketTransport.ts b/libraries/botframework-streaming/src/WebSocket/WebSocketTransport.ts similarity index 96% rename from libraries/botframework-streaming-extensions/src/WebSocket/WebSocketTransport.ts rename to libraries/botframework-streaming/src/WebSocket/WebSocketTransport.ts index e128940f3b..fdf5fc705d 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketTransport.ts +++ b/libraries/botframework-streaming/src/WebSocket/WebSocketTransport.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/index.ts b/libraries/botframework-streaming/src/WebSocket/index.ts similarity index 84% rename from libraries/botframework-streaming-extensions/src/WebSocket/index.ts rename to libraries/botframework-streaming/src/WebSocket/index.ts index f46903add8..b339d59cd1 100644 --- a/libraries/botframework-streaming-extensions/src/WebSocket/index.ts +++ b/libraries/botframework-streaming/src/WebSocket/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/src/index.ts b/libraries/botframework-streaming/src/index.ts similarity index 92% rename from libraries/botframework-streaming-extensions/src/index.ts rename to libraries/botframework-streaming/src/index.ts index c33397575c..a48409935d 100644 --- a/libraries/botframework-streaming-extensions/src/index.ts +++ b/libraries/botframework-streaming/src/index.ts @@ -1,5 +1,5 @@ /** - * @module botframework-streaming-extensions + * @module botframework-streaming */ /** * Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/libraries/botframework-streaming-extensions/tests/Assembler.test.js b/libraries/botframework-streaming/tests/Assembler.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/Assembler.test.js rename to libraries/botframework-streaming/tests/Assembler.test.js diff --git a/libraries/botframework-streaming-extensions/tests/ContentStream.test.js b/libraries/botframework-streaming/tests/ContentStream.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/ContentStream.test.js rename to libraries/botframework-streaming/tests/ContentStream.test.js diff --git a/libraries/botframework-streaming-extensions/tests/Disassembler.test.js b/libraries/botframework-streaming/tests/Disassembler.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/Disassembler.test.js rename to libraries/botframework-streaming/tests/Disassembler.test.js diff --git a/libraries/botframework-streaming-extensions/tests/HeaderSerializer.test.js b/libraries/botframework-streaming/tests/HeaderSerializer.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/HeaderSerializer.test.js rename to libraries/botframework-streaming/tests/HeaderSerializer.test.js diff --git a/libraries/botframework-streaming-extensions/tests/NamedPipe.test.js b/libraries/botframework-streaming/tests/NamedPipe.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/NamedPipe.test.js rename to libraries/botframework-streaming/tests/NamedPipe.test.js diff --git a/libraries/botframework-streaming-extensions/tests/PayloadSender.test.js b/libraries/botframework-streaming/tests/PayloadSender.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/PayloadSender.test.js rename to libraries/botframework-streaming/tests/PayloadSender.test.js diff --git a/libraries/botframework-streaming-extensions/tests/ProtocolAdapter.test.js b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/ProtocolAdapter.test.js rename to libraries/botframework-streaming/tests/ProtocolAdapter.test.js diff --git a/libraries/botframework-streaming-extensions/tests/RequestManager.test.js b/libraries/botframework-streaming/tests/RequestManager.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/RequestManager.test.js rename to libraries/botframework-streaming/tests/RequestManager.test.js diff --git a/libraries/botframework-streaming-extensions/tests/SendOperations.test.js b/libraries/botframework-streaming/tests/SendOperations.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/SendOperations.test.js rename to libraries/botframework-streaming/tests/SendOperations.test.js diff --git a/libraries/botframework-streaming-extensions/tests/StreamManager.test.js b/libraries/botframework-streaming/tests/StreamManager.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/StreamManager.test.js rename to libraries/botframework-streaming/tests/StreamManager.test.js diff --git a/libraries/botframework-streaming-extensions/tests/StreamingRequest.test.js b/libraries/botframework-streaming/tests/StreamingRequest.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/StreamingRequest.test.js rename to libraries/botframework-streaming/tests/StreamingRequest.test.js diff --git a/libraries/botframework-streaming-extensions/tests/StreamingResponse.test.js b/libraries/botframework-streaming/tests/StreamingResponse.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/StreamingResponse.test.js rename to libraries/botframework-streaming/tests/StreamingResponse.test.js diff --git a/libraries/botframework-streaming-extensions/tests/SubscribableStream.test.js b/libraries/botframework-streaming/tests/SubscribableStream.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/SubscribableStream.test.js rename to libraries/botframework-streaming/tests/SubscribableStream.test.js diff --git a/libraries/botframework-streaming-extensions/tests/TransportConstants.test.js b/libraries/botframework-streaming/tests/TransportConstants.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/TransportConstants.test.js rename to libraries/botframework-streaming/tests/TransportConstants.test.js diff --git a/libraries/botframework-streaming-extensions/tests/WebSocket.test.js b/libraries/botframework-streaming/tests/WebSocket.test.js similarity index 100% rename from libraries/botframework-streaming-extensions/tests/WebSocket.test.js rename to libraries/botframework-streaming/tests/WebSocket.test.js diff --git a/libraries/botframework-streaming-extensions/tests/mocha.opts b/libraries/botframework-streaming/tests/mocha.opts similarity index 100% rename from libraries/botframework-streaming-extensions/tests/mocha.opts rename to libraries/botframework-streaming/tests/mocha.opts diff --git a/libraries/botframework-streaming-extensions/tsconfig.json b/libraries/botframework-streaming/tsconfig.json similarity index 100% rename from libraries/botframework-streaming-extensions/tsconfig.json rename to libraries/botframework-streaming/tsconfig.json From 17cce267886269a71aea8df5549debdba2841e8d Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Sun, 13 Oct 2019 12:38:10 -0700 Subject: [PATCH 02/32] Streaming: Move BotFrameworkStreamingAdapter to botbuilder module --- .../.gitignore | 4 - .../botbuilder-streaming-extensions/README.md | 25 - .../package.json | 44 - .../src/index.ts | 1 - .../tsconfig.json | 14 - libraries/botbuilder/package.json | 2 + .../src/botFrameworkStreamingAdapter.ts} | 577 +++++------ .../botFrameworkStreamingAdapter.test.js} | 918 +++++++++--------- libraries/botframework-streaming/package.json | 2 +- 9 files changed, 751 insertions(+), 836 deletions(-) delete mode 100644 libraries/botbuilder-streaming-extensions/.gitignore delete mode 100644 libraries/botbuilder-streaming-extensions/README.md delete mode 100644 libraries/botbuilder-streaming-extensions/package.json delete mode 100644 libraries/botbuilder-streaming-extensions/src/index.ts delete mode 100644 libraries/botbuilder-streaming-extensions/tsconfig.json rename libraries/{botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts => botbuilder/src/botFrameworkStreamingAdapter.ts} (95%) rename libraries/{botbuilder-streaming-extensions/tests/BotFrameworkStreamingAdapter.test.js => botbuilder/tests/botFrameworkStreamingAdapter.test.js} (97%) diff --git a/libraries/botbuilder-streaming-extensions/.gitignore b/libraries/botbuilder-streaming-extensions/.gitignore deleted file mode 100644 index 392f0b0976..0000000000 --- a/libraries/botbuilder-streaming-extensions/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/lib -/node_modules -*.js.map -/coverage/** diff --git a/libraries/botbuilder-streaming-extensions/README.md b/libraries/botbuilder-streaming-extensions/README.md deleted file mode 100644 index e9e9f8bbdd..0000000000 --- a/libraries/botbuilder-streaming-extensions/README.md +++ /dev/null @@ -1,25 +0,0 @@ -This library contains the BotBuilder integration layer of of Bot Framework Streaming Extensions, which extends the 3.0 Bot Framework protocol to communicate over multiplexed, persistent, connections such as named pipes or WebSocket. - -- [Installing](#installing) -- [Documentation](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0) -- [GitHub Repo](https://github.com/Microsoft/botbuilder-js) -- [Report Issues](https://github.com/Microsoft/botbuilder-js/issues) - -## Installing -To add the latest published version of this package to your bot: - -```bash -npm install --save botbuilder-streaming-extensions -``` - -#### Use the Daily Build - -To get access to the daily builds of this library, configure npm to use the MyGet feed before installing. - -```bash -npm config set registry https://botbuilder.myget.org/F/botbuilder-v4-js-daily/npm/ -``` - -To reset the registry in order to get the latest published version, run: -```bash -npm config set registry https://registry.npmjs.org/ \ No newline at end of file diff --git a/libraries/botbuilder-streaming-extensions/package.json b/libraries/botbuilder-streaming-extensions/package.json deleted file mode 100644 index caae677b5e..0000000000 --- a/libraries/botbuilder-streaming-extensions/package.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "botbuilder-streaming-extensions", - "version": "0.0.1", - "description": "", - "main": "lib/index.js", - "typings": "lib/index.d.js", - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@types/chai": "^4.1.7", - "@types/node": "^10.12.18", - "chai": "^4.2.0", - "nyc": "^11.4.1", - "ts-node": "^4.1.0", - "tslint": "^5.16.0", - "tslint-microsoft-contrib": "^5.2.1", - "typescript": "3.1.1" - }, - "dependencies": { - "@azure/ms-rest-js": "1.2.6", - "botbuilder": "~4.5.1", - "botbuilder-core": "~4.5.1", - "botframework-connector": "~4.5.1", - "botframework-schema": "~4.5.1", - "botframework-streaming": "~4.6.1", - "promise.prototype.finally": "^3.1.0", - "uuid": "^3.3.2", - "watershed": "^0.4.0" - }, - "engines": { - "node": ">12.3" - }, - "scripts": { - "test": "tsc && nyc mocha tests/", - "build": "tsc", - "clean": "erase /q /s .\\lib", - "set-version": "npm version --allow-same-version ${Version}" - }, - "files": [ - "/lib", - "/src" - ] -} diff --git a/libraries/botbuilder-streaming-extensions/src/index.ts b/libraries/botbuilder-streaming-extensions/src/index.ts deleted file mode 100644 index b9e59e5d12..0000000000 --- a/libraries/botbuilder-streaming-extensions/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './botFrameworkStreamingAdapter'; \ No newline at end of file diff --git a/libraries/botbuilder-streaming-extensions/tsconfig.json b/libraries/botbuilder-streaming-extensions/tsconfig.json deleted file mode 100644 index 379990fba7..0000000000 --- a/libraries/botbuilder-streaming-extensions/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "target": "ESNext", - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "outDir": "./lib", - "rootDir": "./src", - "types" : ["node"] - }, - "include": [ - "src/**/*" - ] -} \ No newline at end of file diff --git a/libraries/botbuilder/package.json b/libraries/botbuilder/package.json index 6262b2d440..fe91e4333a 100644 --- a/libraries/botbuilder/package.json +++ b/libraries/botbuilder/package.json @@ -20,9 +20,11 @@ "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" }, diff --git a/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts b/libraries/botbuilder/src/botFrameworkStreamingAdapter.ts similarity index 95% rename from libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts rename to libraries/botbuilder/src/botFrameworkStreamingAdapter.ts index 298fe3cb1c..73ac29a8f4 100644 --- a/libraries/botbuilder-streaming-extensions/src/BotFrameworkStreamingAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkStreamingAdapter.ts @@ -1,288 +1,289 @@ -/** - * @module botbuilder-streaming-extensions - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -import { BotFrameworkAdapterSettings, InvokeResponse, BotFrameworkAdapter, WebRequest, WebResponse } from 'botbuilder'; -import { ActivityHandler, Middleware, MiddlewareHandler, TurnContext } from 'botbuilder-core'; -import { ConnectorClient, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider } from 'botframework-connector'; -import { Activity, ActivityTypes } from 'botframework-schema'; -import * as os from 'os'; -import { ISocket, IStreamingTransportServer, IReceiveRequest, NamedPipeServer, NodeWebSocket, - RequestHandler, StreamingResponse, WebSocketServer, StreamingRequest } from 'botframework-streaming'; //TODO: When integration layer is moved this will need to reference the external library. -import { HttpClient, HttpOperationResponse, WebResource } from '@azure/ms-rest-js'; -import { Watershed } from 'watershed'; -import { Request, ServerUpgradeResponse } from 'restify'; - -export enum StatusCodes { - OK = 200, - BAD_REQUEST = 400, - UNAUTHORIZED = 401, - NOT_FOUND = 404, - METHOD_NOT_ALLOWED = 405, - UPGRADE_REQUIRED = 426, - INTERNAL_SERVER_ERROR = 500, - NOT_IMPLEMENTED = 501, -} - -const defaultPipeName = 'bfv4.pipes'; -const pjson: any = require('../package.json'); -const VERSION_PATH:string = '/api/version'; -const MESSAGES_PATH:string = '/api/messages'; -const INVOKE_RESPONSE:string = 'BotFrameworkStreamingAdapter.InvokeResponse'; -const GET:string = 'GET'; -const POST:string = 'POST'; -let USER_AGENT:string; - -/// -/// Used to process incoming requests sent over an and adhering to the Bot Framework Protocol v3 with Streaming Extensions. -/// -export class BotFrameworkStreamingAdapter extends BotFrameworkAdapter implements RequestHandler { - private bot: ActivityHandler; - private logger; - private server: IStreamingTransportServer; - private middleWare: (MiddlewareHandler|Middleware)[]; - - /// - /// Initializes a new instance of the class. - /// The StreamingRequestHandler serves as a translation layer between the transport layer and bot adapter. - /// It receives ReceiveRequests from the transport and provides them to the bot adapter in a form - /// it is able to build activities out of, which are then handed to the bot itself to processed. - /// Throws error if arguments are null. - /// - /// The bot to be used for all requests to this handler. - /// Optional logger, defaults to console. - /// The settings for use with the BotFrameworkAdapter. - /// An optional set of middleware to register with the adapter. - public constructor(bot: ActivityHandler, logger = console, settings?: BotFrameworkAdapterSettings, middleWare: (MiddlewareHandler|Middleware)[] = []) { - super(settings); - this.bot = bot; - this.logger = logger; - this.middleWare = middleWare; - } - - /// - /// Process the initial request to establish a long lived connection via a streaming server. - /// - /// The connection request. - /// The response sent on error or connection termination. - /// Settings to set on the BotframeworkAdapter. - public async connectWebSocket(req: Request, res: ServerUpgradeResponse, settings: BotFrameworkAdapterSettings): Promise { - if (!req.isUpgradeRequest()) { - let e = new Error('Upgrade to WebSockets required.'); - this.logger.log(e); - res.status(StatusCodes.UPGRADE_REQUIRED); - res.send(e.message); - - return Promise.resolve(); - } - - const authenticated = await this.authenticateConnection(req, settings.appId, settings.appPassword, settings.channelService); - if (!authenticated) { - this.logger.log('Unauthorized connection attempt.'); - res.status(StatusCodes.UNAUTHORIZED); - - return Promise.resolve(); - } - - const upgrade = res.claimUpgrade(); - const ws = new Watershed(); - const socket = ws.accept(req, upgrade.socket, upgrade.head); - - await this.startWebSocket(new NodeWebSocket(socket)); - } - - /// - /// Connects the handler to a Named Pipe server and begins listening for incoming requests. - /// - /// The name of the named pipe to use when creating the server. - public async connectNamedPipe(pipename: string = defaultPipeName): Promise{ - this.server = new NamedPipeServer(pipename, this); - await this.server.start(); - } - - /// - /// Checks the validity of the request and attempts to map it the correct virtual endpoint, - /// then generates and returns a response if appropriate. - /// - /// A ReceiveRequest from the connected channel. - /// A response created by the BotAdapter to be sent to the client that originated the request. - public async processRequest(request: IReceiveRequest): Promise { - let response = new StreamingResponse(); - - if (!request || !request.verb || !request.path) { - response.statusCode = StatusCodes.BAD_REQUEST; - this.logger.log('Request missing verb and/or path.'); - - return response; - } - - if (request.verb.toLocaleUpperCase() === GET && request.path.toLocaleLowerCase() === VERSION_PATH) { - response.statusCode = StatusCodes.OK; - response.setBody(this.getUserAgent()); - - return response; - } - - let body: Activity; - try { - body = await this.readRequestBodyAsString(request); - - } catch (error) { - response.statusCode = StatusCodes.BAD_REQUEST; - this.logger.log('Unable to read request body. Error: ' + error); - - return response; - } - - if (request.verb.toLocaleUpperCase() !== POST) { - response.statusCode = StatusCodes.METHOD_NOT_ALLOWED; - - return response; - } - - if (request.path.toLocaleLowerCase() !== MESSAGES_PATH) { - response.statusCode = StatusCodes.NOT_FOUND; - - return response; - } - - try { - this.middleWare.forEach((mw): void => { - this.use(mw); - }); - let context = new TurnContext(this, body); - await this.runMiddleware(context, async (turnContext): Promise => { - await this.bot.run(turnContext); - }); - - if (body.type === ActivityTypes.Invoke) { - let invokeResponse: any = context.turnState.get(INVOKE_RESPONSE); - - if (invokeResponse && invokeResponse.value) { - const value: InvokeResponse = invokeResponse.value; - response.statusCode = value.status; - response.setBody(value.body); - } else { - response.statusCode = StatusCodes.NOT_IMPLEMENTED; - } - } else { - response.statusCode = StatusCodes.OK; - } - } catch (error) { - response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR; - this.logger.log(error); - - return response; - - } - - return response; - } - - /// - /// Hides the adapter's built in means of creating a connector client - /// and subtitutes a StreamingHttpClient in place of the standard HttpClient, - /// thus allowing compatibility with streaming extensions. - /// - public createConnectorClient(serviceUrl: string): ConnectorClient { - return new ConnectorClient( - this.credentials, - { - baseUri: serviceUrl, - userAgent: super['USER_AGENT'], - httpClient: new StreamingHttpClient(this.server) - }); - } - - private async authenticateConnection(req: WebRequest, appId?: string, appPassword?: string, channelService?: string): Promise { - if (!appId || !appPassword) { - // auth is disabled - return true; - } - - try { - let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; - let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; - let credentials = new MicrosoftAppCredentials(appId, appPassword); - let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); - let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); - - return claims.isAuthenticated; - } catch (error) { - this.logger.log(error); - - return false; - } - } - - /// - /// Connects the handler to a WebSocket server and begins listening for incoming requests. - /// - /// The socket to use when creating the server. - private async startWebSocket(socket: ISocket): Promise{ - this.server = new WebSocketServer(socket, this); - await this.server.start(); - } - - private async readRequestBodyAsString(request: IReceiveRequest): Promise { - try { - let contentStream = request.streams[0]; - - return await contentStream.readAsJson(); - } catch (error) { - this.logger.log(error); - - return Promise.reject(error); - } - } - - private getUserAgent(): string { - if(USER_AGENT){ - return USER_AGENT; - } - const ARCHITECTURE: any = os.arch(); - const TYPE: any = os.type(); - const RELEASE: any = os.release(); - const NODE_VERSION: any = process.version; - USER_AGENT = `Microsoft-BotFramework/3.1 BotBuilder/${ pjson.version } ` + - `(Node.js,Version=${ NODE_VERSION }; ${ TYPE } ${ RELEASE }; ${ ARCHITECTURE })`; - - return USER_AGENT; - } -} - -class StreamingHttpClient implements HttpClient { - private readonly server: IStreamingTransportServer; - - public constructor(server: IStreamingTransportServer) { - 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. - /// - /// The outgoing request created by the BotframeworkAdapter. - /// The streaming transport compatible response to send back to the client. - public async sendRequest(httpRequest: WebResource): Promise { - 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 botbuilder + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +//import { BotFrameworkAdapterSettings, InvokeResponse, BotFrameworkAdapter, WebRequest, WebResponse } from 'botbuilder'; +import { ActivityHandler, Middleware, MiddlewareHandler, TurnContext } from 'botbuilder-core'; +import { ConnectorClient, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider } from 'botframework-connector'; +import { Activity, ActivityTypes } from 'botframework-schema'; +import * as os from 'os'; +import { ISocket, IStreamingTransportServer, IReceiveRequest, NamedPipeServer, NodeWebSocket, + RequestHandler, StreamingResponse, WebSocketServer, StreamingRequest } from 'botframework-streaming'; +import { HttpClient, HttpOperationResponse, WebResource } from '@azure/ms-rest-js'; +import { Watershed } from 'watershed'; +import { Request, ServerUpgradeResponse } from 'restify'; +import { BotFrameworkAdapter, BotFrameworkAdapterSettings, InvokeResponse, WebRequest } from '.'; + +export enum StatusCodes { + OK = 200, + BAD_REQUEST = 400, + UNAUTHORIZED = 401, + NOT_FOUND = 404, + METHOD_NOT_ALLOWED = 405, + UPGRADE_REQUIRED = 426, + INTERNAL_SERVER_ERROR = 500, + NOT_IMPLEMENTED = 501, +} + +const defaultPipeName = 'bfv4.pipes'; +const pjson: any = require('../package.json'); +const VERSION_PATH:string = '/api/version'; +const MESSAGES_PATH:string = '/api/messages'; +const INVOKE_RESPONSE:string = 'BotFrameworkStreamingAdapter.InvokeResponse'; +const GET:string = 'GET'; +const POST:string = 'POST'; +let USER_AGENT:string; + +/// +/// Used to process incoming requests sent over an and adhering to the Bot Framework Protocol v3 with Streaming Extensions. +/// +export class BotFrameworkStreamingAdapter extends BotFrameworkAdapter implements RequestHandler { + private bot: ActivityHandler; + private logger; + private server: IStreamingTransportServer; + private middleWare: (MiddlewareHandler|Middleware)[]; + + /// + /// Initializes a new instance of the class. + /// The StreamingRequestHandler serves as a translation layer between the transport layer and bot adapter. + /// It receives ReceiveRequests from the transport and provides them to the bot adapter in a form + /// it is able to build activities out of, which are then handed to the bot itself to processed. + /// Throws error if arguments are null. + /// + /// The bot to be used for all requests to this handler. + /// Optional logger, defaults to console. + /// The settings for use with the BotFrameworkAdapter. + /// An optional set of middleware to register with the adapter. + public constructor(bot: ActivityHandler, logger = console, settings?: BotFrameworkAdapterSettings, middleWare: (MiddlewareHandler|Middleware)[] = []) { + super(settings); + this.bot = bot; + this.logger = logger; + this.middleWare = middleWare; + } + + /// + /// Process the initial request to establish a long lived connection via a streaming server. + /// + /// The connection request. + /// The response sent on error or connection termination. + /// Settings to set on the BotframeworkAdapter. + public async connectWebSocket(req: Request, res: ServerUpgradeResponse, settings: BotFrameworkAdapterSettings): Promise { + if (!req.isUpgradeRequest()) { + let e = new Error('Upgrade to WebSockets required.'); + this.logger.log(e); + res.status(StatusCodes.UPGRADE_REQUIRED); + res.send(e.message); + + return Promise.resolve(); + } + + const authenticated = await this.authenticateConnection(req, settings.appId, settings.appPassword, settings.channelService); + if (!authenticated) { + this.logger.log('Unauthorized connection attempt.'); + res.status(StatusCodes.UNAUTHORIZED); + + return Promise.resolve(); + } + + const upgrade = res.claimUpgrade(); + const ws = new Watershed(); + const socket = ws.accept(req, upgrade.socket, upgrade.head); + + await this.startWebSocket(new NodeWebSocket(socket)); + } + + /// + /// Connects the handler to a Named Pipe server and begins listening for incoming requests. + /// + /// The name of the named pipe to use when creating the server. + public async connectNamedPipe(pipename: string = defaultPipeName): Promise{ + this.server = new NamedPipeServer(pipename, this); + await this.server.start(); + } + + /// + /// Checks the validity of the request and attempts to map it the correct virtual endpoint, + /// then generates and returns a response if appropriate. + /// + /// A ReceiveRequest from the connected channel. + /// A response created by the BotAdapter to be sent to the client that originated the request. + public async processRequest(request: IReceiveRequest): Promise { + let response = new StreamingResponse(); + + if (!request || !request.verb || !request.path) { + response.statusCode = StatusCodes.BAD_REQUEST; + this.logger.log('Request missing verb and/or path.'); + + return response; + } + + if (request.verb.toLocaleUpperCase() === GET && request.path.toLocaleLowerCase() === VERSION_PATH) { + response.statusCode = StatusCodes.OK; + response.setBody(this.getUserAgent()); + + return response; + } + + let body: Activity; + try { + body = await this.readRequestBodyAsString(request); + + } catch (error) { + response.statusCode = StatusCodes.BAD_REQUEST; + this.logger.log('Unable to read request body. Error: ' + error); + + return response; + } + + if (request.verb.toLocaleUpperCase() !== POST) { + response.statusCode = StatusCodes.METHOD_NOT_ALLOWED; + + return response; + } + + if (request.path.toLocaleLowerCase() !== MESSAGES_PATH) { + response.statusCode = StatusCodes.NOT_FOUND; + + return response; + } + + try { + this.middleWare.forEach((mw): void => { + this.use(mw); + }); + let context = new TurnContext(this, body); + await this.runMiddleware(context, async (turnContext): Promise => { + await this.bot.run(turnContext); + }); + + if (body.type === ActivityTypes.Invoke) { + let invokeResponse: any = context.turnState.get(INVOKE_RESPONSE); + + if (invokeResponse && invokeResponse.value) { + const value: InvokeResponse = invokeResponse.value; + response.statusCode = value.status; + response.setBody(value.body); + } else { + response.statusCode = StatusCodes.NOT_IMPLEMENTED; + } + } else { + response.statusCode = StatusCodes.OK; + } + } catch (error) { + response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR; + this.logger.log(error); + + return response; + + } + + return response; + } + + /// + /// Hides the adapter's built in means of creating a connector client + /// and subtitutes a StreamingHttpClient in place of the standard HttpClient, + /// thus allowing compatibility with streaming extensions. + /// + public createConnectorClient(serviceUrl: string): ConnectorClient { + return new ConnectorClient( + this.credentials, + { + baseUri: serviceUrl, + userAgent: super['USER_AGENT'], + httpClient: new StreamingHttpClient(this.server) + }); + } + + private async authenticateConnection(req: WebRequest, appId?: string, appPassword?: string, channelService?: string): Promise { + if (!appId || !appPassword) { + // auth is disabled + return true; + } + + try { + let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; + let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; + let credentials = new MicrosoftAppCredentials(appId, appPassword); + let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); + let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); + + return claims.isAuthenticated; + } catch (error) { + this.logger.log(error); + + return false; + } + } + + /// + /// Connects the handler to a WebSocket server and begins listening for incoming requests. + /// + /// The socket to use when creating the server. + private async startWebSocket(socket: ISocket): Promise{ + this.server = new WebSocketServer(socket, this); + await this.server.start(); + } + + private async readRequestBodyAsString(request: IReceiveRequest): Promise { + try { + let contentStream = request.streams[0]; + + return await contentStream.readAsJson(); + } catch (error) { + this.logger.log(error); + + return Promise.reject(error); + } + } + + private getUserAgent(): string { + if(USER_AGENT){ + return USER_AGENT; + } + const ARCHITECTURE: any = os.arch(); + const TYPE: any = os.type(); + const RELEASE: any = os.release(); + const NODE_VERSION: any = process.version; + USER_AGENT = `Microsoft-BotFramework/3.1 BotBuilder/${ pjson.version } ` + + `(Node.js,Version=${ NODE_VERSION }; ${ TYPE } ${ RELEASE }; ${ ARCHITECTURE })`; + + return USER_AGENT; + } +} + +class StreamingHttpClient implements HttpClient { + private readonly server: IStreamingTransportServer; + + public constructor(server: IStreamingTransportServer) { + 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. + /// + /// The outgoing request created by the BotframeworkAdapter. + /// The streaming transport compatible response to send back to the client. + public async sendRequest(httpRequest: WebResource): Promise { + 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); + } +} diff --git a/libraries/botbuilder-streaming-extensions/tests/BotFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js similarity index 97% rename from libraries/botbuilder-streaming-extensions/tests/BotFrameworkStreamingAdapter.test.js rename to libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 4cb833d5d4..83546ee35e 100644 --- a/libraries/botbuilder-streaming-extensions/tests/BotFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -1,460 +1,460 @@ -const Adapter = require('../lib/botFrameworkStreamingAdapter'); -const ActivityHandler = require("botbuilder-core"); -const chai = require('chai'); -var expect = chai.expect; - -class FauxSock{ - constructor(contentString){ - if(contentString){ - this.contentString = contentString; - this.position = 0; - } - this.connected = true; - } - isConnected(){ return this.connected; } - write(buffer){ return ; } - connect(serverAddress){ return new Promise(); } - close(){ this.connected = false; return; } - setOnMessageHandler(handler){ return; } //(x: any) => void); - setOnErrorHandler(handler){ return; } - setOnCloseHandler(handler){ return; } -} - -class TestRequest { - constructor(){ - let headers = []; - } - - isUpgradeRequest(){ - return this.upgradeRequestVal; - } - - setIsUpgradeRequest(value){ - this.upgradeRequestVal = value; - } - - status(){ - return this.statusVal; - } - - status(value){ - this.statusVal = value; - } - - path(value){ - this.pathVal = value; - } - - path(){ - return this.pathVal; - } - - verb(value){ - this.verbVal = value; - } - - verb(){ - return this.verbVal; - } - - streams(value){ - this.streamsVal = value; - } - - streams(){ - return this.streamsVal; - } - - setHeaders(){ - return this.headersVal; - } - - setHeaders(value){ - this.headers = value; - } - -} - -class TestResponse { - - construtor(){ - } - - send(value){ - this.sendVal = value; - return this.sendVal; - } - - status(value){ - this.statusVal = value; - return this.statusVal; - } - - setClaimUpgrade(value) - { - this.claimUpgradeVal = value; - } - - claimUpgrade(){ - return this.claimUpgradeVal; - } -} - -class TestAdapterSettings { - constructor(appId = undefined, appPassword = undefined, channelAuthTenant, oAuthEndpoint, openIdMetadata, channelServce){ - this.appId = appId; - this.appPassword = appPassword; - } -} - -describe('BotFrameworkStreamingAdapter tests', () => { - - it('has the correct status codes', () => { - expect(Adapter.StatusCodes.OK).to.equal(200); - expect(Adapter.StatusCodes.BAD_REQUEST).to.equal(400); - expect(Adapter.StatusCodes.UNAUTHORIZED).to.equal(401); - expect(Adapter.StatusCodes.NOT_FOUND).to.equal(404); - expect(Adapter.StatusCodes.METHOD_NOT_ALLOWED).to.equal(405); - expect(Adapter.StatusCodes.UPGRADE_REQUIRED).to.equal(426); - expect(Adapter.StatusCodes.INTERNAL_SERVER_ERROR).to.equal(500); - expect(Adapter.StatusCodes.NOT_IMPLEMENTED).to.equal(501); - }); - - it('gets constructed properly', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - - expect(handler).to.be.instanceOf(Adapter.BotFrameworkStreamingAdapter); - expect(handler.bot).to.equal(bot); - expect(handler.logger).to.equal(console); - expect(handler.middleWare).to.be.an('array').that.is.empty; - }); - - it('starts and stops a namedpipe server', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - - handler.connectNamedPipe('PipeyMcPipeface'); - expect(handler.server.disconnect()).to.not.throw; - }); - - it('starts and stops a websocket server', (done) => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - let response = new TestResponse({claimUpgrade:'anything'}); - let settings = new TestAdapterSettings(undefined, undefined); - - expect(handler.connectWebSocket(request, response, settings)).to.not.throw; - done(); - }); - - it('returns a connector client', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - cc = handler.createConnectorClient('www.contoso.com'); - expect(cc.baseUri).to.equal('www.contoso.com'); - }); - - it('connectWebSocket returns an error when request is not an upgrade request', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.setIsUpgradeRequest(false); - let response = new TestResponse(); - let settings = new TestAdapterSettings(undefined, undefined); - - handler.connectWebSocket(request, response, settings).catch(); - expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); - expect(response.statusVal).to.equal(426); - }); - - it('connectWebSocket returns status code 401 when request is not authorized', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); - request.setHeaders({channelid: 'fakechannel', authorization: 'donttrustme'}); - let response = new TestResponse(); - let settings = new TestAdapterSettings('appId', 'password'); - - await handler.connectWebSocket(request, response, settings).then(function(){ - return; - }); - expect(response.sendVal).to.equal(undefined); - expect(response.statusVal).to.equal(401); - }); - - it('connectWebSocket connects', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); - request.headers = []; - request.headers['upgrade'] = 'websocket'; - request.headers['sec-websocket-key'] = 'BFlat'; - request.headers['sec-websocket-version'] = '13'; - request.headers['sec-websocket-protocol'] = ''; - let response = new TestResponse(); - let fakeSocket = { - unshift: function(){return true;}, - write: function(value){console.log(value);}, - on: function(value){console.log(value);}, - read: function(){return new Buffer('data', 'utf8');}, - end: function(){return;}, - }; - response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); - let settings = new TestAdapterSettings(); - - await handler.connectWebSocket(request, response, settings).then(function(){ - return; - }); - }); - - it('returns a 400 when the request is missing verb', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = undefined; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); - }); - - it('returns a 400 when the request is missing path', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = undefined; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); - }); - - it('returns a 400 when the request body is missing', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest( 'POST', '/api/messages'); - request.verb = 'POST'; - request.path = '/api/messages'; - request.streams = undefined; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); - }); - - it('returns user agent information when a GET hits the version endpoint', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'GET'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - }); - - it('returns user agent information from cache when a GET hits the version endpoint more than once', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'GET'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - }); - - it('returns 405 for unsupported methods', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'UPDATE'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(405); - }); - }); - - it('returns 404 for unsupported paths', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/supersecretbackdoor'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(404); - }); - }); - - it('processes a well formed request when there is no middleware with a non-Invoke activity type', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'something', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - }); - }); - - it('returns a 501 when activity type is invoke, but the activity is invalid', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(501); - }); - }); - - it('sends a request', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); - request.headers = []; - request.headers['upgrade'] = 'websocket'; - request.headers['sec-websocket-key'] = 'BFlat'; - request.headers['sec-websocket-version'] = '13'; - request.headers['sec-websocket-protocol'] = ''; - let response = new TestResponse(); - let fakeSocket = { - unshift: function(){return true;}, - write: function(){return Promise.resolve; }, - on: function(){return;}, - read: function(){return new Buffer('data', 'utf8');}, - end: function(){return Promise.resolve;}, - }; - var sinon = require('sinon'); - var spy = sinon.spy(fakeSocket, "write"); - response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); - let settings = new TestAdapterSettings(); - - await handler.connectWebSocket(request, response, settings).then(function(){ - return; - }); - - let connection = handler.createConnectorClient('fakeUrl'); - connection.sendRequest({method: 'POST', url: 'testResultDotCom', body: 'Test body!'}); - expect(spy.called).to.be.true; - }).timeout(2000); - - it('returns a 500 when bot can not run', async () => { - const MiddleWare = require('botbuilder-core'); - let bot = {}; - let mw = { - async onTurn(context, next) - { - console.log('Middleware executed!'); - await next(); - }}; - let mwset = []; - mwset.push(mw); - let handler = new Adapter.BotFrameworkStreamingAdapter({ bot: bot, middleWare: mwset}); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(500); - }); - }); - - it('executes middleware', async () => { - var sinon = require('sinon'); - let bot= new ActivityHandler.ActivityHandler(); - bot.run = function(turnContext){return Promise.resolve();}; - let mw = { - async onTurn(context, next) - { - console.log('Middleware executed!'); - await next(); - }}; - - let mwset = []; - mwset.push(mw); - let handler = new Adapter.BotFrameworkStreamingAdapter({bot: bot, middleWare: mwset}); - handler.bot.run = function(turnContext){return Promise.resolve();}; - var spy = sinon.spy(handler.bot, "run"); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(501); - expect(spy.called).to.be.true; - }); - }); +const Adapter = require('../lib/botFrameworkStreamingAdapter'); +const ActivityHandler = require("botbuilder-core"); +const chai = require('chai'); +var expect = chai.expect; + +class FauxSock{ + constructor(contentString){ + if(contentString){ + this.contentString = contentString; + this.position = 0; + } + this.connected = true; + } + isConnected(){ return this.connected; } + write(buffer){ return ; } + connect(serverAddress){ return new Promise(); } + close(){ this.connected = false; return; } + setOnMessageHandler(handler){ return; } //(x: any) => void); + setOnErrorHandler(handler){ return; } + setOnCloseHandler(handler){ return; } +} + +class TestRequest { + constructor(){ + let headers = []; + } + + isUpgradeRequest(){ + return this.upgradeRequestVal; + } + + setIsUpgradeRequest(value){ + this.upgradeRequestVal = value; + } + + status(){ + return this.statusVal; + } + + status(value){ + this.statusVal = value; + } + + path(value){ + this.pathVal = value; + } + + path(){ + return this.pathVal; + } + + verb(value){ + this.verbVal = value; + } + + verb(){ + return this.verbVal; + } + + streams(value){ + this.streamsVal = value; + } + + streams(){ + return this.streamsVal; + } + + setHeaders(){ + return this.headersVal; + } + + setHeaders(value){ + this.headers = value; + } + +} + +class TestResponse { + + construtor(){ + } + + send(value){ + this.sendVal = value; + return this.sendVal; + } + + status(value){ + this.statusVal = value; + return this.statusVal; + } + + setClaimUpgrade(value) + { + this.claimUpgradeVal = value; + } + + claimUpgrade(){ + return this.claimUpgradeVal; + } +} + +class TestAdapterSettings { + constructor(appId = undefined, appPassword = undefined, channelAuthTenant, oAuthEndpoint, openIdMetadata, channelServce){ + this.appId = appId; + this.appPassword = appPassword; + } +} + +describe('BotFrameworkStreamingAdapter tests', () => { + + it('has the correct status codes', () => { + expect(Adapter.StatusCodes.OK).to.equal(200); + expect(Adapter.StatusCodes.BAD_REQUEST).to.equal(400); + expect(Adapter.StatusCodes.UNAUTHORIZED).to.equal(401); + expect(Adapter.StatusCodes.NOT_FOUND).to.equal(404); + expect(Adapter.StatusCodes.METHOD_NOT_ALLOWED).to.equal(405); + expect(Adapter.StatusCodes.UPGRADE_REQUIRED).to.equal(426); + expect(Adapter.StatusCodes.INTERNAL_SERVER_ERROR).to.equal(500); + expect(Adapter.StatusCodes.NOT_IMPLEMENTED).to.equal(501); + }); + + it('gets constructed properly', () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + + expect(handler).to.be.instanceOf(Adapter.BotFrameworkStreamingAdapter); + expect(handler.bot).to.equal(bot); + expect(handler.logger).to.equal(console); + expect(handler.middleWare).to.be.an('array').that.is.empty; + }); + + it('starts and stops a namedpipe server', () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + + handler.connectNamedPipe('PipeyMcPipeface'); + expect(handler.server.disconnect()).to.not.throw; + }); + + it('starts and stops a websocket server', (done) => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + let response = new TestResponse({claimUpgrade:'anything'}); + let settings = new TestAdapterSettings(undefined, undefined); + + expect(handler.connectWebSocket(request, response, settings)).to.not.throw; + done(); + }); + + it('returns a connector client', () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + cc = handler.createConnectorClient('www.contoso.com'); + expect(cc.baseUri).to.equal('www.contoso.com'); + }); + + it('connectWebSocket returns an error when request is not an upgrade request', () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.setIsUpgradeRequest(false); + let response = new TestResponse(); + let settings = new TestAdapterSettings(undefined, undefined); + + handler.connectWebSocket(request, response, settings).catch(); + expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); + expect(response.statusVal).to.equal(426); + }); + + it('connectWebSocket returns status code 401 when request is not authorized', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + request.setHeaders({channelid: 'fakechannel', authorization: 'donttrustme'}); + let response = new TestResponse(); + let settings = new TestAdapterSettings('appId', 'password'); + + await handler.connectWebSocket(request, response, settings).then(function(){ + return; + }); + expect(response.sendVal).to.equal(undefined); + expect(response.statusVal).to.equal(401); + }); + + it('connectWebSocket connects', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + request.headers = []; + request.headers['upgrade'] = 'websocket'; + request.headers['sec-websocket-key'] = 'BFlat'; + request.headers['sec-websocket-version'] = '13'; + request.headers['sec-websocket-protocol'] = ''; + let response = new TestResponse(); + let fakeSocket = { + unshift: function(){return true;}, + write: function(value){console.log(value);}, + on: function(value){console.log(value);}, + read: function(){return new Buffer('data', 'utf8');}, + end: function(){return;}, + }; + response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); + let settings = new TestAdapterSettings(); + + await handler.connectWebSocket(request, response, settings).then(function(){ + return; + }); + }); + + it('returns a 400 when the request is missing verb', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = undefined; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(400); + }); + }); + + it('returns a 400 when the request is missing path', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = undefined; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(400); + }); + }); + + it('returns a 400 when the request body is missing', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest( 'POST', '/api/messages'); + request.verb = 'POST'; + request.path = '/api/messages'; + request.streams = undefined; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(400); + }); + }); + + it('returns user agent information when a GET hits the version endpoint', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'GET'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(200); + expect(response.streams[0].content).to.not.be.undefined; + }); + }); + + it('returns user agent information from cache when a GET hits the version endpoint more than once', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'GET'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(200); + expect(response.streams[0].content).to.not.be.undefined; + }); + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(200); + expect(response.streams[0].content).to.not.be.undefined; + }); + }); + + it('returns 405 for unsupported methods', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'UPDATE'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(405); + }); + }); + + it('returns 404 for unsupported paths', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/supersecretbackdoor'; + let fakeStream = { + readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(404); + }); + }); + + it('processes a well formed request when there is no middleware with a non-Invoke activity type', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function(){ return {type: 'something', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(200); + }); + }); + + it('returns a 501 when activity type is invoke, but the activity is invalid', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(501); + }); + }); + + it('sends a request', async () => { + let bot = new ActivityHandler.ActivityHandler(); + let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + request.headers = []; + request.headers['upgrade'] = 'websocket'; + request.headers['sec-websocket-key'] = 'BFlat'; + request.headers['sec-websocket-version'] = '13'; + request.headers['sec-websocket-protocol'] = ''; + let response = new TestResponse(); + let fakeSocket = { + unshift: function(){return true;}, + write: function(){return Promise.resolve; }, + on: function(){return;}, + read: function(){return new Buffer('data', 'utf8');}, + end: function(){return Promise.resolve;}, + }; + var sinon = require('sinon'); + var spy = sinon.spy(fakeSocket, "write"); + response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); + let settings = new TestAdapterSettings(); + + await handler.connectWebSocket(request, response, settings).then(function(){ + return; + }); + + let connection = handler.createConnectorClient('fakeUrl'); + connection.sendRequest({method: 'POST', url: 'testResultDotCom', body: 'Test body!'}); + expect(spy.called).to.be.true; + }).timeout(2000); + + it('returns a 500 when bot can not run', async () => { + const MiddleWare = require('botbuilder-core'); + let bot = {}; + let mw = { + async onTurn(context, next) + { + console.log('Middleware executed!'); + await next(); + }}; + let mwset = []; + mwset.push(mw); + let handler = new Adapter.BotFrameworkStreamingAdapter({ bot: bot, middleWare: mwset}); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(500); + }); + }); + + it('executes middleware', async () => { + var sinon = require('sinon'); + let bot= new ActivityHandler.ActivityHandler(); + bot.run = function(turnContext){return Promise.resolve();}; + let mw = { + async onTurn(context, next) + { + console.log('Middleware executed!'); + await next(); + }}; + + let mwset = []; + mwset.push(mw); + let handler = new Adapter.BotFrameworkStreamingAdapter({bot: bot, middleWare: mwset}); + handler.bot.run = function(turnContext){return Promise.resolve();}; + var spy = sinon.spy(handler.bot, "run"); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, + }; + request.streams[0] = fakeStream; + + await handler.processRequest(request).then( + function(response) { + expect(response.statusCode).to.equal(501); + expect(spy.called).to.be.true; + }); + }); }); \ No newline at end of file diff --git a/libraries/botframework-streaming/package.json b/libraries/botframework-streaming/package.json index 30267b65aa..21fdabffaa 100644 --- a/libraries/botframework-streaming/package.json +++ b/libraries/botframework-streaming/package.json @@ -1,6 +1,6 @@ { "name": "botframework-streaming", - "version": "4.6.1", + "version": "4.1.6", "description": "", "main": "lib/index.js", "typings": "lib/index.d.js", From 59a1da33c087cd5728c2f44ef4ff2041abc0955b Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 11:20:08 -0700 Subject: [PATCH 03/32] Streaming: integrate streaming into botFrameworkAdapter though useWebSocket and useNamedPipe methods --- libraries/botbuilder-core/src/botAdapter.ts | 2 +- libraries/botbuilder-core/src/turnContext.ts | 15 +- .../botbuilder/src/botFrameworkAdapter.ts | 261 +++++++++++++++- .../src/botFrameworkStreamingAdapter.ts | 289 ------------------ .../botFrameworkStreamingAdapter.test.js | 129 ++++---- 5 files changed, 345 insertions(+), 351 deletions(-) delete mode 100644 libraries/botbuilder/src/botFrameworkStreamingAdapter.ts diff --git a/libraries/botbuilder-core/src/botAdapter.ts b/libraries/botbuilder-core/src/botAdapter.ts index 41ec41eb24..6dddf9516d 100644 --- a/libraries/botbuilder-core/src/botAdapter.ts +++ b/libraries/botbuilder-core/src/botAdapter.ts @@ -18,7 +18,7 @@ import { TurnContext } from './turnContext'; * of channels. */ export abstract class BotAdapter { - private middleware: MiddlewareSet = new MiddlewareSet(); + protected middleware: MiddlewareSet = new MiddlewareSet(); private turnError: (context: TurnContext, error: Error) => Promise; /** diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index 3aa7a5f39a..fcf48b84a9 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -544,9 +544,20 @@ export class TurnContext { * This can be determined by looking at the ServiceUrl property: * (1) All channels that send messages via http/https are not streaming * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. - * @param activity + * @param activity the activity. */ public static isFromStreamingConnection(activity: Activity): boolean { - return activity && activity.serviceUrl && !activity.serviceUrl.toLowerCase().startsWith('http'); + return activity && this.isStreamingServiceUrl(activity.serviceUrl); + } + + /** + * Determine if the serviceUrl was sent via an Http/Https connection or Streaming + * This can be determined by looking at the ServiceUrl property: + * (1) All channels that send messages via http/https are not streaming + * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. + * @param serviceUrl the serviceUrl provided in the resquest. + */ + public static isStreamingServiceUrl(serviceUrl: string): boolean { + return serviceUrl && !serviceUrl.toLowerCase().startsWith('http'); } } diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 795bc4eef5..95d911681f 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -7,6 +7,54 @@ import { Activity, ActivityTypes, BotAdapter, BotCallbackHandlerKey, ChannelAcco import { AuthenticationConstants, ChannelValidation, ConnectorClient, EmulatorApiClient, GovernmentConstants, GovernmentChannelValidation, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider, TokenApiClient, TokenStatus, TokenApiModels } from 'botframework-connector'; import * as os from 'os'; import { TokenResolver } from './tokenResolver'; +import { IStreamingTransportServer, StreamingRequest, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming/lib'; +import { WebResource, HttpOperationResponse, HttpClient } from 'botframework-connector/node_modules/@azure/ms-rest-js'; +import { Request, ServerUpgradeResponse } from 'restify'; +import { Watershed } from 'watershed'; + +export enum StatusCodes { + OK = 200, + BAD_REQUEST = 400, + UNAUTHORIZED = 401, + NOT_FOUND = 404, + METHOD_NOT_ALLOWED = 405, + UPGRADE_REQUIRED = 426, + INTERNAL_SERVER_ERROR = 500, + NOT_IMPLEMENTED = 501, +} + +class StreamingHttpClient implements HttpClient { + private readonly server: IStreamingTransportServer; + + public constructor(server: IStreamingTransportServer) { + 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. + /// + /// The outgoing request created by the BotframeworkAdapter. + /// The streaming transport compatible response to send back to the client. + public async sendRequest(httpRequest: WebResource): Promise { + 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); + } +} /** * Represents an Express or Restify request object. @@ -136,6 +184,11 @@ const USER_AGENT: string = `Microsoft-BotFramework/3.1 BotBuilder/${ pjson.versi const OAUTH_ENDPOINT = 'https://api.botframework.com'; const US_GOV_OAUTH_ENDPOINT = 'https://api.botframework.azure.us'; const INVOKE_RESPONSE_KEY: symbol = Symbol('invokeResponse'); +const defaultPipeName = 'bfv4.pipes'; +const VERSION_PATH:string = '/api/version'; +const MESSAGES_PATH:string = '/api/messages'; +const GET:string = 'GET'; +const POST:string = 'POST'; /** * A [BotAdapter](xref:botbuilder-core.BotAdapter) that can connect a bot to a service endpoint. @@ -172,10 +225,17 @@ const INVOKE_RESPONSE_KEY: symbol = Symbol('invokeResponse'); * ``` */ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvider { - protected readonly credentials: MicrosoftAppCredentials; - protected readonly credentialsProvider: SimpleCredentialProvider; - protected readonly settings: BotFrameworkAdapterSettings; - private isEmulatingOAuthCards: boolean; + private readonly credentials: MicrosoftAppCredentials; + private readonly credentialsProvider: SimpleCredentialProvider; + private readonly settings: BotFrameworkAdapterSettings; + private readonly logger; + + private streamingLogic: (context: TurnContext) => Promise; + + private isEmulatingOAuthCards: boolean; + private streamingServer: IStreamingTransportServer; + + /** * Creates a new instance of the [BotFrameworkAdapter](xref:botbuilder.BotFrameworkAdapter) class. @@ -286,7 +346,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * An asynchronous method that creates and starts a conversation with a user on a channel. * * @param reference A reference for the conversation to create. - * @param logic The asynchronous method to call after the adapter middleware runs. + * @param logic The asynchronous method to call after the adapter middleware runs. If not provided, the adap * * @remarks * To use this method, you need both the bot's and the user's account information on a channel. @@ -881,6 +941,133 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide ); } + /// + /// Checks the validity of the request and attempts to map it the correct virtual endpoint, + /// then generates and returns a response if appropriate. + /// + /// A ReceiveRequest from the connected channel. + /// A response created by the BotAdapter to be sent to the client that originated the request. + public async processRequest(request: IReceiveRequest): Promise { + let response = new StreamingResponse(); + + if (!request || !request.verb || !request.path) { + response.statusCode = StatusCodes.BAD_REQUEST; + //this.logger.log('Request missing verb and/or path.'); + + return response; + } + + if (request.verb.toLocaleUpperCase() === GET && request.path.toLocaleLowerCase() === VERSION_PATH) { + response.statusCode = StatusCodes.OK; + response.setBody(this.getUserAgent()); + + return response; + } + + let body: Activity; + try { + body = await this.readRequestBodyAsString(request); + + } catch (error) { + response.statusCode = StatusCodes.BAD_REQUEST; + //this.logger.log('Unable to read request body. Error: ' + error); + + return response; + } + + if (request.verb.toLocaleUpperCase() !== POST) { + response.statusCode = StatusCodes.METHOD_NOT_ALLOWED; + + return response; + } + + if (request.path.toLocaleLowerCase() !== MESSAGES_PATH) { + response.statusCode = StatusCodes.NOT_FOUND; + + return response; + } + + try { + let context = new TurnContext(this, body); + await this.runMiddleware(context, async (turnContext): Promise => { + await this.streamingLogic(context); + }); + + if (body.type === ActivityTypes.Invoke) { + let invokeResponse: any = context.turnState.get(INVOKE_RESPONSE_KEY); + + if (invokeResponse && invokeResponse.value) { + const value: InvokeResponse = invokeResponse.value; + response.statusCode = value.status; + response.setBody(value.body); + } else { + response.statusCode = StatusCodes.NOT_IMPLEMENTED; + } + } else { + response.statusCode = StatusCodes.OK; + } + } catch (error) { + response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR; + //this.logger.log(error); + + return response; + + } + + return response; + } + + /// + /// Process the initial request to establish a long lived connection via a streaming server. + /// + /// The connection request. + /// The response sent on error or connection termination. + /// Settings to set on the BotframeworkAdapter. + public async useWebSocket(req: Request, res: ServerUpgradeResponse, streamingLogic: (context: TurnContext) => Promise): Promise { + if (!req.isUpgradeRequest()) { + let e = new Error('Upgrade to WebSockets required.'); + //this.logger.log(e); + res.status(StatusCodes.UPGRADE_REQUIRED); + res.send(e.message); + + return Promise.resolve(); + } + + if (!streamingLogic) { + throw new Error('Streaming logic needs to be provided to `useWebSocket`'); + } + + this.streamingLogic = streamingLogic; + + const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); + if (!authenticated) { + //this.logger.log('Unauthorized connection attempt.'); + res.status(StatusCodes.UNAUTHORIZED); + + return Promise.resolve(); + } + + const upgrade = res.claimUpgrade(); + const ws = new Watershed(); + const socket = ws.accept(req, upgrade.socket, upgrade.head); + + await this.startWebSocket(new NodeWebSocket(socket)); + } + /// + /// Connects the handler to a Named Pipe server and begins listening for incoming requests. + /// + /// The name of the named pipe to use when creating the server. + public async useNamedPipe(pipename: string = defaultPipeName, streamingLogic: (context: TurnContext) => Promise): Promise{ + if (!streamingLogic) { + throw new Error('Streaming logic needs to be provided to `useNamedPipe`'); + } + + this.streamingLogic = streamingLogic; + + this.streamingServer = new NamedPipeServer(pipename, this); + await this.streamingServer.start(); + } + /** * Allows for the overriding of authentication in unit tests. * @param request Received request. @@ -904,6 +1091,16 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * Override this in a derived class to create a mock connector client for unit testing. */ public createConnectorClient(serviceUrl: string): ConnectorClient { + if (TurnContext.isStreamingServiceUrl(serviceUrl)) { + return new ConnectorClient( + this.credentials, + { + baseUri: serviceUrl, + userAgent: USER_AGENT, + httpClient: new StreamingHttpClient(this.streamingServer) + }); + } + const client: ConnectorClient = new ConnectorClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT} ); return client; } @@ -967,6 +1164,60 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide protected createContext(request: Partial): TurnContext { return new TurnContext(this as any, request); } + + private async authenticateConnection(req: WebRequest, appId?: string, appPassword?: string, channelService?: string): Promise { + if (!appId || !appPassword) { + // auth is disabled + return true; + } + + try { + let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; + let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; + let credentials = new MicrosoftAppCredentials(appId, appPassword); + let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); + let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); + + return claims.isAuthenticated; + } catch (error) { + //this.logger.log(error); + + return false; + } + } + + /// + /// Connects the handler to a WebSocket server and begins listening for incoming requests. + /// + /// The socket to use when creating the server. + private async startWebSocket(socket: ISocket): Promise{ + this.streamingServer = new WebSocketServer(socket, this); + await this.streamingServer.start(); + } + + private async readRequestBodyAsString(request: IReceiveRequest): Promise { + try { + let contentStream = request.streams[0]; + + return await contentStream.readAsJson(); + } catch (error) { + //this.logger.log(error); + + return Promise.reject(error); + } + } + + private getUserAgent(): string { + if(USER_AGENT){ + return USER_AGENT; + } + const ARCHITECTURE: any = os.arch(); + const TYPE: any = os.type(); + const RELEASE: any = os.release(); + const NODE_VERSION: any = process.version; + return `Microsoft-BotFramework/3.1 BotBuilder/${ pjson.version } ` + + `(Node.js,Version=${ NODE_VERSION }; ${ TYPE } ${ RELEASE }; ${ ARCHITECTURE })`; + } } /** diff --git a/libraries/botbuilder/src/botFrameworkStreamingAdapter.ts b/libraries/botbuilder/src/botFrameworkStreamingAdapter.ts deleted file mode 100644 index 73ac29a8f4..0000000000 --- a/libraries/botbuilder/src/botFrameworkStreamingAdapter.ts +++ /dev/null @@ -1,289 +0,0 @@ -/** - * @module botbuilder - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -//import { BotFrameworkAdapterSettings, InvokeResponse, BotFrameworkAdapter, WebRequest, WebResponse } from 'botbuilder'; -import { ActivityHandler, Middleware, MiddlewareHandler, TurnContext } from 'botbuilder-core'; -import { ConnectorClient, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider } from 'botframework-connector'; -import { Activity, ActivityTypes } from 'botframework-schema'; -import * as os from 'os'; -import { ISocket, IStreamingTransportServer, IReceiveRequest, NamedPipeServer, NodeWebSocket, - RequestHandler, StreamingResponse, WebSocketServer, StreamingRequest } from 'botframework-streaming'; -import { HttpClient, HttpOperationResponse, WebResource } from '@azure/ms-rest-js'; -import { Watershed } from 'watershed'; -import { Request, ServerUpgradeResponse } from 'restify'; -import { BotFrameworkAdapter, BotFrameworkAdapterSettings, InvokeResponse, WebRequest } from '.'; - -export enum StatusCodes { - OK = 200, - BAD_REQUEST = 400, - UNAUTHORIZED = 401, - NOT_FOUND = 404, - METHOD_NOT_ALLOWED = 405, - UPGRADE_REQUIRED = 426, - INTERNAL_SERVER_ERROR = 500, - NOT_IMPLEMENTED = 501, -} - -const defaultPipeName = 'bfv4.pipes'; -const pjson: any = require('../package.json'); -const VERSION_PATH:string = '/api/version'; -const MESSAGES_PATH:string = '/api/messages'; -const INVOKE_RESPONSE:string = 'BotFrameworkStreamingAdapter.InvokeResponse'; -const GET:string = 'GET'; -const POST:string = 'POST'; -let USER_AGENT:string; - -/// -/// Used to process incoming requests sent over an and adhering to the Bot Framework Protocol v3 with Streaming Extensions. -/// -export class BotFrameworkStreamingAdapter extends BotFrameworkAdapter implements RequestHandler { - private bot: ActivityHandler; - private logger; - private server: IStreamingTransportServer; - private middleWare: (MiddlewareHandler|Middleware)[]; - - /// - /// Initializes a new instance of the class. - /// The StreamingRequestHandler serves as a translation layer between the transport layer and bot adapter. - /// It receives ReceiveRequests from the transport and provides them to the bot adapter in a form - /// it is able to build activities out of, which are then handed to the bot itself to processed. - /// Throws error if arguments are null. - /// - /// The bot to be used for all requests to this handler. - /// Optional logger, defaults to console. - /// The settings for use with the BotFrameworkAdapter. - /// An optional set of middleware to register with the adapter. - public constructor(bot: ActivityHandler, logger = console, settings?: BotFrameworkAdapterSettings, middleWare: (MiddlewareHandler|Middleware)[] = []) { - super(settings); - this.bot = bot; - this.logger = logger; - this.middleWare = middleWare; - } - - /// - /// Process the initial request to establish a long lived connection via a streaming server. - /// - /// The connection request. - /// The response sent on error or connection termination. - /// Settings to set on the BotframeworkAdapter. - public async connectWebSocket(req: Request, res: ServerUpgradeResponse, settings: BotFrameworkAdapterSettings): Promise { - if (!req.isUpgradeRequest()) { - let e = new Error('Upgrade to WebSockets required.'); - this.logger.log(e); - res.status(StatusCodes.UPGRADE_REQUIRED); - res.send(e.message); - - return Promise.resolve(); - } - - const authenticated = await this.authenticateConnection(req, settings.appId, settings.appPassword, settings.channelService); - if (!authenticated) { - this.logger.log('Unauthorized connection attempt.'); - res.status(StatusCodes.UNAUTHORIZED); - - return Promise.resolve(); - } - - const upgrade = res.claimUpgrade(); - const ws = new Watershed(); - const socket = ws.accept(req, upgrade.socket, upgrade.head); - - await this.startWebSocket(new NodeWebSocket(socket)); - } - - /// - /// Connects the handler to a Named Pipe server and begins listening for incoming requests. - /// - /// The name of the named pipe to use when creating the server. - public async connectNamedPipe(pipename: string = defaultPipeName): Promise{ - this.server = new NamedPipeServer(pipename, this); - await this.server.start(); - } - - /// - /// Checks the validity of the request and attempts to map it the correct virtual endpoint, - /// then generates and returns a response if appropriate. - /// - /// A ReceiveRequest from the connected channel. - /// A response created by the BotAdapter to be sent to the client that originated the request. - public async processRequest(request: IReceiveRequest): Promise { - let response = new StreamingResponse(); - - if (!request || !request.verb || !request.path) { - response.statusCode = StatusCodes.BAD_REQUEST; - this.logger.log('Request missing verb and/or path.'); - - return response; - } - - if (request.verb.toLocaleUpperCase() === GET && request.path.toLocaleLowerCase() === VERSION_PATH) { - response.statusCode = StatusCodes.OK; - response.setBody(this.getUserAgent()); - - return response; - } - - let body: Activity; - try { - body = await this.readRequestBodyAsString(request); - - } catch (error) { - response.statusCode = StatusCodes.BAD_REQUEST; - this.logger.log('Unable to read request body. Error: ' + error); - - return response; - } - - if (request.verb.toLocaleUpperCase() !== POST) { - response.statusCode = StatusCodes.METHOD_NOT_ALLOWED; - - return response; - } - - if (request.path.toLocaleLowerCase() !== MESSAGES_PATH) { - response.statusCode = StatusCodes.NOT_FOUND; - - return response; - } - - try { - this.middleWare.forEach((mw): void => { - this.use(mw); - }); - let context = new TurnContext(this, body); - await this.runMiddleware(context, async (turnContext): Promise => { - await this.bot.run(turnContext); - }); - - if (body.type === ActivityTypes.Invoke) { - let invokeResponse: any = context.turnState.get(INVOKE_RESPONSE); - - if (invokeResponse && invokeResponse.value) { - const value: InvokeResponse = invokeResponse.value; - response.statusCode = value.status; - response.setBody(value.body); - } else { - response.statusCode = StatusCodes.NOT_IMPLEMENTED; - } - } else { - response.statusCode = StatusCodes.OK; - } - } catch (error) { - response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR; - this.logger.log(error); - - return response; - - } - - return response; - } - - /// - /// Hides the adapter's built in means of creating a connector client - /// and subtitutes a StreamingHttpClient in place of the standard HttpClient, - /// thus allowing compatibility with streaming extensions. - /// - public createConnectorClient(serviceUrl: string): ConnectorClient { - return new ConnectorClient( - this.credentials, - { - baseUri: serviceUrl, - userAgent: super['USER_AGENT'], - httpClient: new StreamingHttpClient(this.server) - }); - } - - private async authenticateConnection(req: WebRequest, appId?: string, appPassword?: string, channelService?: string): Promise { - if (!appId || !appPassword) { - // auth is disabled - return true; - } - - try { - let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; - let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; - let credentials = new MicrosoftAppCredentials(appId, appPassword); - let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); - let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); - - return claims.isAuthenticated; - } catch (error) { - this.logger.log(error); - - return false; - } - } - - /// - /// Connects the handler to a WebSocket server and begins listening for incoming requests. - /// - /// The socket to use when creating the server. - private async startWebSocket(socket: ISocket): Promise{ - this.server = new WebSocketServer(socket, this); - await this.server.start(); - } - - private async readRequestBodyAsString(request: IReceiveRequest): Promise { - try { - let contentStream = request.streams[0]; - - return await contentStream.readAsJson(); - } catch (error) { - this.logger.log(error); - - return Promise.reject(error); - } - } - - private getUserAgent(): string { - if(USER_AGENT){ - return USER_AGENT; - } - const ARCHITECTURE: any = os.arch(); - const TYPE: any = os.type(); - const RELEASE: any = os.release(); - const NODE_VERSION: any = process.version; - USER_AGENT = `Microsoft-BotFramework/3.1 BotBuilder/${ pjson.version } ` + - `(Node.js,Version=${ NODE_VERSION }; ${ TYPE } ${ RELEASE }; ${ ARCHITECTURE })`; - - return USER_AGENT; - } -} - -class StreamingHttpClient implements HttpClient { - private readonly server: IStreamingTransportServer; - - public constructor(server: IStreamingTransportServer) { - 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. - /// - /// The outgoing request created by the BotframeworkAdapter. - /// The streaming transport compatible response to send back to the client. - public async sendRequest(httpRequest: WebResource): Promise { - 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); - } -} diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 83546ee35e..83b8609d12 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -1,4 +1,4 @@ -const Adapter = require('../lib/botFrameworkStreamingAdapter'); +const Adapter = require('../lib/botFrameworkAdapter'); const ActivityHandler = require("botbuilder-core"); const chai = require('chai'); var expect = chai.expect; @@ -121,73 +121,77 @@ describe('BotFrameworkStreamingAdapter tests', () => { }); it('gets constructed properly', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); - expect(handler).to.be.instanceOf(Adapter.BotFrameworkStreamingAdapter); - expect(handler.bot).to.equal(bot); - expect(handler.logger).to.equal(console); - expect(handler.middleWare).to.be.an('array').that.is.empty; + expect(handler).to.be.instanceOf(Adapter.BotFrameworkAdapter); }); it('starts and stops a namedpipe server', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); - handler.connectNamedPipe('PipeyMcPipeface'); - expect(handler.server.disconnect()).to.not.throw; + handler.useNamedPipe('PipeyMcPipeface', async (context) => { + // Route to bot + await bot.run(context); + }); + expect(handler.streamingServer.disconnect()).to.not.throw; }); it('starts and stops a websocket server', (done) => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); let response = new TestResponse({claimUpgrade:'anything'}); - let settings = new TestAdapterSettings(undefined, undefined); - expect(handler.connectWebSocket(request, response, settings)).to.not.throw; + expect(handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + })).to.not.throw; done(); }); it('returns a connector client', () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); cc = handler.createConnectorClient('www.contoso.com'); expect(cc.baseUri).to.equal('www.contoso.com'); }); - it('connectWebSocket returns an error when request is not an upgrade request', () => { + it('useWebSocket returns an error when request is not an upgrade request', () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.setIsUpgradeRequest(false); let response = new TestResponse(); - let settings = new TestAdapterSettings(undefined, undefined); - handler.connectWebSocket(request, response, settings).catch(); + handler.useWebSocket(request, response, async (context) => { + // Route incoming streaming requests to bot + await bot.run(context); + }).catch(); expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); expect(response.statusVal).to.equal(426); }); - it('connectWebSocket returns status code 401 when request is not authorized', async () => { + it('useWebSocket returns status code 401 when request is not authorized', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(new TestAdapterSettings('appId', 'password')); let request = new TestRequest(); request.setIsUpgradeRequest(true); request.setHeaders({channelid: 'fakechannel', authorization: 'donttrustme'}); let response = new TestResponse(); - let settings = new TestAdapterSettings('appId', 'password'); - await handler.connectWebSocket(request, response, settings).then(function(){ + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }).then(function(){ return; }); expect(response.sendVal).to.equal(undefined); expect(response.statusVal).to.equal(401); }); - it('connectWebSocket connects', async () => { + it('useWebSocket connects', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.setIsUpgradeRequest(true); request.headers = []; @@ -204,16 +208,18 @@ describe('BotFrameworkStreamingAdapter tests', () => { end: function(){return;}, }; response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); - let settings = new TestAdapterSettings(); - await handler.connectWebSocket(request, response, settings).then(function(){ + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }).then(function(){ return; }); }); it('returns a 400 when the request is missing verb', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = undefined; request.path = '/api/messages'; @@ -230,7 +236,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns a 400 when the request is missing path', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'POST'; request.path = undefined; @@ -247,7 +253,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns a 400 when the request body is missing', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest( 'POST', '/api/messages'); request.verb = 'POST'; request.path = '/api/messages'; @@ -261,7 +267,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns user agent information when a GET hits the version endpoint', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'GET'; request.path = '/api/version'; @@ -279,7 +285,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns user agent information from cache when a GET hits the version endpoint more than once', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'GET'; request.path = '/api/version'; @@ -303,7 +309,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns 405 for unsupported methods', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'UPDATE'; request.path = '/api/version'; @@ -320,7 +326,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns 404 for unsupported paths', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/supersecretbackdoor'; @@ -337,7 +343,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('processes a well formed request when there is no middleware with a non-Invoke activity type', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/messages'; @@ -346,15 +352,20 @@ describe('BotFrameworkStreamingAdapter tests', () => { }; request.streams[0] = fakeStream; + handler.streamingLogic = async (context) => { + // Route to bot + await bot.run(context); + }; + await handler.processRequest(request).then( function(response) { expect(response.statusCode).to.equal(200); - }); + }); }); it('returns a 501 when activity type is invoke, but the activity is invalid', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/messages'; @@ -363,6 +374,11 @@ describe('BotFrameworkStreamingAdapter tests', () => { }; request.streams[0] = fakeStream; + handler.streamingLogic = async (context) => { + // Route to bot + await bot.run(context); + }; + await handler.processRequest(request).then( function(response) { expect(response.statusCode).to.equal(501); @@ -371,7 +387,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('sends a request', async () => { let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkStreamingAdapter(bot); + let handler = new Adapter.BotFrameworkAdapter(); let request = new TestRequest(); request.setIsUpgradeRequest(true); request.headers = []; @@ -390,9 +406,11 @@ describe('BotFrameworkStreamingAdapter tests', () => { var sinon = require('sinon'); var spy = sinon.spy(fakeSocket, "write"); response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); - let settings = new TestAdapterSettings(); - - await handler.connectWebSocket(request, response, settings).then(function(){ + + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }).then(function(){ return; }); @@ -412,7 +430,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { }}; let mwset = []; mwset.push(mw); - let handler = new Adapter.BotFrameworkStreamingAdapter({ bot: bot, middleWare: mwset}); + let handler = new Adapter.BotFrameworkAdapter({ bot: bot, middleWare: mwset}); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/messages'; @@ -429,20 +447,18 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('executes middleware', async () => { var sinon = require('sinon'); - let bot= new ActivityHandler.ActivityHandler(); + let bot = new ActivityHandler.ActivityHandler(); bot.run = function(turnContext){return Promise.resolve();}; - let mw = { - async onTurn(context, next) - { - console.log('Middleware executed!'); - await next(); - }}; - + + let mwset = []; - mwset.push(mw); - let handler = new Adapter.BotFrameworkStreamingAdapter({bot: bot, middleWare: mwset}); - handler.bot.run = function(turnContext){return Promise.resolve();}; - var spy = sinon.spy(handler.bot, "run"); + let handler = new Adapter.BotFrameworkAdapter(); + handler.use(async(context, next) => { + console.log('Middleware executed!'); + return next(); + }); + + var spy = sinon.spy(bot, 'run'); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/messages'; @@ -451,6 +467,11 @@ describe('BotFrameworkStreamingAdapter tests', () => { }; request.streams[0] = fakeStream; + handler.streamingLogic = async (context) => { + // Route to bot + await bot.run(context); + }; + await handler.processRequest(request).then( function(response) { expect(response.statusCode).to.equal(501); From fe6d846275a77e99fd3492d713e93a52362b91d3 Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 11:25:21 -0700 Subject: [PATCH 04/32] Streaming: temporary move for lower case folders --- .../src/Payloads/SendOperations.ts | 104 ++++++++-------- .../src/Payloads/StreamManager.ts | 116 +++++++++--------- .../PayloadAssembler.ts | 0 .../src/{Assemblers => assemblers2}/index.ts | 0 .../CancelDisassembler.ts | 0 .../HttpContentStreamDisassembler.ts | 0 .../PayloadDisassembler.ts | 0 .../RequestDisassembler.ts | 0 .../ResponseDisassembler.ts | 0 .../index.ts | 0 .../IAssemblerParams.ts | 0 .../{Interfaces => interfaces2}/IHeader.ts | 0 .../IHttpContentHeaders.ts | 0 .../IReceiveRequest.ts | 0 .../IReceiveResponse.ts | 0 .../IRequestPayload.ts | 0 .../IResponsePayload.ts | 0 .../ISendPacket.ts | 0 .../{Interfaces => interfaces2}/ISocket.ts | 0 .../IStreamDescription.ts | 0 .../IStreamWrapper.ts | 0 .../IStreamingTransportClient.ts | 0 .../IStreamingTransportServer.ts | 0 .../{Interfaces => interfaces2}/ITransport.ts | 0 .../ITransportReceiver.ts | 0 .../ITransportSender.ts | 0 .../src/{Interfaces => interfaces2}/index.ts | 0 .../NamedPipeClient.ts | 0 .../NamedPipeServer.ts | 0 .../NamedPipeTransport.ts | 0 .../src/{NamedPipe => namedpipe2}/index.ts | 0 .../PayloadReceiver.ts | 0 .../PayloadSender.ts | 0 .../TransportDisconnectedEventArgs.ts | 0 .../TransportDisconnectedEventHandler.ts | 0 .../index.ts | 0 .../HeaderSerializer.ts | 0 .../PayloadAssemblerManager.ts | 0 .../PayloadConstants.ts | 0 .../{Payloads => payloads2}/PayloadTypes.ts | 0 .../{Payloads => payloads2}/RequestManager.ts | 0 .../src/payloads2/SendOperations.ts | 52 ++++++++ .../src/payloads2/StreamManager.ts | 58 +++++++++ .../src/{Payloads => payloads2}/index.ts | 0 .../src/{Utilities => utilities2}/index.ts | 0 .../protocol-base.ts | 0 .../BrowserWebSocket.ts | 0 .../NodeWebSocket.ts | 0 .../WebSocketClient.ts | 0 .../WebSocketServer.ts | 0 .../WebSocketTransport.ts | 0 .../src/{WebSocket => webSocket2}/index.ts | 0 52 files changed, 220 insertions(+), 110 deletions(-) rename libraries/botframework-streaming/src/{Assemblers => assemblers2}/PayloadAssembler.ts (100%) rename libraries/botframework-streaming/src/{Assemblers => assemblers2}/index.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/CancelDisassembler.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/HttpContentStreamDisassembler.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/PayloadDisassembler.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/RequestDisassembler.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/ResponseDisassembler.ts (100%) rename libraries/botframework-streaming/src/{Disassemblers => disassemblers2}/index.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IAssemblerParams.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IHeader.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IHttpContentHeaders.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IReceiveRequest.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IReceiveResponse.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IRequestPayload.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IResponsePayload.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/ISendPacket.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/ISocket.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IStreamDescription.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IStreamWrapper.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IStreamingTransportClient.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/IStreamingTransportServer.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/ITransport.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/ITransportReceiver.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/ITransportSender.ts (100%) rename libraries/botframework-streaming/src/{Interfaces => interfaces2}/index.ts (100%) rename libraries/botframework-streaming/src/{NamedPipe => namedpipe2}/NamedPipeClient.ts (100%) rename libraries/botframework-streaming/src/{NamedPipe => namedpipe2}/NamedPipeServer.ts (100%) rename libraries/botframework-streaming/src/{NamedPipe => namedpipe2}/NamedPipeTransport.ts (100%) rename libraries/botframework-streaming/src/{NamedPipe => namedpipe2}/index.ts (100%) rename libraries/botframework-streaming/src/{PayloadTransport => payloadTransport2}/PayloadReceiver.ts (100%) rename libraries/botframework-streaming/src/{PayloadTransport => payloadTransport2}/PayloadSender.ts (100%) rename libraries/botframework-streaming/src/{PayloadTransport => payloadTransport2}/TransportDisconnectedEventArgs.ts (100%) rename libraries/botframework-streaming/src/{PayloadTransport => payloadTransport2}/TransportDisconnectedEventHandler.ts (100%) rename libraries/botframework-streaming/src/{PayloadTransport => payloadTransport2}/index.ts (100%) rename libraries/botframework-streaming/src/{Payloads => payloads2}/HeaderSerializer.ts (100%) rename libraries/botframework-streaming/src/{Payloads => payloads2}/PayloadAssemblerManager.ts (100%) rename libraries/botframework-streaming/src/{Payloads => payloads2}/PayloadConstants.ts (100%) rename libraries/botframework-streaming/src/{Payloads => payloads2}/PayloadTypes.ts (100%) rename libraries/botframework-streaming/src/{Payloads => payloads2}/RequestManager.ts (100%) create mode 100644 libraries/botframework-streaming/src/payloads2/SendOperations.ts create mode 100644 libraries/botframework-streaming/src/payloads2/StreamManager.ts rename libraries/botframework-streaming/src/{Payloads => payloads2}/index.ts (100%) rename libraries/botframework-streaming/src/{Utilities => utilities2}/index.ts (100%) rename libraries/botframework-streaming/src/{Utilities => utilities2}/protocol-base.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/BrowserWebSocket.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/NodeWebSocket.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/WebSocketClient.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/WebSocketServer.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/WebSocketTransport.ts (100%) rename libraries/botframework-streaming/src/{WebSocket => webSocket2}/index.ts (100%) diff --git a/libraries/botframework-streaming/src/Payloads/SendOperations.ts b/libraries/botframework-streaming/src/Payloads/SendOperations.ts index a558986304..0471926a53 100644 --- a/libraries/botframework-streaming/src/Payloads/SendOperations.ts +++ b/libraries/botframework-streaming/src/Payloads/SendOperations.ts @@ -1,52 +1,52 @@ -/** - * @module botframework-streaming - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { StreamingRequest } from '../StreamingRequest'; -import { StreamingResponse } from '../StreamingResponse'; -import { CancelDisassembler } from '../Disassemblers/CancelDisassembler'; -import { HttpContentStreamDisassembler } from '../Disassemblers/HttpContentStreamDisassembler'; -import { RequestDisassembler } from '../Disassemblers/RequestDisassembler'; -import { ResponseDisassembler } from '../Disassemblers/ResponseDisassembler'; -import { PayloadTypes } from './PayloadTypes'; - -export class SendOperations { - private readonly payloadSender: PayloadSender; - - public constructor(payloadSender: PayloadSender) { - this.payloadSender = payloadSender; - } - - public async sendRequest(id: string, request: StreamingRequest): Promise { - let disassembler = new RequestDisassembler(this.payloadSender, id, request); - - await disassembler.disassemble(); - - if (request.streams) { - request.streams.forEach(async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - }); - } - } - - public async sendResponse(id: string, response: StreamingResponse): Promise { - let disassembler = new ResponseDisassembler(this.payloadSender, id, response); - - await disassembler.disassemble(); - - if (response.streams) { - response.streams.forEach(async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - }); - } - } - - public async sendCancelStream(id: string): Promise { - let disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); - disassembler.disassemble(); - } -} +/** + * @module botframework-streaming + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +import { PayloadSender } from '../PayloadTransport/PayloadSender'; +import { StreamingRequest } from '../StreamingRequest'; +import { StreamingResponse } from '../StreamingResponse'; +import { CancelDisassembler } from '../disassemblers/CancelDisassembler'; +import { HttpContentStreamDisassembler } from '../disassemblers/HttpContentStreamDisassembler'; +import { RequestDisassembler } from '../disassemblers/RequestDisassembler'; +import { ResponseDisassembler } from '../disassemblers/ResponseDisassembler'; +import { PayloadTypes } from './PayloadTypes'; + +export class SendOperations { + private readonly payloadSender: PayloadSender; + + public constructor(payloadSender: PayloadSender) { + this.payloadSender = payloadSender; + } + + public async sendRequest(id: string, request: StreamingRequest): Promise { + let disassembler = new RequestDisassembler(this.payloadSender, id, request); + + await disassembler.disassemble(); + + if (request.streams) { + request.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); + } + } + + public async sendResponse(id: string, response: StreamingResponse): Promise { + let disassembler = new ResponseDisassembler(this.payloadSender, id, response); + + await disassembler.disassemble(); + + if (response.streams) { + response.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); + } + } + + public async sendCancelStream(id: string): Promise { + let disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); + disassembler.disassemble(); + } +} diff --git a/libraries/botframework-streaming/src/Payloads/StreamManager.ts b/libraries/botframework-streaming/src/Payloads/StreamManager.ts index dfa578aa89..2bdeb73039 100644 --- a/libraries/botframework-streaming/src/Payloads/StreamManager.ts +++ b/libraries/botframework-streaming/src/Payloads/StreamManager.ts @@ -1,58 +1,58 @@ -/** - * @module botframework-streaming - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -import { IHeader } from '../Interfaces/IHeader'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadAssembler } from '../Assemblers/PayloadAssembler'; - -export class StreamManager { - private readonly activeAssemblers = []; - private readonly onCancelStream: Function; - - public constructor(onCancelStream: Function) { - this.onCancelStream = onCancelStream; - } - - public getPayloadAssembler(id: string): PayloadAssembler { - if (!this.activeAssemblers[id]) { - // A new id has come in, kick off the process of tracking it. - let assembler = new PayloadAssembler(this, {id: id}); - this.activeAssemblers[id] = assembler; - - return assembler; - } else { - - return this.activeAssemblers[id]; - } - } - - public getPayloadStream(header: IHeader): SubscribableStream { - let assembler = this.getPayloadAssembler(header.id); - - return assembler.getPayloadStream(); - } - - public onReceive(header: IHeader, contentStream: SubscribableStream, contentLength: number): void { - if (!this.activeAssemblers[header.id]) { - return; - } - this.activeAssemblers[header.id].onReceive(header, contentStream, contentLength); - } - - public closeStream(id: string): void { - if (!this.activeAssemblers[id]) { - return; - } else { - let assembler: PayloadAssembler = this.activeAssemblers[id]; - this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); - let targetStream = assembler.getPayloadStream(); - if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { - this.onCancelStream(assembler); - } - } - } -} +/** + * @module botframework-streaming + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +import { IHeader } from '../Interfaces/IHeader'; +import { SubscribableStream } from '../SubscribableStream'; +import { PayloadAssembler } from '../assemblers/PayloadAssembler'; + +export class StreamManager { + private readonly activeAssemblers = []; + private readonly onCancelStream: Function; + + public constructor(onCancelStream: Function) { + this.onCancelStream = onCancelStream; + } + + public getPayloadAssembler(id: string): PayloadAssembler { + if (!this.activeAssemblers[id]) { + // A new id has come in, kick off the process of tracking it. + let assembler = new PayloadAssembler(this, {id: id}); + this.activeAssemblers[id] = assembler; + + return assembler; + } else { + + return this.activeAssemblers[id]; + } + } + + public getPayloadStream(header: IHeader): SubscribableStream { + let assembler = this.getPayloadAssembler(header.id); + + return assembler.getPayloadStream(); + } + + public onReceive(header: IHeader, contentStream: SubscribableStream, contentLength: number): void { + if (!this.activeAssemblers[header.id]) { + return; + } + this.activeAssemblers[header.id].onReceive(header, contentStream, contentLength); + } + + public closeStream(id: string): void { + if (!this.activeAssemblers[id]) { + return; + } else { + let assembler: PayloadAssembler = this.activeAssemblers[id]; + this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); + let targetStream = assembler.getPayloadStream(); + if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { + this.onCancelStream(assembler); + } + } + } +} diff --git a/libraries/botframework-streaming/src/Assemblers/PayloadAssembler.ts b/libraries/botframework-streaming/src/assemblers2/PayloadAssembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Assemblers/PayloadAssembler.ts rename to libraries/botframework-streaming/src/assemblers2/PayloadAssembler.ts diff --git a/libraries/botframework-streaming/src/Assemblers/index.ts b/libraries/botframework-streaming/src/assemblers2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/Assemblers/index.ts rename to libraries/botframework-streaming/src/assemblers2/index.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/CancelDisassembler.ts b/libraries/botframework-streaming/src/disassemblers2/CancelDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/CancelDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers2/CancelDisassembler.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/HttpContentStreamDisassembler.ts b/libraries/botframework-streaming/src/disassemblers2/HttpContentStreamDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/HttpContentStreamDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers2/HttpContentStreamDisassembler.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/PayloadDisassembler.ts b/libraries/botframework-streaming/src/disassemblers2/PayloadDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/PayloadDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers2/PayloadDisassembler.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/RequestDisassembler.ts b/libraries/botframework-streaming/src/disassemblers2/RequestDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/RequestDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers2/RequestDisassembler.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/ResponseDisassembler.ts b/libraries/botframework-streaming/src/disassemblers2/ResponseDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/ResponseDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers2/ResponseDisassembler.ts diff --git a/libraries/botframework-streaming/src/Disassemblers/index.ts b/libraries/botframework-streaming/src/disassemblers2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/Disassemblers/index.ts rename to libraries/botframework-streaming/src/disassemblers2/index.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IAssemblerParams.ts b/libraries/botframework-streaming/src/interfaces2/IAssemblerParams.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IAssemblerParams.ts rename to libraries/botframework-streaming/src/interfaces2/IAssemblerParams.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IHeader.ts b/libraries/botframework-streaming/src/interfaces2/IHeader.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IHeader.ts rename to libraries/botframework-streaming/src/interfaces2/IHeader.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IHttpContentHeaders.ts b/libraries/botframework-streaming/src/interfaces2/IHttpContentHeaders.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IHttpContentHeaders.ts rename to libraries/botframework-streaming/src/interfaces2/IHttpContentHeaders.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IReceiveRequest.ts b/libraries/botframework-streaming/src/interfaces2/IReceiveRequest.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IReceiveRequest.ts rename to libraries/botframework-streaming/src/interfaces2/IReceiveRequest.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IReceiveResponse.ts b/libraries/botframework-streaming/src/interfaces2/IReceiveResponse.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IReceiveResponse.ts rename to libraries/botframework-streaming/src/interfaces2/IReceiveResponse.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IRequestPayload.ts b/libraries/botframework-streaming/src/interfaces2/IRequestPayload.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IRequestPayload.ts rename to libraries/botframework-streaming/src/interfaces2/IRequestPayload.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IResponsePayload.ts b/libraries/botframework-streaming/src/interfaces2/IResponsePayload.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IResponsePayload.ts rename to libraries/botframework-streaming/src/interfaces2/IResponsePayload.ts diff --git a/libraries/botframework-streaming/src/Interfaces/ISendPacket.ts b/libraries/botframework-streaming/src/interfaces2/ISendPacket.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/ISendPacket.ts rename to libraries/botframework-streaming/src/interfaces2/ISendPacket.ts diff --git a/libraries/botframework-streaming/src/Interfaces/ISocket.ts b/libraries/botframework-streaming/src/interfaces2/ISocket.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/ISocket.ts rename to libraries/botframework-streaming/src/interfaces2/ISocket.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IStreamDescription.ts b/libraries/botframework-streaming/src/interfaces2/IStreamDescription.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IStreamDescription.ts rename to libraries/botframework-streaming/src/interfaces2/IStreamDescription.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IStreamWrapper.ts b/libraries/botframework-streaming/src/interfaces2/IStreamWrapper.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IStreamWrapper.ts rename to libraries/botframework-streaming/src/interfaces2/IStreamWrapper.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IStreamingTransportClient.ts b/libraries/botframework-streaming/src/interfaces2/IStreamingTransportClient.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IStreamingTransportClient.ts rename to libraries/botframework-streaming/src/interfaces2/IStreamingTransportClient.ts diff --git a/libraries/botframework-streaming/src/Interfaces/IStreamingTransportServer.ts b/libraries/botframework-streaming/src/interfaces2/IStreamingTransportServer.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/IStreamingTransportServer.ts rename to libraries/botframework-streaming/src/interfaces2/IStreamingTransportServer.ts diff --git a/libraries/botframework-streaming/src/Interfaces/ITransport.ts b/libraries/botframework-streaming/src/interfaces2/ITransport.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/ITransport.ts rename to libraries/botframework-streaming/src/interfaces2/ITransport.ts diff --git a/libraries/botframework-streaming/src/Interfaces/ITransportReceiver.ts b/libraries/botframework-streaming/src/interfaces2/ITransportReceiver.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/ITransportReceiver.ts rename to libraries/botframework-streaming/src/interfaces2/ITransportReceiver.ts diff --git a/libraries/botframework-streaming/src/Interfaces/ITransportSender.ts b/libraries/botframework-streaming/src/interfaces2/ITransportSender.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/ITransportSender.ts rename to libraries/botframework-streaming/src/interfaces2/ITransportSender.ts diff --git a/libraries/botframework-streaming/src/Interfaces/index.ts b/libraries/botframework-streaming/src/interfaces2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/Interfaces/index.ts rename to libraries/botframework-streaming/src/interfaces2/index.ts diff --git a/libraries/botframework-streaming/src/NamedPipe/NamedPipeClient.ts b/libraries/botframework-streaming/src/namedpipe2/NamedPipeClient.ts similarity index 100% rename from libraries/botframework-streaming/src/NamedPipe/NamedPipeClient.ts rename to libraries/botframework-streaming/src/namedpipe2/NamedPipeClient.ts diff --git a/libraries/botframework-streaming/src/NamedPipe/NamedPipeServer.ts b/libraries/botframework-streaming/src/namedpipe2/NamedPipeServer.ts similarity index 100% rename from libraries/botframework-streaming/src/NamedPipe/NamedPipeServer.ts rename to libraries/botframework-streaming/src/namedpipe2/NamedPipeServer.ts diff --git a/libraries/botframework-streaming/src/NamedPipe/NamedPipeTransport.ts b/libraries/botframework-streaming/src/namedpipe2/NamedPipeTransport.ts similarity index 100% rename from libraries/botframework-streaming/src/NamedPipe/NamedPipeTransport.ts rename to libraries/botframework-streaming/src/namedpipe2/NamedPipeTransport.ts diff --git a/libraries/botframework-streaming/src/NamedPipe/index.ts b/libraries/botframework-streaming/src/namedpipe2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/NamedPipe/index.ts rename to libraries/botframework-streaming/src/namedpipe2/index.ts diff --git a/libraries/botframework-streaming/src/PayloadTransport/PayloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport2/PayloadReceiver.ts similarity index 100% rename from libraries/botframework-streaming/src/PayloadTransport/PayloadReceiver.ts rename to libraries/botframework-streaming/src/payloadTransport2/PayloadReceiver.ts diff --git a/libraries/botframework-streaming/src/PayloadTransport/PayloadSender.ts b/libraries/botframework-streaming/src/payloadTransport2/PayloadSender.ts similarity index 100% rename from libraries/botframework-streaming/src/PayloadTransport/PayloadSender.ts rename to libraries/botframework-streaming/src/payloadTransport2/PayloadSender.ts diff --git a/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventArgs.ts b/libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventArgs.ts similarity index 100% rename from libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventArgs.ts rename to libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventArgs.ts diff --git a/libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventHandler.ts b/libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventHandler.ts similarity index 100% rename from libraries/botframework-streaming/src/PayloadTransport/TransportDisconnectedEventHandler.ts rename to libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventHandler.ts diff --git a/libraries/botframework-streaming/src/PayloadTransport/index.ts b/libraries/botframework-streaming/src/payloadTransport2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/PayloadTransport/index.ts rename to libraries/botframework-streaming/src/payloadTransport2/index.ts diff --git a/libraries/botframework-streaming/src/Payloads/HeaderSerializer.ts b/libraries/botframework-streaming/src/payloads2/HeaderSerializer.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/HeaderSerializer.ts rename to libraries/botframework-streaming/src/payloads2/HeaderSerializer.ts diff --git a/libraries/botframework-streaming/src/Payloads/PayloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads2/PayloadAssemblerManager.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/PayloadAssemblerManager.ts rename to libraries/botframework-streaming/src/payloads2/PayloadAssemblerManager.ts diff --git a/libraries/botframework-streaming/src/Payloads/PayloadConstants.ts b/libraries/botframework-streaming/src/payloads2/PayloadConstants.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/PayloadConstants.ts rename to libraries/botframework-streaming/src/payloads2/PayloadConstants.ts diff --git a/libraries/botframework-streaming/src/Payloads/PayloadTypes.ts b/libraries/botframework-streaming/src/payloads2/PayloadTypes.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/PayloadTypes.ts rename to libraries/botframework-streaming/src/payloads2/PayloadTypes.ts diff --git a/libraries/botframework-streaming/src/Payloads/RequestManager.ts b/libraries/botframework-streaming/src/payloads2/RequestManager.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/RequestManager.ts rename to libraries/botframework-streaming/src/payloads2/RequestManager.ts diff --git a/libraries/botframework-streaming/src/payloads2/SendOperations.ts b/libraries/botframework-streaming/src/payloads2/SendOperations.ts new file mode 100644 index 0000000000..a558986304 --- /dev/null +++ b/libraries/botframework-streaming/src/payloads2/SendOperations.ts @@ -0,0 +1,52 @@ +/** + * @module botframework-streaming + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +import { PayloadSender } from '../PayloadTransport/PayloadSender'; +import { StreamingRequest } from '../StreamingRequest'; +import { StreamingResponse } from '../StreamingResponse'; +import { CancelDisassembler } from '../Disassemblers/CancelDisassembler'; +import { HttpContentStreamDisassembler } from '../Disassemblers/HttpContentStreamDisassembler'; +import { RequestDisassembler } from '../Disassemblers/RequestDisassembler'; +import { ResponseDisassembler } from '../Disassemblers/ResponseDisassembler'; +import { PayloadTypes } from './PayloadTypes'; + +export class SendOperations { + private readonly payloadSender: PayloadSender; + + public constructor(payloadSender: PayloadSender) { + this.payloadSender = payloadSender; + } + + public async sendRequest(id: string, request: StreamingRequest): Promise { + let disassembler = new RequestDisassembler(this.payloadSender, id, request); + + await disassembler.disassemble(); + + if (request.streams) { + request.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); + } + } + + public async sendResponse(id: string, response: StreamingResponse): Promise { + let disassembler = new ResponseDisassembler(this.payloadSender, id, response); + + await disassembler.disassemble(); + + if (response.streams) { + response.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); + } + } + + public async sendCancelStream(id: string): Promise { + let disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); + disassembler.disassemble(); + } +} diff --git a/libraries/botframework-streaming/src/payloads2/StreamManager.ts b/libraries/botframework-streaming/src/payloads2/StreamManager.ts new file mode 100644 index 0000000000..dfa578aa89 --- /dev/null +++ b/libraries/botframework-streaming/src/payloads2/StreamManager.ts @@ -0,0 +1,58 @@ +/** + * @module botframework-streaming + */ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +import { IHeader } from '../Interfaces/IHeader'; +import { SubscribableStream } from '../SubscribableStream'; +import { PayloadAssembler } from '../Assemblers/PayloadAssembler'; + +export class StreamManager { + private readonly activeAssemblers = []; + private readonly onCancelStream: Function; + + public constructor(onCancelStream: Function) { + this.onCancelStream = onCancelStream; + } + + public getPayloadAssembler(id: string): PayloadAssembler { + if (!this.activeAssemblers[id]) { + // A new id has come in, kick off the process of tracking it. + let assembler = new PayloadAssembler(this, {id: id}); + this.activeAssemblers[id] = assembler; + + return assembler; + } else { + + return this.activeAssemblers[id]; + } + } + + public getPayloadStream(header: IHeader): SubscribableStream { + let assembler = this.getPayloadAssembler(header.id); + + return assembler.getPayloadStream(); + } + + public onReceive(header: IHeader, contentStream: SubscribableStream, contentLength: number): void { + if (!this.activeAssemblers[header.id]) { + return; + } + this.activeAssemblers[header.id].onReceive(header, contentStream, contentLength); + } + + public closeStream(id: string): void { + if (!this.activeAssemblers[id]) { + return; + } else { + let assembler: PayloadAssembler = this.activeAssemblers[id]; + this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); + let targetStream = assembler.getPayloadStream(); + if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { + this.onCancelStream(assembler); + } + } + } +} diff --git a/libraries/botframework-streaming/src/Payloads/index.ts b/libraries/botframework-streaming/src/payloads2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/Payloads/index.ts rename to libraries/botframework-streaming/src/payloads2/index.ts diff --git a/libraries/botframework-streaming/src/Utilities/index.ts b/libraries/botframework-streaming/src/utilities2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/Utilities/index.ts rename to libraries/botframework-streaming/src/utilities2/index.ts diff --git a/libraries/botframework-streaming/src/Utilities/protocol-base.ts b/libraries/botframework-streaming/src/utilities2/protocol-base.ts similarity index 100% rename from libraries/botframework-streaming/src/Utilities/protocol-base.ts rename to libraries/botframework-streaming/src/utilities2/protocol-base.ts diff --git a/libraries/botframework-streaming/src/WebSocket/BrowserWebSocket.ts b/libraries/botframework-streaming/src/webSocket2/BrowserWebSocket.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/BrowserWebSocket.ts rename to libraries/botframework-streaming/src/webSocket2/BrowserWebSocket.ts diff --git a/libraries/botframework-streaming/src/WebSocket/NodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket2/NodeWebSocket.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/NodeWebSocket.ts rename to libraries/botframework-streaming/src/webSocket2/NodeWebSocket.ts diff --git a/libraries/botframework-streaming/src/WebSocket/WebSocketClient.ts b/libraries/botframework-streaming/src/webSocket2/WebSocketClient.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/WebSocketClient.ts rename to libraries/botframework-streaming/src/webSocket2/WebSocketClient.ts diff --git a/libraries/botframework-streaming/src/WebSocket/WebSocketServer.ts b/libraries/botframework-streaming/src/webSocket2/WebSocketServer.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/WebSocketServer.ts rename to libraries/botframework-streaming/src/webSocket2/WebSocketServer.ts diff --git a/libraries/botframework-streaming/src/WebSocket/WebSocketTransport.ts b/libraries/botframework-streaming/src/webSocket2/WebSocketTransport.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/WebSocketTransport.ts rename to libraries/botframework-streaming/src/webSocket2/WebSocketTransport.ts diff --git a/libraries/botframework-streaming/src/WebSocket/index.ts b/libraries/botframework-streaming/src/webSocket2/index.ts similarity index 100% rename from libraries/botframework-streaming/src/WebSocket/index.ts rename to libraries/botframework-streaming/src/webSocket2/index.ts From f71af7560bfbdae251b295f0ed32da3751a3930b Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 11:30:51 -0700 Subject: [PATCH 05/32] Streaming: directory casing rename part 2 --- .../src/ContentStream.ts | 2 +- .../src/Payloads/SendOperations.ts | 52 ----------------- .../src/Payloads/StreamManager.ts | 58 ------------------- .../src/ProtocolAdapter.ts | 2 +- .../PayloadAssembler.ts | 0 .../src/{assemblers2 => assemblers}/index.ts | 0 .../CancelDisassembler.ts | 0 .../HttpContentStreamDisassembler.ts | 0 .../PayloadDisassembler.ts | 0 .../RequestDisassembler.ts | 0 .../ResponseDisassembler.ts | 0 .../index.ts | 0 .../IAssemblerParams.ts | 0 .../{interfaces2 => interfaces}/IHeader.ts | 0 .../IHttpContentHeaders.ts | 0 .../IReceiveRequest.ts | 0 .../IReceiveResponse.ts | 0 .../IRequestPayload.ts | 0 .../IResponsePayload.ts | 0 .../ISendPacket.ts | 0 .../{interfaces2 => interfaces}/ISocket.ts | 0 .../IStreamDescription.ts | 0 .../IStreamWrapper.ts | 0 .../IStreamingTransportClient.ts | 0 .../IStreamingTransportServer.ts | 0 .../{interfaces2 => interfaces}/ITransport.ts | 0 .../ITransportReceiver.ts | 0 .../ITransportSender.ts | 0 .../src/{interfaces2 => interfaces}/index.ts | 0 .../NamedPipeClient.ts | 0 .../NamedPipeServer.ts | 0 .../NamedPipeTransport.ts | 0 .../src/{namedpipe2 => namedPipe}/index.ts | 0 .../PayloadReceiver.ts | 0 .../PayloadSender.ts | 0 .../TransportDisconnectedEventArgs.ts | 0 .../TransportDisconnectedEventHandler.ts | 0 .../index.ts | 0 .../HeaderSerializer.ts | 0 .../PayloadAssemblerManager.ts | 0 .../PayloadConstants.ts | 0 .../{payloads2 => payloads3}/PayloadTypes.ts | 0 .../RequestManager.ts | 0 .../SendOperations.ts | 0 .../{payloads2 => payloads3}/StreamManager.ts | 0 .../src/{payloads2 => payloads3}/index.ts | 0 .../src/{utilities2 => utilities}/index.ts | 0 .../protocol-base.ts | 0 .../BrowserWebSocket.ts | 0 .../NodeWebSocket.ts | 0 .../WebSocketClient.ts | 0 .../WebSocketServer.ts | 0 .../WebSocketTransport.ts | 0 .../src/{webSocket2 => webSocket}/index.ts | 0 54 files changed, 2 insertions(+), 112 deletions(-) delete mode 100644 libraries/botframework-streaming/src/Payloads/SendOperations.ts delete mode 100644 libraries/botframework-streaming/src/Payloads/StreamManager.ts rename libraries/botframework-streaming/src/{assemblers2 => assemblers}/PayloadAssembler.ts (100%) rename libraries/botframework-streaming/src/{assemblers2 => assemblers}/index.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/CancelDisassembler.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/HttpContentStreamDisassembler.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/PayloadDisassembler.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/RequestDisassembler.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/ResponseDisassembler.ts (100%) rename libraries/botframework-streaming/src/{disassemblers2 => disassemblers}/index.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IAssemblerParams.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IHeader.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IHttpContentHeaders.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IReceiveRequest.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IReceiveResponse.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IRequestPayload.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IResponsePayload.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/ISendPacket.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/ISocket.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IStreamDescription.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IStreamWrapper.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IStreamingTransportClient.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/IStreamingTransportServer.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/ITransport.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/ITransportReceiver.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/ITransportSender.ts (100%) rename libraries/botframework-streaming/src/{interfaces2 => interfaces}/index.ts (100%) rename libraries/botframework-streaming/src/{namedpipe2 => namedPipe}/NamedPipeClient.ts (100%) rename libraries/botframework-streaming/src/{namedpipe2 => namedPipe}/NamedPipeServer.ts (100%) rename libraries/botframework-streaming/src/{namedpipe2 => namedPipe}/NamedPipeTransport.ts (100%) rename libraries/botframework-streaming/src/{namedpipe2 => namedPipe}/index.ts (100%) rename libraries/botframework-streaming/src/{payloadTransport2 => payloadTransport}/PayloadReceiver.ts (100%) rename libraries/botframework-streaming/src/{payloadTransport2 => payloadTransport}/PayloadSender.ts (100%) rename libraries/botframework-streaming/src/{payloadTransport2 => payloadTransport}/TransportDisconnectedEventArgs.ts (100%) rename libraries/botframework-streaming/src/{payloadTransport2 => payloadTransport}/TransportDisconnectedEventHandler.ts (100%) rename libraries/botframework-streaming/src/{payloadTransport2 => payloadTransport}/index.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/HeaderSerializer.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/PayloadAssemblerManager.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/PayloadConstants.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/PayloadTypes.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/RequestManager.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/SendOperations.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/StreamManager.ts (100%) rename libraries/botframework-streaming/src/{payloads2 => payloads3}/index.ts (100%) rename libraries/botframework-streaming/src/{utilities2 => utilities}/index.ts (100%) rename libraries/botframework-streaming/src/{utilities2 => utilities}/protocol-base.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/BrowserWebSocket.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/NodeWebSocket.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/WebSocketClient.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/WebSocketServer.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/WebSocketTransport.ts (100%) rename libraries/botframework-streaming/src/{webSocket2 => webSocket}/index.ts (100%) diff --git a/libraries/botframework-streaming/src/ContentStream.ts b/libraries/botframework-streaming/src/ContentStream.ts index 2b1d96d742..1ae62a8614 100644 --- a/libraries/botframework-streaming/src/ContentStream.ts +++ b/libraries/botframework-streaming/src/ContentStream.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ import { SubscribableStream } from './SubscribableStream'; -import { PayloadAssembler } from './Assemblers'; +import { PayloadAssembler } from './assemblers'; export class ContentStream { public id: string; diff --git a/libraries/botframework-streaming/src/Payloads/SendOperations.ts b/libraries/botframework-streaming/src/Payloads/SendOperations.ts deleted file mode 100644 index 0471926a53..0000000000 --- a/libraries/botframework-streaming/src/Payloads/SendOperations.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @module botframework-streaming - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { StreamingRequest } from '../StreamingRequest'; -import { StreamingResponse } from '../StreamingResponse'; -import { CancelDisassembler } from '../disassemblers/CancelDisassembler'; -import { HttpContentStreamDisassembler } from '../disassemblers/HttpContentStreamDisassembler'; -import { RequestDisassembler } from '../disassemblers/RequestDisassembler'; -import { ResponseDisassembler } from '../disassemblers/ResponseDisassembler'; -import { PayloadTypes } from './PayloadTypes'; - -export class SendOperations { - private readonly payloadSender: PayloadSender; - - public constructor(payloadSender: PayloadSender) { - this.payloadSender = payloadSender; - } - - public async sendRequest(id: string, request: StreamingRequest): Promise { - let disassembler = new RequestDisassembler(this.payloadSender, id, request); - - await disassembler.disassemble(); - - if (request.streams) { - request.streams.forEach(async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - }); - } - } - - public async sendResponse(id: string, response: StreamingResponse): Promise { - let disassembler = new ResponseDisassembler(this.payloadSender, id, response); - - await disassembler.disassemble(); - - if (response.streams) { - response.streams.forEach(async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - }); - } - } - - public async sendCancelStream(id: string): Promise { - let disassembler = new CancelDisassembler(this.payloadSender, id, PayloadTypes.cancelStream); - disassembler.disassemble(); - } -} diff --git a/libraries/botframework-streaming/src/Payloads/StreamManager.ts b/libraries/botframework-streaming/src/Payloads/StreamManager.ts deleted file mode 100644 index 2bdeb73039..0000000000 --- a/libraries/botframework-streaming/src/Payloads/StreamManager.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @module botframework-streaming - */ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ -import { IHeader } from '../Interfaces/IHeader'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadAssembler } from '../assemblers/PayloadAssembler'; - -export class StreamManager { - private readonly activeAssemblers = []; - private readonly onCancelStream: Function; - - public constructor(onCancelStream: Function) { - this.onCancelStream = onCancelStream; - } - - public getPayloadAssembler(id: string): PayloadAssembler { - if (!this.activeAssemblers[id]) { - // A new id has come in, kick off the process of tracking it. - let assembler = new PayloadAssembler(this, {id: id}); - this.activeAssemblers[id] = assembler; - - return assembler; - } else { - - return this.activeAssemblers[id]; - } - } - - public getPayloadStream(header: IHeader): SubscribableStream { - let assembler = this.getPayloadAssembler(header.id); - - return assembler.getPayloadStream(); - } - - public onReceive(header: IHeader, contentStream: SubscribableStream, contentLength: number): void { - if (!this.activeAssemblers[header.id]) { - return; - } - this.activeAssemblers[header.id].onReceive(header, contentStream, contentLength); - } - - public closeStream(id: string): void { - if (!this.activeAssemblers[id]) { - return; - } else { - let assembler: PayloadAssembler = this.activeAssemblers[id]; - this.activeAssemblers.splice(this.activeAssemblers.indexOf(id), 1); - let targetStream = assembler.getPayloadStream(); - if ((assembler.contentLength && targetStream.length < assembler.contentLength) || !assembler.end) { - this.onCancelStream(assembler); - } - } - } -} diff --git a/libraries/botframework-streaming/src/ProtocolAdapter.ts b/libraries/botframework-streaming/src/ProtocolAdapter.ts index ef6ec5ac4a..0cb04ee11a 100644 --- a/libraries/botframework-streaming/src/ProtocolAdapter.ts +++ b/libraries/botframework-streaming/src/ProtocolAdapter.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { PayloadAssembler } from './Assemblers/PayloadAssembler'; +import { PayloadAssembler } from './assemblers/PayloadAssembler'; import { PayloadAssemblerManager } from './Payloads/PayloadAssemblerManager'; import { RequestManager } from './Payloads/RequestManager'; import { SendOperations } from './Payloads/SendOperations'; diff --git a/libraries/botframework-streaming/src/assemblers2/PayloadAssembler.ts b/libraries/botframework-streaming/src/assemblers/PayloadAssembler.ts similarity index 100% rename from libraries/botframework-streaming/src/assemblers2/PayloadAssembler.ts rename to libraries/botframework-streaming/src/assemblers/PayloadAssembler.ts diff --git a/libraries/botframework-streaming/src/assemblers2/index.ts b/libraries/botframework-streaming/src/assemblers/index.ts similarity index 100% rename from libraries/botframework-streaming/src/assemblers2/index.ts rename to libraries/botframework-streaming/src/assemblers/index.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/CancelDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/CancelDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/CancelDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/CancelDisassembler.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/HttpContentStreamDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/HttpContentStreamDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/HttpContentStreamDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/HttpContentStreamDisassembler.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/PayloadDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/PayloadDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/PayloadDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/PayloadDisassembler.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/RequestDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/RequestDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/RequestDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/RequestDisassembler.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/ResponseDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/ResponseDisassembler.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/ResponseDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/ResponseDisassembler.ts diff --git a/libraries/botframework-streaming/src/disassemblers2/index.ts b/libraries/botframework-streaming/src/disassemblers/index.ts similarity index 100% rename from libraries/botframework-streaming/src/disassemblers2/index.ts rename to libraries/botframework-streaming/src/disassemblers/index.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IAssemblerParams.ts b/libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IAssemblerParams.ts rename to libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IHeader.ts b/libraries/botframework-streaming/src/interfaces/IHeader.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IHeader.ts rename to libraries/botframework-streaming/src/interfaces/IHeader.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IHttpContentHeaders.ts b/libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IHttpContentHeaders.ts rename to libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IReceiveRequest.ts b/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IReceiveRequest.ts rename to libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IReceiveResponse.ts b/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IReceiveResponse.ts rename to libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IRequestPayload.ts b/libraries/botframework-streaming/src/interfaces/IRequestPayload.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IRequestPayload.ts rename to libraries/botframework-streaming/src/interfaces/IRequestPayload.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IResponsePayload.ts b/libraries/botframework-streaming/src/interfaces/IResponsePayload.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IResponsePayload.ts rename to libraries/botframework-streaming/src/interfaces/IResponsePayload.ts diff --git a/libraries/botframework-streaming/src/interfaces2/ISendPacket.ts b/libraries/botframework-streaming/src/interfaces/ISendPacket.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/ISendPacket.ts rename to libraries/botframework-streaming/src/interfaces/ISendPacket.ts diff --git a/libraries/botframework-streaming/src/interfaces2/ISocket.ts b/libraries/botframework-streaming/src/interfaces/ISocket.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/ISocket.ts rename to libraries/botframework-streaming/src/interfaces/ISocket.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IStreamDescription.ts b/libraries/botframework-streaming/src/interfaces/IStreamDescription.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IStreamDescription.ts rename to libraries/botframework-streaming/src/interfaces/IStreamDescription.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IStreamWrapper.ts b/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IStreamWrapper.ts rename to libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IStreamingTransportClient.ts b/libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IStreamingTransportClient.ts rename to libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts diff --git a/libraries/botframework-streaming/src/interfaces2/IStreamingTransportServer.ts b/libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/IStreamingTransportServer.ts rename to libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts diff --git a/libraries/botframework-streaming/src/interfaces2/ITransport.ts b/libraries/botframework-streaming/src/interfaces/ITransport.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/ITransport.ts rename to libraries/botframework-streaming/src/interfaces/ITransport.ts diff --git a/libraries/botframework-streaming/src/interfaces2/ITransportReceiver.ts b/libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/ITransportReceiver.ts rename to libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts diff --git a/libraries/botframework-streaming/src/interfaces2/ITransportSender.ts b/libraries/botframework-streaming/src/interfaces/ITransportSender.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/ITransportSender.ts rename to libraries/botframework-streaming/src/interfaces/ITransportSender.ts diff --git a/libraries/botframework-streaming/src/interfaces2/index.ts b/libraries/botframework-streaming/src/interfaces/index.ts similarity index 100% rename from libraries/botframework-streaming/src/interfaces2/index.ts rename to libraries/botframework-streaming/src/interfaces/index.ts diff --git a/libraries/botframework-streaming/src/namedpipe2/NamedPipeClient.ts b/libraries/botframework-streaming/src/namedPipe/NamedPipeClient.ts similarity index 100% rename from libraries/botframework-streaming/src/namedpipe2/NamedPipeClient.ts rename to libraries/botframework-streaming/src/namedPipe/NamedPipeClient.ts diff --git a/libraries/botframework-streaming/src/namedpipe2/NamedPipeServer.ts b/libraries/botframework-streaming/src/namedPipe/NamedPipeServer.ts similarity index 100% rename from libraries/botframework-streaming/src/namedpipe2/NamedPipeServer.ts rename to libraries/botframework-streaming/src/namedPipe/NamedPipeServer.ts diff --git a/libraries/botframework-streaming/src/namedpipe2/NamedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/NamedPipeTransport.ts similarity index 100% rename from libraries/botframework-streaming/src/namedpipe2/NamedPipeTransport.ts rename to libraries/botframework-streaming/src/namedPipe/NamedPipeTransport.ts diff --git a/libraries/botframework-streaming/src/namedpipe2/index.ts b/libraries/botframework-streaming/src/namedPipe/index.ts similarity index 100% rename from libraries/botframework-streaming/src/namedpipe2/index.ts rename to libraries/botframework-streaming/src/namedPipe/index.ts diff --git a/libraries/botframework-streaming/src/payloadTransport2/PayloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/PayloadReceiver.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport2/PayloadReceiver.ts rename to libraries/botframework-streaming/src/payloadTransport/PayloadReceiver.ts diff --git a/libraries/botframework-streaming/src/payloadTransport2/PayloadSender.ts b/libraries/botframework-streaming/src/payloadTransport/PayloadSender.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport2/PayloadSender.ts rename to libraries/botframework-streaming/src/payloadTransport/PayloadSender.ts diff --git a/libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventArgs.ts b/libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventArgs.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventArgs.ts rename to libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventArgs.ts diff --git a/libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventHandler.ts b/libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventHandler.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport2/TransportDisconnectedEventHandler.ts rename to libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventHandler.ts diff --git a/libraries/botframework-streaming/src/payloadTransport2/index.ts b/libraries/botframework-streaming/src/payloadTransport/index.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport2/index.ts rename to libraries/botframework-streaming/src/payloadTransport/index.ts diff --git a/libraries/botframework-streaming/src/payloads2/HeaderSerializer.ts b/libraries/botframework-streaming/src/payloads3/HeaderSerializer.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/HeaderSerializer.ts rename to libraries/botframework-streaming/src/payloads3/HeaderSerializer.ts diff --git a/libraries/botframework-streaming/src/payloads2/PayloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads3/PayloadAssemblerManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/PayloadAssemblerManager.ts rename to libraries/botframework-streaming/src/payloads3/PayloadAssemblerManager.ts diff --git a/libraries/botframework-streaming/src/payloads2/PayloadConstants.ts b/libraries/botframework-streaming/src/payloads3/PayloadConstants.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/PayloadConstants.ts rename to libraries/botframework-streaming/src/payloads3/PayloadConstants.ts diff --git a/libraries/botframework-streaming/src/payloads2/PayloadTypes.ts b/libraries/botframework-streaming/src/payloads3/PayloadTypes.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/PayloadTypes.ts rename to libraries/botframework-streaming/src/payloads3/PayloadTypes.ts diff --git a/libraries/botframework-streaming/src/payloads2/RequestManager.ts b/libraries/botframework-streaming/src/payloads3/RequestManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/RequestManager.ts rename to libraries/botframework-streaming/src/payloads3/RequestManager.ts diff --git a/libraries/botframework-streaming/src/payloads2/SendOperations.ts b/libraries/botframework-streaming/src/payloads3/SendOperations.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/SendOperations.ts rename to libraries/botframework-streaming/src/payloads3/SendOperations.ts diff --git a/libraries/botframework-streaming/src/payloads2/StreamManager.ts b/libraries/botframework-streaming/src/payloads3/StreamManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/StreamManager.ts rename to libraries/botframework-streaming/src/payloads3/StreamManager.ts diff --git a/libraries/botframework-streaming/src/payloads2/index.ts b/libraries/botframework-streaming/src/payloads3/index.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads2/index.ts rename to libraries/botframework-streaming/src/payloads3/index.ts diff --git a/libraries/botframework-streaming/src/utilities2/index.ts b/libraries/botframework-streaming/src/utilities/index.ts similarity index 100% rename from libraries/botframework-streaming/src/utilities2/index.ts rename to libraries/botframework-streaming/src/utilities/index.ts diff --git a/libraries/botframework-streaming/src/utilities2/protocol-base.ts b/libraries/botframework-streaming/src/utilities/protocol-base.ts similarity index 100% rename from libraries/botframework-streaming/src/utilities2/protocol-base.ts rename to libraries/botframework-streaming/src/utilities/protocol-base.ts diff --git a/libraries/botframework-streaming/src/webSocket2/BrowserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/BrowserWebSocket.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/BrowserWebSocket.ts rename to libraries/botframework-streaming/src/webSocket/BrowserWebSocket.ts diff --git a/libraries/botframework-streaming/src/webSocket2/NodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/NodeWebSocket.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/NodeWebSocket.ts rename to libraries/botframework-streaming/src/webSocket/NodeWebSocket.ts diff --git a/libraries/botframework-streaming/src/webSocket2/WebSocketClient.ts b/libraries/botframework-streaming/src/webSocket/WebSocketClient.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/WebSocketClient.ts rename to libraries/botframework-streaming/src/webSocket/WebSocketClient.ts diff --git a/libraries/botframework-streaming/src/webSocket2/WebSocketServer.ts b/libraries/botframework-streaming/src/webSocket/WebSocketServer.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/WebSocketServer.ts rename to libraries/botframework-streaming/src/webSocket/WebSocketServer.ts diff --git a/libraries/botframework-streaming/src/webSocket2/WebSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/WebSocketTransport.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/WebSocketTransport.ts rename to libraries/botframework-streaming/src/webSocket/WebSocketTransport.ts diff --git a/libraries/botframework-streaming/src/webSocket2/index.ts b/libraries/botframework-streaming/src/webSocket/index.ts similarity index 100% rename from libraries/botframework-streaming/src/webSocket2/index.ts rename to libraries/botframework-streaming/src/webSocket/index.ts From a658a8ed13a47f73ee6a68ec2aa688479a06d09d Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 11:31:22 -0700 Subject: [PATCH 06/32] Streaming: directory renaming last part --- .../src/{payloads3 => payloads}/HeaderSerializer.ts | 0 .../src/{payloads3 => payloads}/PayloadAssemblerManager.ts | 0 .../src/{payloads3 => payloads}/PayloadConstants.ts | 0 .../src/{payloads3 => payloads}/PayloadTypes.ts | 0 .../src/{payloads3 => payloads}/RequestManager.ts | 0 .../src/{payloads3 => payloads}/SendOperations.ts | 0 .../src/{payloads3 => payloads}/StreamManager.ts | 0 .../botframework-streaming/src/{payloads3 => payloads}/index.ts | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename libraries/botframework-streaming/src/{payloads3 => payloads}/HeaderSerializer.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/PayloadAssemblerManager.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/PayloadConstants.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/PayloadTypes.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/RequestManager.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/SendOperations.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/StreamManager.ts (100%) rename libraries/botframework-streaming/src/{payloads3 => payloads}/index.ts (100%) diff --git a/libraries/botframework-streaming/src/payloads3/HeaderSerializer.ts b/libraries/botframework-streaming/src/payloads/HeaderSerializer.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/HeaderSerializer.ts rename to libraries/botframework-streaming/src/payloads/HeaderSerializer.ts diff --git a/libraries/botframework-streaming/src/payloads3/PayloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads/PayloadAssemblerManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/PayloadAssemblerManager.ts rename to libraries/botframework-streaming/src/payloads/PayloadAssemblerManager.ts diff --git a/libraries/botframework-streaming/src/payloads3/PayloadConstants.ts b/libraries/botframework-streaming/src/payloads/PayloadConstants.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/PayloadConstants.ts rename to libraries/botframework-streaming/src/payloads/PayloadConstants.ts diff --git a/libraries/botframework-streaming/src/payloads3/PayloadTypes.ts b/libraries/botframework-streaming/src/payloads/PayloadTypes.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/PayloadTypes.ts rename to libraries/botframework-streaming/src/payloads/PayloadTypes.ts diff --git a/libraries/botframework-streaming/src/payloads3/RequestManager.ts b/libraries/botframework-streaming/src/payloads/RequestManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/RequestManager.ts rename to libraries/botframework-streaming/src/payloads/RequestManager.ts diff --git a/libraries/botframework-streaming/src/payloads3/SendOperations.ts b/libraries/botframework-streaming/src/payloads/SendOperations.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/SendOperations.ts rename to libraries/botframework-streaming/src/payloads/SendOperations.ts diff --git a/libraries/botframework-streaming/src/payloads3/StreamManager.ts b/libraries/botframework-streaming/src/payloads/StreamManager.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/StreamManager.ts rename to libraries/botframework-streaming/src/payloads/StreamManager.ts diff --git a/libraries/botframework-streaming/src/payloads3/index.ts b/libraries/botframework-streaming/src/payloads/index.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads3/index.ts rename to libraries/botframework-streaming/src/payloads/index.ts From c66a0ceaca7ff19b5dcfcc0ec0c76f7536537ebd Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 12:26:03 -0700 Subject: [PATCH 07/32] Streaming: rename all files and references to proper casing --- .../src/assemblers/index.ts | 2 +- ...ayloadAssembler.ts => payloadAssembler.ts} | 16 ++++++------ .../{ContentStream.ts => contentStream.ts} | 2 +- ...lDisassembler.ts => cancelDisassembler.ts} | 6 ++--- ...er.ts => httpContentStreamDisassembler.ts} | 12 ++++----- .../src/disassemblers/index.ts | 10 +++---- ...Disassembler.ts => payloadDisassembler.ts} | 10 +++---- ...Disassembler.ts => requestDisassembler.ts} | 12 ++++----- ...isassembler.ts => responseDisassembler.ts} | 12 ++++----- ...pContentStream.ts => httpContentStream.ts} | 6 ++--- libraries/botframework-streaming/src/index.ts | 16 ++++++------ .../src/interfaces/IReceiveRequest.ts | 2 +- .../src/interfaces/IReceiveResponse.ts | 2 +- .../src/interfaces/ISendPacket.ts | 2 +- .../src/interfaces/IStreamWrapper.ts | 2 +- .../src/namedPipe/index.ts | 6 ++--- ...{NamedPipeClient.ts => namedPipeClient.ts} | 12 ++++----- ...{NamedPipeServer.ts => namedPipeServer.ts} | 12 ++++----- ...PipeTransport.ts => namedPipeTransport.ts} | 4 +-- .../src/payloadTransport/index.ts | 12 ++++----- ...{PayloadReceiver.ts => payloadReceiver.ts} | 12 ++++----- .../{PayloadSender.ts => payloadSender.ts} | 16 ++++++------ ...s.ts => transportDisconnectedEventArgs.ts} | 0 ...s => transportDisconnectedEventHandler.ts} | 2 +- ...eaderSerializer.ts => headerSerializer.ts} | 4 +-- .../src/payloads/index.ts | 14 +++++----- ...rManager.ts => payloadAssemblerManager.ts} | 10 +++---- ...ayloadConstants.ts => payloadConstants.ts} | 0 .../{PayloadTypes.ts => payloadTypes.ts} | 0 .../{RequestManager.ts => requestManager.ts} | 2 +- .../{SendOperations.ts => sendOperations.ts} | 16 ++++++------ .../{StreamManager.ts => streamManager.ts} | 6 ++--- ...{ProtocolAdapter.ts => protocolAdapter.ts} | 26 +++++++++---------- .../{RequestHandler.ts => requestHandler.ts} | 2 +- ...treamingRequest.ts => streamingRequest.ts} | 4 +-- ...eamingResponse.ts => streamingResponse.ts} | 4 +-- ...ribableStream.ts => subscribableStream.ts} | 0 ...rowserWebSocket.ts => browserWebSocket.ts} | 2 +- .../src/webSocket/index.ts | 12 ++++----- .../{NodeWebSocket.ts => nodeWebSocket.ts} | 2 +- ...{WebSocketClient.ts => webSocketClient.ts} | 12 ++++----- ...{WebSocketServer.ts => webSocketServer.ts} | 14 +++++----- ...cketTransport.ts => webSocketTransport.ts} | 6 ++--- .../tests/Assembler.test.js | 10 +++---- .../tests/ContentStream.test.js | 10 +++---- .../tests/Disassembler.test.js | 14 +++++----- .../tests/HeaderSerializer.test.js | 6 ++--- .../tests/NamedPipe.test.js | 2 +- .../tests/PayloadSender.test.js | 12 ++++----- .../tests/ProtocolAdapter.test.js | 22 ++++++++-------- .../tests/RequestManager.test.js | 2 +- .../tests/SendOperations.test.js | 12 ++++----- .../tests/StreamManager.test.js | 8 +++--- .../tests/StreamingRequest.test.js | 6 ++--- .../tests/StreamingResponse.test.js | 6 ++--- .../tests/SubscribableStream.test.js | 2 +- .../tests/TransportConstants.test.js | 2 +- .../tests/WebSocket.test.js | 2 +- 58 files changed, 220 insertions(+), 220 deletions(-) rename libraries/botframework-streaming/src/assemblers/{PayloadAssembler.ts => payloadAssembler.ts} (87%) rename libraries/botframework-streaming/src/{ContentStream.ts => contentStream.ts} (94%) rename libraries/botframework-streaming/src/disassemblers/{CancelDisassembler.ts => cancelDisassembler.ts} (77%) rename libraries/botframework-streaming/src/disassemblers/{HttpContentStreamDisassembler.ts => httpContentStreamDisassembler.ts} (64%) rename libraries/botframework-streaming/src/disassemblers/{PayloadDisassembler.ts => payloadDisassembler.ts} (79%) rename libraries/botframework-streaming/src/disassemblers/{RequestDisassembler.ts => requestDisassembler.ts} (68%) rename libraries/botframework-streaming/src/disassemblers/{ResponseDisassembler.ts => responseDisassembler.ts} (68%) rename libraries/botframework-streaming/src/{HttpContentStream.ts => httpContentStream.ts} (84%) rename libraries/botframework-streaming/src/namedPipe/{NamedPipeClient.ts => namedPipeClient.ts} (92%) rename libraries/botframework-streaming/src/namedPipe/{NamedPipeServer.ts => namedPipeServer.ts} (93%) rename libraries/botframework-streaming/src/namedPipe/{NamedPipeTransport.ts => namedPipeTransport.ts} (94%) rename libraries/botframework-streaming/src/payloadTransport/{PayloadReceiver.ts => payloadReceiver.ts} (90%) rename libraries/botframework-streaming/src/payloadTransport/{PayloadSender.ts => payloadSender.ts} (82%) rename libraries/botframework-streaming/src/payloadTransport/{TransportDisconnectedEventArgs.ts => transportDisconnectedEventArgs.ts} (100%) rename libraries/botframework-streaming/src/payloadTransport/{TransportDisconnectedEventHandler.ts => transportDisconnectedEventHandler.ts} (78%) rename libraries/botframework-streaming/src/payloads/{HeaderSerializer.ts => headerSerializer.ts} (94%) rename libraries/botframework-streaming/src/payloads/{PayloadAssemblerManager.ts => payloadAssemblerManager.ts} (87%) rename libraries/botframework-streaming/src/payloads/{PayloadConstants.ts => payloadConstants.ts} (100%) rename libraries/botframework-streaming/src/payloads/{PayloadTypes.ts => payloadTypes.ts} (100%) rename libraries/botframework-streaming/src/payloads/{RequestManager.ts => requestManager.ts} (92%) rename libraries/botframework-streaming/src/payloads/{SendOperations.ts => sendOperations.ts} (72%) rename libraries/botframework-streaming/src/payloads/{StreamManager.ts => streamManager.ts} (88%) rename libraries/botframework-streaming/src/{ProtocolAdapter.ts => protocolAdapter.ts} (82%) rename libraries/botframework-streaming/src/{RequestHandler.ts => requestHandler.ts} (92%) rename libraries/botframework-streaming/src/{StreamingRequest.ts => streamingRequest.ts} (92%) rename libraries/botframework-streaming/src/{StreamingResponse.ts => streamingResponse.ts} (91%) rename libraries/botframework-streaming/src/{SubscribableStream.ts => subscribableStream.ts} (100%) rename libraries/botframework-streaming/src/webSocket/{BrowserWebSocket.ts => browserWebSocket.ts} (95%) rename libraries/botframework-streaming/src/webSocket/{NodeWebSocket.ts => nodeWebSocket.ts} (95%) rename libraries/botframework-streaming/src/webSocket/{WebSocketClient.ts => webSocketClient.ts} (92%) rename libraries/botframework-streaming/src/webSocket/{WebSocketServer.ts => webSocketServer.ts} (89%) rename libraries/botframework-streaming/src/webSocket/{WebSocketTransport.ts => webSocketTransport.ts} (94%) diff --git a/libraries/botframework-streaming/src/assemblers/index.ts b/libraries/botframework-streaming/src/assemblers/index.ts index f892ea9f65..b7b330aa38 100644 --- a/libraries/botframework-streaming/src/assemblers/index.ts +++ b/libraries/botframework-streaming/src/assemblers/index.ts @@ -6,4 +6,4 @@ * Licensed under the MIT License. */ -export * from './PayloadAssembler'; +export * from './payloadAssembler'; diff --git a/libraries/botframework-streaming/src/assemblers/PayloadAssembler.ts b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts similarity index 87% rename from libraries/botframework-streaming/src/assemblers/PayloadAssembler.ts rename to libraries/botframework-streaming/src/assemblers/payloadAssembler.ts index db5873f1e8..5cb657ca49 100644 --- a/libraries/botframework-streaming/src/assemblers/PayloadAssembler.ts +++ b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts @@ -5,14 +5,14 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { SubscribableStream } from '../SubscribableStream'; -import { StreamManager, PayloadTypes } from '../Payloads'; -import { ContentStream } from '../ContentStream'; -import { IAssemblerParams } from '../Interfaces/IAssemblerParams'; -import { IHeader } from '../Interfaces/IHeader'; -import { IResponsePayload } from '../Interfaces/IResponsePayload'; -import { IReceiveResponse, IReceiveRequest } from '../Interfaces'; -import { IRequestPayload } from '../Interfaces/IRequestPayload'; +import { SubscribableStream } from '../subscribableStream'; +import { StreamManager, PayloadTypes } from '../payloads'; +import { ContentStream } from '../contentStream'; +import { IAssemblerParams } from '../interfaces/IAssemblerParams'; +import { IHeader } from '../interfaces/IHeader'; +import { IResponsePayload } from '../interfaces/IResponsePayload'; +import { IReceiveResponse, IReceiveRequest } from '../interfaces'; +import { IRequestPayload } from '../interfaces/IRequestPayload'; export class PayloadAssembler { diff --git a/libraries/botframework-streaming/src/ContentStream.ts b/libraries/botframework-streaming/src/contentStream.ts similarity index 94% rename from libraries/botframework-streaming/src/ContentStream.ts rename to libraries/botframework-streaming/src/contentStream.ts index 1ae62a8614..fa4fabc3fc 100644 --- a/libraries/botframework-streaming/src/ContentStream.ts +++ b/libraries/botframework-streaming/src/contentStream.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { SubscribableStream } from './SubscribableStream'; +import { SubscribableStream } from './subscribableStream'; import { PayloadAssembler } from './assemblers'; export class ContentStream { diff --git a/libraries/botframework-streaming/src/disassemblers/CancelDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts similarity index 77% rename from libraries/botframework-streaming/src/disassemblers/CancelDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts index 69473a2e96..6cb0853e32 100644 --- a/libraries/botframework-streaming/src/disassemblers/CancelDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts @@ -5,9 +5,9 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { IHeader } from '../Interfaces/IHeader'; -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { PayloadSender } from '../PayloadTransport/PayloadSender'; +import { IHeader } from '../interfaces/IHeader'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { PayloadSender } from '../payloadTransport/payloadSender'; export class CancelDisassembler { private readonly sender: PayloadSender; diff --git a/libraries/botframework-streaming/src/disassemblers/HttpContentStreamDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts similarity index 64% rename from libraries/botframework-streaming/src/disassemblers/HttpContentStreamDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts index 03c5cecddc..08c3989978 100644 --- a/libraries/botframework-streaming/src/disassemblers/HttpContentStreamDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts @@ -5,12 +5,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { HttpContentStream } from '../HttpContentStream'; -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { PayloadDisassembler } from './PayloadDisassembler'; -import { IStreamWrapper } from '../Interfaces/IStreamWrapper'; +import { HttpContentStream } from '../httpContentStream'; +import { PayloadSender } from '../payloadTransport/payloadSender'; +import { SubscribableStream } from '../subscribableStream'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { PayloadDisassembler } from './payloadDisassembler'; +import { IStreamWrapper } from '../interfaces/IStreamWrapper'; export class HttpContentStreamDisassembler extends PayloadDisassembler { public readonly contentStream: HttpContentStream; diff --git a/libraries/botframework-streaming/src/disassemblers/index.ts b/libraries/botframework-streaming/src/disassemblers/index.ts index da0b60e3f1..860a66d5bb 100644 --- a/libraries/botframework-streaming/src/disassemblers/index.ts +++ b/libraries/botframework-streaming/src/disassemblers/index.ts @@ -6,8 +6,8 @@ * Licensed under the MIT License. */ -export * from './CancelDisassembler'; -export * from './HttpContentStreamDisassembler'; -export * from './PayloadDisassembler'; -export * from './RequestDisassembler'; -export * from './ResponseDisassembler'; +export * from './cancelDisassembler'; +export * from './httpContentStreamDisassembler'; +export * from './payloadDisassembler'; +export * from './requestDisassembler'; +export * from './responseDisassembler'; diff --git a/libraries/botframework-streaming/src/disassemblers/PayloadDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts similarity index 79% rename from libraries/botframework-streaming/src/disassemblers/PayloadDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts index c4302cf006..9c840008ae 100644 --- a/libraries/botframework-streaming/src/disassemblers/PayloadDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts @@ -5,11 +5,11 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { IHeader } from '../Interfaces/IHeader'; -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { SubscribableStream } from '../SubscribableStream'; -import { IStreamWrapper } from '../Interfaces/IStreamWrapper'; +import { IHeader } from '../interfaces/IHeader'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { PayloadSender } from '../payloadTransport/payloadSender'; +import { SubscribableStream } from '../subscribableStream'; +import { IStreamWrapper } from '../interfaces/IStreamWrapper'; export abstract class PayloadDisassembler { public abstract payloadType: PayloadTypes; diff --git a/libraries/botframework-streaming/src/disassemblers/RequestDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts similarity index 68% rename from libraries/botframework-streaming/src/disassemblers/RequestDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts index 5c358a7a20..270f24218b 100644 --- a/libraries/botframework-streaming/src/disassemblers/RequestDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts @@ -5,12 +5,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { StreamingRequest } from '../StreamingRequest'; -import { PayloadDisassembler } from './PayloadDisassembler'; -import { IStreamWrapper } from '../Interfaces/IStreamWrapper'; -import { IRequestPayload } from '../Interfaces/IRequestPayload'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { PayloadSender } from '../payloadTransport/payloadSender'; +import { StreamingRequest } from '../streamingRequest'; +import { PayloadDisassembler } from './payloadDisassembler'; +import { IStreamWrapper } from '../interfaces/IStreamWrapper'; +import { IRequestPayload } from '../interfaces/IRequestPayload'; export class RequestDisassembler extends PayloadDisassembler { public request: StreamingRequest; diff --git a/libraries/botframework-streaming/src/disassemblers/ResponseDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts similarity index 68% rename from libraries/botframework-streaming/src/disassemblers/ResponseDisassembler.ts rename to libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts index ac7f846bc3..b22771679d 100644 --- a/libraries/botframework-streaming/src/disassemblers/ResponseDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts @@ -5,12 +5,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { StreamingResponse } from '../StreamingResponse'; -import { PayloadDisassembler } from './PayloadDisassembler'; -import { IStreamWrapper } from '../Interfaces/IStreamWrapper'; -import { IResponsePayload } from '../Interfaces/IResponsePayload'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { PayloadSender } from '../payloadTransport/payloadSender'; +import { StreamingResponse } from '../streamingResponse'; +import { PayloadDisassembler } from './payloadDisassembler'; +import { IStreamWrapper } from '../interfaces/IStreamWrapper'; +import { IResponsePayload } from '../interfaces/IResponsePayload'; export class ResponseDisassembler extends PayloadDisassembler { public readonly response: StreamingResponse; diff --git a/libraries/botframework-streaming/src/HttpContentStream.ts b/libraries/botframework-streaming/src/httpContentStream.ts similarity index 84% rename from libraries/botframework-streaming/src/HttpContentStream.ts rename to libraries/botframework-streaming/src/httpContentStream.ts index 6ec27ce61e..59befea44f 100644 --- a/libraries/botframework-streaming/src/HttpContentStream.ts +++ b/libraries/botframework-streaming/src/httpContentStream.ts @@ -5,9 +5,9 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { SubscribableStream } from './SubscribableStream'; -import { generateGuid } from './Utilities/protocol-base'; -import { IHttpContentHeaders } from './Interfaces/IHttpContentHeaders'; +import { SubscribableStream } from './subscribableStream'; +import { generateGuid } from './utilities/protocol-base'; +import { IHttpContentHeaders } from './interfaces/IHttpContentHeaders'; export class HttpContentStream { public readonly id: string; diff --git a/libraries/botframework-streaming/src/index.ts b/libraries/botframework-streaming/src/index.ts index a48409935d..9c4404de88 100644 --- a/libraries/botframework-streaming/src/index.ts +++ b/libraries/botframework-streaming/src/index.ts @@ -5,12 +5,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -export { ContentStream } from './ContentStream'; -export { HttpContent } from './HttpContentStream'; +export { ContentStream } from './contentStream'; +export { HttpContent } from './httpContentStream'; export { IStreamingTransportServer, IStreamingTransportClient, ISocket, IReceiveRequest, IReceiveResponse } from './Interfaces' -export { NamedPipeClient, NamedPipeServer } from './NamedPipe'; -export { RequestHandler } from './RequestHandler'; -export { StreamingRequest } from './StreamingRequest'; -export { StreamingResponse } from './StreamingResponse'; -export { SubscribableStream } from './SubscribableStream'; -export { BrowserWebSocket, NodeWebSocket, WebSocketClient, WebSocketServer } from './WebSocket'; +export { NamedPipeClient, NamedPipeServer } from './namedPipe'; +export { RequestHandler } from './requestHandler'; +export { StreamingRequest } from './streamingRequest'; +export { StreamingResponse } from './streamingResponse'; +export { SubscribableStream } from './subscribableStream'; +export { BrowserWebSocket, NodeWebSocket, WebSocketClient, WebSocketServer } from './webSocket'; diff --git a/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts b/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts index 5bcec8463e..cfb2a190cd 100644 --- a/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts +++ b/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ContentStream } from '../ContentStream'; +import { ContentStream } from '../contentStream'; export interface IReceiveRequest { /// Request verb, null on responses diff --git a/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts b/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts index c051b217db..512bc58278 100644 --- a/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts +++ b/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ContentStream } from '../ContentStream'; +import { ContentStream } from '../contentStream'; export interface IReceiveResponse { statusCode?: number; diff --git a/libraries/botframework-streaming/src/interfaces/ISendPacket.ts b/libraries/botframework-streaming/src/interfaces/ISendPacket.ts index 73632be3b3..2510a9c92a 100644 --- a/libraries/botframework-streaming/src/interfaces/ISendPacket.ts +++ b/libraries/botframework-streaming/src/interfaces/ISendPacket.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ import { IHeader } from './IHeader'; -import { SubscribableStream } from '../SubscribableStream'; +import { SubscribableStream } from '../subscribableStream'; export interface ISendPacket { header: IHeader; diff --git a/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts b/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts index 5ff893cc75..2ea718f721 100644 --- a/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts +++ b/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { SubscribableStream } from '../SubscribableStream'; +import { SubscribableStream } from '../subscribableStream'; export interface IStreamWrapper { stream: SubscribableStream; diff --git a/libraries/botframework-streaming/src/namedPipe/index.ts b/libraries/botframework-streaming/src/namedPipe/index.ts index 61967f4c27..86f96dfd54 100644 --- a/libraries/botframework-streaming/src/namedPipe/index.ts +++ b/libraries/botframework-streaming/src/namedPipe/index.ts @@ -6,6 +6,6 @@ * Licensed under the MIT License. */ -export * from './NamedPipeClient'; -export * from './NamedPipeServer'; -export * from './NamedPipeTransport'; +export * from './namedPipeClient'; +export * from './namedPipeServer'; +export * from './namedPipeTransport'; diff --git a/libraries/botframework-streaming/src/namedPipe/NamedPipeClient.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts similarity index 92% rename from libraries/botframework-streaming/src/namedPipe/NamedPipeClient.ts rename to libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts index 177bde674e..e4310e47d0 100644 --- a/libraries/botframework-streaming/src/namedPipe/NamedPipeClient.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts @@ -6,16 +6,16 @@ * Licensed under the MIT License. */ import { connect } from 'net'; -import { ProtocolAdapter } from '../ProtocolAdapter'; -import { RequestHandler } from '../RequestHandler'; -import { StreamingRequest } from '../StreamingRequest'; -import { RequestManager } from '../Payloads'; +import { ProtocolAdapter } from '../protocolAdapter'; +import { RequestHandler } from '../requestHandler'; +import { StreamingRequest } from '../streamingRequest'; +import { RequestManager } from '../payloads'; import { PayloadReceiver, PayloadSender -} from '../PayloadTransport'; +} from '../payloadTransport'; import { NamedPipeTransport } from './NamedPipeTransport'; -import { IStreamingTransportClient, IReceiveResponse } from '../Interfaces'; +import { IStreamingTransportClient, IReceiveResponse } from '../interfaces'; export class NamedPipeClient implements IStreamingTransportClient { private readonly _baseName: string; diff --git a/libraries/botframework-streaming/src/namedPipe/NamedPipeServer.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts similarity index 93% rename from libraries/botframework-streaming/src/namedPipe/NamedPipeServer.ts rename to libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts index 559fbda3ee..53ae5a1308 100644 --- a/libraries/botframework-streaming/src/namedPipe/NamedPipeServer.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts @@ -6,16 +6,16 @@ * Licensed under the MIT License. */ import { Server, Socket } from 'net'; -import { ProtocolAdapter } from '../ProtocolAdapter'; -import { RequestHandler } from '../RequestHandler'; -import { StreamingRequest } from '../StreamingRequest'; -import { RequestManager } from '../Payloads'; +import { ProtocolAdapter } from '../protocolAdapter'; +import { RequestHandler } from '../requestHandler'; +import { StreamingRequest } from '../streamingRequest'; +import { RequestManager } from '../payloads'; import { PayloadReceiver, PayloadSender -} from '../PayloadTransport'; +} from '../payloadTransport'; import { NamedPipeTransport } from './NamedPipeTransport'; -import { IStreamingTransportServer, IReceiveResponse } from '../Interfaces'; +import { IStreamingTransportServer, IReceiveResponse } from '../interfaces'; /// /// A server for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying Named Pipe transport. diff --git a/libraries/botframework-streaming/src/namedPipe/NamedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts similarity index 94% rename from libraries/botframework-streaming/src/namedPipe/NamedPipeTransport.ts rename to libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts index 59077ee291..75ec02b6c6 100644 --- a/libraries/botframework-streaming/src/namedPipe/NamedPipeTransport.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts @@ -6,8 +6,8 @@ * Licensed under the MIT License. */ import { Socket } from 'net'; -import { ITransportSender } from '../Interfaces/ITransportSender'; -import { ITransportReceiver } from '../Interfaces/ITransportReceiver'; +import { ITransportSender } from '../interfaces/ITransportSender'; +import { ITransportReceiver } from '../interfaces/ITransportReceiver'; export class NamedPipeTransport implements ITransportSender, ITransportReceiver { public static readonly PipePath: string = '\\\\.\\pipe\\'; diff --git a/libraries/botframework-streaming/src/payloadTransport/index.ts b/libraries/botframework-streaming/src/payloadTransport/index.ts index 3dc4b2ead9..461b0d0e0c 100644 --- a/libraries/botframework-streaming/src/payloadTransport/index.ts +++ b/libraries/botframework-streaming/src/payloadTransport/index.ts @@ -6,9 +6,9 @@ * Licensed under the MIT License. */ -export * from './PayloadReceiver'; -export * from './PayloadSender'; -export * from './PayloadReceiver'; -export * from './PayloadSender'; -export * from './TransportDisconnectedEventArgs'; -export * from './TransportDisconnectedEventHandler'; +export * from './payloadReceiver'; +export * from './payloadSender'; +export * from './payloadReceiver'; +export * from './payloadSender'; +export * from './transportDisconnectedEventArgs'; +export * from './transportDisconnectedEventHandler'; diff --git a/libraries/botframework-streaming/src/payloadTransport/PayloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts similarity index 90% rename from libraries/botframework-streaming/src/payloadTransport/PayloadReceiver.ts rename to libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts index ec97e48a3a..d6542601ba 100644 --- a/libraries/botframework-streaming/src/payloadTransport/PayloadReceiver.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts @@ -6,13 +6,13 @@ * Licensed under the MIT License. */ import { TransportDisconnectedEventHandler } from '.'; -import { PayloadTypes } from '../Payloads/PayloadTypes'; -import { HeaderSerializer } from '../Payloads/HeaderSerializer'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadConstants } from '../Payloads/PayloadConstants'; +import { PayloadTypes } from '../payloads/payloadTypes'; +import { HeaderSerializer } from '../payloads/headerSerializer'; +import { SubscribableStream } from '../subscribableStream'; +import { PayloadConstants } from '../payloads/payloadConstants'; import { TransportDisconnectedEventArgs } from './TransportDisconnectedEventArgs'; -import { ITransportReceiver } from '../Interfaces/ITransportReceiver'; -import { IHeader } from '../Interfaces/IHeader'; +import { ITransportReceiver } from '../interfaces/ITransportReceiver'; +import { IHeader } from '../interfaces/IHeader'; export class PayloadReceiver { public isConnected: boolean; diff --git a/libraries/botframework-streaming/src/payloadTransport/PayloadSender.ts b/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts similarity index 82% rename from libraries/botframework-streaming/src/payloadTransport/PayloadSender.ts rename to libraries/botframework-streaming/src/payloadTransport/payloadSender.ts index 2c7f12a2ee..061eb830d3 100644 --- a/libraries/botframework-streaming/src/payloadTransport/PayloadSender.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts @@ -6,14 +6,14 @@ * Licensed under the MIT License. */ -import { HeaderSerializer } from '../Payloads/HeaderSerializer'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadConstants } from '../Payloads/PayloadConstants'; -import { TransportDisconnectedEventArgs } from './TransportDisconnectedEventArgs'; -import { TransportDisconnectedEventHandler } from './TransportDisconnectedEventHandler'; -import { ITransportSender } from '../Interfaces/ITransportSender'; -import { IHeader } from '../Interfaces/IHeader'; -import { ISendPacket } from '../Interfaces/ISendPacket'; +import { HeaderSerializer } from '../payloads/headerSerializer'; +import { SubscribableStream } from '../subscribableStream'; +import { PayloadConstants } from '../payloads/payloadConstants'; +import { TransportDisconnectedEventArgs } from './transportDisconnectedEventArgs'; +import { TransportDisconnectedEventHandler } from './transportDisconnectedEventHandler'; +import { ITransportSender } from '../interfaces/ITransportSender'; +import { IHeader } from '../interfaces/IHeader'; +import { ISendPacket } from '../interfaces/ISendPacket'; export class PayloadSender { public disconnected?: TransportDisconnectedEventHandler; diff --git a/libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventArgs.ts b/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventArgs.ts similarity index 100% rename from libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventArgs.ts rename to libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventArgs.ts diff --git a/libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventHandler.ts b/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts similarity index 78% rename from libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventHandler.ts rename to libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts index 7b43ba9d99..9d7ad02121 100644 --- a/libraries/botframework-streaming/src/payloadTransport/TransportDisconnectedEventHandler.ts +++ b/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts @@ -5,6 +5,6 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { TransportDisconnectedEventArgs } from './TransportDisconnectedEventArgs'; +import { TransportDisconnectedEventArgs } from './transportDisconnectedEventArgs'; export type TransportDisconnectedEventHandler = (sender: any, e: TransportDisconnectedEventArgs) => void; diff --git a/libraries/botframework-streaming/src/payloads/HeaderSerializer.ts b/libraries/botframework-streaming/src/payloads/headerSerializer.ts similarity index 94% rename from libraries/botframework-streaming/src/payloads/HeaderSerializer.ts rename to libraries/botframework-streaming/src/payloads/headerSerializer.ts index 7b172ee97c..8bc851a4ff 100644 --- a/libraries/botframework-streaming/src/payloads/HeaderSerializer.ts +++ b/libraries/botframework-streaming/src/payloads/headerSerializer.ts @@ -5,8 +5,8 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { IHeader } from '../Interfaces/IHeader'; -import { PayloadConstants } from './PayloadConstants'; +import { IHeader } from '../interfaces/IHeader'; +import { PayloadConstants } from './payloadConstants'; export class HeaderSerializer { public static readonly Delimiter = '.'; diff --git a/libraries/botframework-streaming/src/payloads/index.ts b/libraries/botframework-streaming/src/payloads/index.ts index 2b026bc0d6..3f13e4f3e7 100644 --- a/libraries/botframework-streaming/src/payloads/index.ts +++ b/libraries/botframework-streaming/src/payloads/index.ts @@ -6,10 +6,10 @@ * Licensed under the MIT License. */ -export * from './HeaderSerializer'; -export * from './StreamManager'; -export * from './PayloadAssemblerManager'; -export * from './PayloadTypes'; -export * from './RequestManager'; -export * from './SendOperations'; -export * from './StreamManager'; +export * from './headerSerializer'; +export * from './streamManager'; +export * from './payloadAssemblerManager'; +export * from './payloadTypes'; +export * from './requestManager'; +export * from './sendOperations'; +export * from './streamManager'; diff --git a/libraries/botframework-streaming/src/payloads/PayloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts similarity index 87% rename from libraries/botframework-streaming/src/payloads/PayloadAssemblerManager.ts rename to libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts index 7146896793..a53f651dd7 100644 --- a/libraries/botframework-streaming/src/payloads/PayloadAssemblerManager.ts +++ b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts @@ -5,11 +5,11 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadAssembler } from '../Assemblers/PayloadAssembler'; -import { StreamManager } from './StreamManager'; -import { IHeader } from '../Interfaces/IHeader'; -import { PayloadTypes } from './PayloadTypes'; +import { SubscribableStream } from '../subscribableStream'; +import { PayloadAssembler } from '../assemblers/payloadAssembler'; +import { StreamManager } from './streamManager'; +import { IHeader } from '../interfaces/IHeader'; +import { PayloadTypes } from './payloadTypes'; export class PayloadAssemblerManager { private readonly onReceiveRequest; diff --git a/libraries/botframework-streaming/src/payloads/PayloadConstants.ts b/libraries/botframework-streaming/src/payloads/payloadConstants.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads/PayloadConstants.ts rename to libraries/botframework-streaming/src/payloads/payloadConstants.ts diff --git a/libraries/botframework-streaming/src/payloads/PayloadTypes.ts b/libraries/botframework-streaming/src/payloads/payloadTypes.ts similarity index 100% rename from libraries/botframework-streaming/src/payloads/PayloadTypes.ts rename to libraries/botframework-streaming/src/payloads/payloadTypes.ts diff --git a/libraries/botframework-streaming/src/payloads/RequestManager.ts b/libraries/botframework-streaming/src/payloads/requestManager.ts similarity index 92% rename from libraries/botframework-streaming/src/payloads/RequestManager.ts rename to libraries/botframework-streaming/src/payloads/requestManager.ts index 76d5f5a021..1fcd6093ca 100644 --- a/libraries/botframework-streaming/src/payloads/RequestManager.ts +++ b/libraries/botframework-streaming/src/payloads/requestManager.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { IReceiveResponse } from '../Interfaces/IReceiveResponse'; +import { IReceiveResponse } from '../interfaces/IReceiveResponse'; class PendingRequest { public requestId: string; diff --git a/libraries/botframework-streaming/src/payloads/SendOperations.ts b/libraries/botframework-streaming/src/payloads/sendOperations.ts similarity index 72% rename from libraries/botframework-streaming/src/payloads/SendOperations.ts rename to libraries/botframework-streaming/src/payloads/sendOperations.ts index a558986304..2225c81108 100644 --- a/libraries/botframework-streaming/src/payloads/SendOperations.ts +++ b/libraries/botframework-streaming/src/payloads/sendOperations.ts @@ -5,14 +5,14 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { PayloadSender } from '../PayloadTransport/PayloadSender'; -import { StreamingRequest } from '../StreamingRequest'; -import { StreamingResponse } from '../StreamingResponse'; -import { CancelDisassembler } from '../Disassemblers/CancelDisassembler'; -import { HttpContentStreamDisassembler } from '../Disassemblers/HttpContentStreamDisassembler'; -import { RequestDisassembler } from '../Disassemblers/RequestDisassembler'; -import { ResponseDisassembler } from '../Disassemblers/ResponseDisassembler'; -import { PayloadTypes } from './PayloadTypes'; +import { PayloadSender } from '../payloadTransport/payloadSender'; +import { StreamingRequest } from '../streamingRequest'; +import { StreamingResponse } from '../streamingResponse'; +import { CancelDisassembler } from '../disassemblers/cancelDisassembler'; +import { HttpContentStreamDisassembler } from '../disassemblers/httpContentStreamDisassembler'; +import { RequestDisassembler } from '../disassemblers/requestDisassembler'; +import { ResponseDisassembler } from '../disassemblers/responseDisassembler'; +import { PayloadTypes } from './payloadTypes'; export class SendOperations { private readonly payloadSender: PayloadSender; diff --git a/libraries/botframework-streaming/src/payloads/StreamManager.ts b/libraries/botframework-streaming/src/payloads/streamManager.ts similarity index 88% rename from libraries/botframework-streaming/src/payloads/StreamManager.ts rename to libraries/botframework-streaming/src/payloads/streamManager.ts index dfa578aa89..7fb3612874 100644 --- a/libraries/botframework-streaming/src/payloads/StreamManager.ts +++ b/libraries/botframework-streaming/src/payloads/streamManager.ts @@ -5,9 +5,9 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { IHeader } from '../Interfaces/IHeader'; -import { SubscribableStream } from '../SubscribableStream'; -import { PayloadAssembler } from '../Assemblers/PayloadAssembler'; +import { IHeader } from '../interfaces/IHeader'; +import { SubscribableStream } from '../subscribableStream'; +import { PayloadAssembler } from '../assemblers/payloadAssembler'; export class StreamManager { private readonly activeAssemblers = []; diff --git a/libraries/botframework-streaming/src/ProtocolAdapter.ts b/libraries/botframework-streaming/src/protocolAdapter.ts similarity index 82% rename from libraries/botframework-streaming/src/ProtocolAdapter.ts rename to libraries/botframework-streaming/src/protocolAdapter.ts index 0cb04ee11a..2b98de551d 100644 --- a/libraries/botframework-streaming/src/ProtocolAdapter.ts +++ b/libraries/botframework-streaming/src/protocolAdapter.ts @@ -5,19 +5,19 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { PayloadAssembler } from './assemblers/PayloadAssembler'; -import { PayloadAssemblerManager } from './Payloads/PayloadAssemblerManager'; -import { RequestManager } from './Payloads/RequestManager'; -import { SendOperations } from './Payloads/SendOperations'; -import { StreamManager } from './Payloads/StreamManager'; -import { PayloadReceiver } from './PayloadTransport/PayloadReceiver'; -import { PayloadSender } from './PayloadTransport/PayloadSender'; -import { RequestHandler } from './RequestHandler'; -import { SubscribableStream } from './SubscribableStream'; -import { StreamingRequest } from './StreamingRequest'; -import { generateGuid } from './Utilities/protocol-base'; -import { IReceiveResponse, IReceiveRequest } from './Interfaces'; -import { IHeader } from './Interfaces/IHeader'; +import { PayloadAssembler } from './assemblers/payloadAssembler'; +import { PayloadAssemblerManager } from './payloads/payloadAssemblerManager'; +import { RequestManager } from './payloads/requestManager'; +import { SendOperations } from './payloads/sendOperations'; +import { StreamManager } from './payloads/streamManager'; +import { PayloadReceiver } from './payloadTransport/payloadReceiver'; +import { PayloadSender } from './payloadTransport/payloadSender'; +import { RequestHandler } from './requestHandler'; +import { SubscribableStream } from './subscribableStream'; +import { StreamingRequest } from './streamingRequest'; +import { generateGuid } from './utilities/protocol-base'; +import { IReceiveResponse, IReceiveRequest } from './interfaces'; +import { IHeader } from './interfaces/IHeader'; export class ProtocolAdapter { private readonly requestHandler: RequestHandler; diff --git a/libraries/botframework-streaming/src/RequestHandler.ts b/libraries/botframework-streaming/src/requestHandler.ts similarity index 92% rename from libraries/botframework-streaming/src/RequestHandler.ts rename to libraries/botframework-streaming/src/requestHandler.ts index 3c0c367fd8..ee9438a247 100644 --- a/libraries/botframework-streaming/src/RequestHandler.ts +++ b/libraries/botframework-streaming/src/requestHandler.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ import { IReceiveRequest } from './Interfaces/IReceiveRequest'; -import { StreamingResponse } from './StreamingResponse'; +import { StreamingResponse } from './streamingResponse'; /// /// Implemented by classes used to process incoming requests sent over an and adhering to the Bot Framework Protocol v3 with Streaming Extensions. /// diff --git a/libraries/botframework-streaming/src/StreamingRequest.ts b/libraries/botframework-streaming/src/streamingRequest.ts similarity index 92% rename from libraries/botframework-streaming/src/StreamingRequest.ts rename to libraries/botframework-streaming/src/streamingRequest.ts index 817327be3b..73f37ce37d 100644 --- a/libraries/botframework-streaming/src/StreamingRequest.ts +++ b/libraries/botframework-streaming/src/streamingRequest.ts @@ -5,8 +5,8 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { HttpContent, HttpContentStream } from './HttpContentStream'; -import { SubscribableStream } from './SubscribableStream'; +import { HttpContent, HttpContentStream } from './httpContentStream'; +import { SubscribableStream } from './subscribableStream'; export class StreamingRequest { /// diff --git a/libraries/botframework-streaming/src/StreamingResponse.ts b/libraries/botframework-streaming/src/streamingResponse.ts similarity index 91% rename from libraries/botframework-streaming/src/StreamingResponse.ts rename to libraries/botframework-streaming/src/streamingResponse.ts index 7195a49310..cc97d801a6 100644 --- a/libraries/botframework-streaming/src/StreamingResponse.ts +++ b/libraries/botframework-streaming/src/streamingResponse.ts @@ -5,8 +5,8 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { HttpContent, HttpContentStream } from './HttpContentStream'; -import { SubscribableStream } from './SubscribableStream'; +import { HttpContent, HttpContentStream } from './httpContentStream'; +import { SubscribableStream } from './subscribableStream'; export class StreamingResponse { public statusCode: number; diff --git a/libraries/botframework-streaming/src/SubscribableStream.ts b/libraries/botframework-streaming/src/subscribableStream.ts similarity index 100% rename from libraries/botframework-streaming/src/SubscribableStream.ts rename to libraries/botframework-streaming/src/subscribableStream.ts diff --git a/libraries/botframework-streaming/src/webSocket/BrowserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts similarity index 95% rename from libraries/botframework-streaming/src/webSocket/BrowserWebSocket.ts rename to libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index 35253afe3b..85c2e69de6 100644 --- a/libraries/botframework-streaming/src/webSocket/BrowserWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ISocket } from '../Interfaces/ISocket'; +import { ISocket } from '../interfaces/ISocket'; export class BrowserWebSocket implements ISocket { private webSocket: WebSocket; diff --git a/libraries/botframework-streaming/src/webSocket/index.ts b/libraries/botframework-streaming/src/webSocket/index.ts index b339d59cd1..b6a02e2b55 100644 --- a/libraries/botframework-streaming/src/webSocket/index.ts +++ b/libraries/botframework-streaming/src/webSocket/index.ts @@ -6,9 +6,9 @@ * Licensed under the MIT License. */ -export * from './BrowserWebSocket'; -export * from '../Interfaces/ISocket'; -export * from './NodeWebSocket'; -export * from './WebSocketClient'; -export * from './WebSocketServer'; -export * from './WebSocketTransport'; +export * from './browserWebSocket'; +export * from '../interfaces/ISocket'; +export * from './nodeWebSocket'; +export * from './webSocketClient'; +export * from './webSocketServer'; +export * from './webSocketTransport'; diff --git a/libraries/botframework-streaming/src/webSocket/NodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts similarity index 95% rename from libraries/botframework-streaming/src/webSocket/NodeWebSocket.ts rename to libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts index 45f27e4f64..37b028f9f6 100644 --- a/libraries/botframework-streaming/src/webSocket/NodeWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts @@ -7,7 +7,7 @@ */ import * as http from 'http'; import * as WaterShed from 'watershed'; -import { ISocket } from '../Interfaces/ISocket'; +import { ISocket } from '../interfaces/ISocket'; export class NodeWebSocket implements ISocket { private readonly waterShedSocket: any; diff --git a/libraries/botframework-streaming/src/webSocket/WebSocketClient.ts b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts similarity index 92% rename from libraries/botframework-streaming/src/webSocket/WebSocketClient.ts rename to libraries/botframework-streaming/src/webSocket/webSocketClient.ts index be6cf2e043..277d6872da 100644 --- a/libraries/botframework-streaming/src/webSocket/WebSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts @@ -5,19 +5,19 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ProtocolAdapter } from '../ProtocolAdapter'; -import { RequestHandler } from '../RequestHandler'; -import { StreamingRequest } from '../StreamingRequest'; -import { RequestManager } from '../Payloads'; +import { ProtocolAdapter } from '../protocolAdapter'; +import { RequestHandler } from '../requestHandler'; +import { StreamingRequest } from '../streamingRequest'; +import { RequestManager } from '../payloads'; import { PayloadReceiver, PayloadSender, TransportDisconnectedEventArgs -} from '../PayloadTransport'; +} from '../payloadTransport'; import { BrowserWebSocket } from './BrowserWebSocket'; import { NodeWebSocket } from './NodeWebSocket'; import { WebSocketTransport } from './WebSocketTransport'; -import { IStreamingTransportClient, IReceiveResponse } from '../Interfaces'; +import { IStreamingTransportClient, IReceiveResponse } from '../interfaces'; /// /// A client for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying WebSocket transport. diff --git a/libraries/botframework-streaming/src/webSocket/WebSocketServer.ts b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts similarity index 89% rename from libraries/botframework-streaming/src/webSocket/WebSocketServer.ts rename to libraries/botframework-streaming/src/webSocket/webSocketServer.ts index dc4c9bf70c..e468be11ad 100644 --- a/libraries/botframework-streaming/src/webSocket/WebSocketServer.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts @@ -5,18 +5,18 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ProtocolAdapter } from '../ProtocolAdapter'; -import { RequestHandler } from '../RequestHandler'; -import { StreamingRequest } from '../StreamingRequest'; -import { RequestManager } from '../Payloads'; +import { ProtocolAdapter } from '../protocolAdapter'; +import { RequestHandler } from '../requestHandler'; +import { StreamingRequest } from '../streamingRequest'; +import { RequestManager } from '../payloads'; import { PayloadReceiver, PayloadSender, TransportDisconnectedEventArgs -} from '../PayloadTransport'; -import { ISocket } from '../Interfaces/ISocket'; +} from '../payloadTransport'; +import { ISocket } from '../interfaces/ISocket'; import { WebSocketTransport } from './WebSocketTransport'; -import { IStreamingTransportServer, IReceiveResponse } from '../Interfaces'; +import { IStreamingTransportServer, IReceiveResponse } from '../interfaces'; /// /// A server for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying WebSocket transport. diff --git a/libraries/botframework-streaming/src/webSocket/WebSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts similarity index 94% rename from libraries/botframework-streaming/src/webSocket/WebSocketTransport.ts rename to libraries/botframework-streaming/src/webSocket/webSocketTransport.ts index fdf5fc705d..ab6ff864fd 100644 --- a/libraries/botframework-streaming/src/webSocket/WebSocketTransport.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts @@ -5,9 +5,9 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { ISocket } from '../Interfaces'; -import { ITransportSender } from '../Interfaces/ITransportSender'; -import { ITransportReceiver } from '../Interfaces/ITransportReceiver'; +import { ISocket } from '../interfaces'; +import { ITransportSender } from '../interfaces/ITransportSender'; +import { ITransportReceiver } from '../interfaces/ITransportReceiver'; export class WebSocketTransport implements ITransportSender, ITransportReceiver { private _socket: ISocket; diff --git a/libraries/botframework-streaming/tests/Assembler.test.js b/libraries/botframework-streaming/tests/Assembler.test.js index 125e5b1b38..4f778cfcb2 100644 --- a/libraries/botframework-streaming/tests/Assembler.test.js +++ b/libraries/botframework-streaming/tests/Assembler.test.js @@ -1,9 +1,9 @@ -const SubscribableStream = require('../lib/SubscribableStream'); +const SubscribableStream = require('../lib/subscribableStream'); const chai = require('chai'); -const StreamManager = require('../lib/Payloads/StreamManager'); -const PayloadTypes = require('../lib/Payloads/PayloadTypes'); -const PayloadAssembler = require('../lib/Assemblers/PayloadAssembler'); -const PayloadAssemblerManager = require('../lib/Payloads/PayloadAssemblerManager'); +const StreamManager = require('../lib/payloads/streamManager'); +const PayloadTypes = require('../lib/payloads/payloadTypes'); +const PayloadAssembler = require('../lib/assemblers/payloadAssembler'); +const PayloadAssemblerManager = require('../lib/payloads/payloadAssemblerManager'); var expect = chai.expect; describe('ReceiveRequestAssembler', () => { diff --git a/libraries/botframework-streaming/tests/ContentStream.test.js b/libraries/botframework-streaming/tests/ContentStream.test.js index 01af89cfd8..e826980e24 100644 --- a/libraries/botframework-streaming/tests/ContentStream.test.js +++ b/libraries/botframework-streaming/tests/ContentStream.test.js @@ -1,9 +1,9 @@ -const ContentStream = require('../lib/ContentStream'); -const PayloadAssembler = require('../lib/Assemblers/PayloadAssembler'); +const ContentStream = require('../lib/contentStream'); +const PayloadAssembler = require('../lib/assemblers/payloadAssembler'); const chai = require('chai'); -const StreamManager = require('../lib/Payloads/StreamManager'); -const SubscribableStream = require('../lib/SubscribableStream'); -const PayloadTypes = require('../lib/Payloads/PayloadTypes'); +const StreamManager = require('../lib/payloads/streamManager'); +const SubscribableStream = require('../lib/subscribableStream'); +const PayloadTypes = require('../lib/payloads/payloadTypes'); const protocol = require('../lib'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/Disassembler.test.js b/libraries/botframework-streaming/tests/Disassembler.test.js index a5f27b8b14..6e47578aff 100644 --- a/libraries/botframework-streaming/tests/Disassembler.test.js +++ b/libraries/botframework-streaming/tests/Disassembler.test.js @@ -1,10 +1,10 @@ -const Disassemblers = require('../lib/Disassemblers/RequestDisassembler'); -const PayloadSender = require('../lib/PayloadTransport/PayloadSender'); -const Request = require('../lib/StreamingRequest'); -const HttpContentStream = require('../lib/HttpContentStream'); -const Stream = require('../lib/SubscribableStream'); -const CancelDisassembler = require('../lib/Disassemblers/CancelDisassembler'); -const PayloadTypes = require('../lib/Payloads/PayloadTypes'); +const Disassemblers = require('../lib/disassemblers/requestDisassembler'); +const PayloadSender = require('../lib/payloadTransport/payloadSender'); +const Request = require('../lib/streamingRequest'); +const HttpContentStream = require('../lib/httpContentStream'); +const Stream = require('../lib/subscribableStream'); +const CancelDisassembler = require('../lib/disassemblers/cancelDisassembler'); +const PayloadTypes = require('../lib/payloads/payloadTypes'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/HeaderSerializer.test.js b/libraries/botframework-streaming/tests/HeaderSerializer.test.js index 63ec56fd41..c4c01e4d37 100644 --- a/libraries/botframework-streaming/tests/HeaderSerializer.test.js +++ b/libraries/botframework-streaming/tests/HeaderSerializer.test.js @@ -1,7 +1,7 @@ const chai = require( 'chai'); -const HeaderSerializer = require( '../lib/Payloads/HeaderSerializer'); -const PayloadTypes = require( '../lib/Payloads/PayloadTypes'); -const PayloadConstants = require( '../lib/Payloads/PayloadConstants'); +const HeaderSerializer = require( '../lib/payloads/headerSerializer'); +const PayloadTypes = require( '../lib/payloads/payloadTypes'); +const PayloadConstants = require( '../lib/payloads/payloadConstants'); var expect = chai.expect; describe('HeaderSerializer', () => { diff --git a/libraries/botframework-streaming/tests/NamedPipe.test.js b/libraries/botframework-streaming/tests/NamedPipe.test.js index 09832c8ce2..5d59f2daae 100644 --- a/libraries/botframework-streaming/tests/NamedPipe.test.js +++ b/libraries/botframework-streaming/tests/NamedPipe.test.js @@ -1,6 +1,6 @@ const net = require('net'); const np = require('../lib'); -const npt = require('../lib/NamedPipe/NamedPipeTransport'); +const npt = require('../lib/namedPipe/namedPipeTransport'); const protocol = require('../lib'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/PayloadSender.test.js b/libraries/botframework-streaming/tests/PayloadSender.test.js index 0122bd224c..4a5cf13c4f 100644 --- a/libraries/botframework-streaming/tests/PayloadSender.test.js +++ b/libraries/botframework-streaming/tests/PayloadSender.test.js @@ -1,9 +1,9 @@ -const SubscribableStream = require('../lib/SubscribableStream'); -const StreamManager = require('../lib/Payloads/StreamManager'); -const PayloadSender = require('../lib/PayloadTransport/PayloadSender'); -const PayloadReceiver = require('../lib/PayloadTransport/PayloadReceiver'); -const PayloadTypes = require('../lib/Payloads/PayloadTypes'); -const PayloadAssemblerManager = require('../lib/Payloads/PayloadAssemblerManager'); +const SubscribableStream = require('../lib/subscribableStream'); +const StreamManager = require('../lib/payloads/streamManager'); +const PayloadSender = require('../lib/PayloadTransport/payloadSender'); +const PayloadReceiver = require('../lib/PayloadTransport/payloadReceiver'); +const PayloadTypes = require('../lib/payloads/payloadTypes'); +const PayloadAssemblerManager = require('../lib/payloads/payloadAssemblerManager'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/ProtocolAdapter.test.js b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js index f88a157fa4..a6c63ced4d 100644 --- a/libraries/botframework-streaming/tests/ProtocolAdapter.test.js +++ b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js @@ -1,14 +1,14 @@ -const PayloadAssembler = require('../lib/Assemblers/PayloadAssembler'); -const ProtocolAdapter = require('../lib/ProtocolAdapter'); -const RequestManager = require('../lib/Payloads/RequestManager'); -const PayloadSender = require('../lib/PayloadTransport/PayloadSender'); -const PayloadReceiver = require('../lib/PayloadTransport/PayloadReceiver'); -const PayloadConstants = require('../lib/Payloads/PayloadConstants'); -const SubscribableStream = require('../lib/SubscribableStream'); -const RequestHandler = require('../lib/RequestHandler'); -const Response = require('../lib/StreamingResponse'); -const Request = require('../lib/StreamingRequest'); -const StreamManager = require('../lib/Payloads/StreamManager'); +const PayloadAssembler = require('../lib/assemblers/payloadAssembler'); +const ProtocolAdapter = require('../lib/protocolAdapter'); +const RequestManager = require('../lib/payloads/requestManager'); +const PayloadSender = require('../lib/payloadTransport/payloadSender'); +const PayloadReceiver = require('../lib/payloadTransport/payloadReceiver'); +const PayloadConstants = require('../lib/payloads/payloadConstants'); +const SubscribableStream = require('../lib/subscribableStream'); +const RequestHandler = require('../lib/requestHandler'); +const Response = require('../lib/streamingResponse'); +const Request = require('../lib/streamingRequest'); +const StreamManager = require('../lib/payloads/streamManager'); const chai = require('chai'); var sinon = require('sinon'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/RequestManager.test.js b/libraries/botframework-streaming/tests/RequestManager.test.js index d97334a390..90d79aa4a7 100644 --- a/libraries/botframework-streaming/tests/RequestManager.test.js +++ b/libraries/botframework-streaming/tests/RequestManager.test.js @@ -1,4 +1,4 @@ -const RequestManager = require( '../lib/Payloads/RequestManager'); +const RequestManager = require( '../lib/payloads/requestManager'); const chai = require( 'chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/SendOperations.test.js b/libraries/botframework-streaming/tests/SendOperations.test.js index 0742a61989..f52324938c 100644 --- a/libraries/botframework-streaming/tests/SendOperations.test.js +++ b/libraries/botframework-streaming/tests/SendOperations.test.js @@ -1,9 +1,9 @@ -const HttpContent = require('../lib/HttpContentStream'); -const PayloadSender = require('../lib/PayloadTransport/PayloadSender'); -const SubscribableStream = require('../lib/SubscribableStream'); -const SendOperations = require('../lib/payloads/SendOperations'); -const StreamingRequest = require('../lib/StreamingRequest'); -const StreamingResponse = require('../lib/StreamingResponse'); +const HttpContent = require('../lib/httpContentStream'); +const PayloadSender = require('../lib/payloadTransport/payloadSender'); +const SubscribableStream = require('../lib/subscribableStream'); +const SendOperations = require('../lib/payloads/sendOperations'); +const StreamingRequest = require('../lib/streamingRequest'); +const StreamingResponse = require('../lib/streamingResponse'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/StreamManager.test.js b/libraries/botframework-streaming/tests/StreamManager.test.js index 6f64cacea2..6f591dcdf0 100644 --- a/libraries/botframework-streaming/tests/StreamManager.test.js +++ b/libraries/botframework-streaming/tests/StreamManager.test.js @@ -1,7 +1,7 @@ -const StreamManager = require('../lib/Payloads/StreamManager'); -const PayloadTypes = require('../lib/Payloads/PayloadTypes'); -const SubscribableStream = require('../lib/SubscribableStream'); -const PayloadAssembler = require('../lib/Assemblers/PayloadAssembler'); +const StreamManager = require('../lib/payloads/streamManager'); +const PayloadTypes = require('../lib/payloads/payloadTypes'); +const SubscribableStream = require('../lib/subscribableStream'); +const PayloadAssembler = require('../lib/assemblers/payloadAssembler'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/StreamingRequest.test.js b/libraries/botframework-streaming/tests/StreamingRequest.test.js index ee543494ff..4ae5890cfc 100644 --- a/libraries/botframework-streaming/tests/StreamingRequest.test.js +++ b/libraries/botframework-streaming/tests/StreamingRequest.test.js @@ -1,6 +1,6 @@ -const StreamingRequest = require( '../lib/StreamingRequest'); -const HttpContent = require('../lib/HttpContentStream'); -const SubscribableStream = require('../lib/SubscribableStream'); +const StreamingRequest = require( '../lib/streamingRequest'); +const HttpContent = require('../lib/httpContentStream'); +const SubscribableStream = require('../lib/subscribableStream'); const chai = require( 'chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/StreamingResponse.test.js b/libraries/botframework-streaming/tests/StreamingResponse.test.js index 6451a2021c..dff862a5b4 100644 --- a/libraries/botframework-streaming/tests/StreamingResponse.test.js +++ b/libraries/botframework-streaming/tests/StreamingResponse.test.js @@ -1,6 +1,6 @@ -const SubscribableStream = require('../lib/SubscribableStream'); -const HttpContentStream = require('../lib/HttpContentStream'); -const StreamingResponse = require('../lib/StreamingResponse'); +const SubscribableStream = require('../lib/subscribableStream'); +const HttpContentStream = require('../lib/httpContentStream'); +const StreamingResponse = require('../lib/streamingResponse'); const chai = require('chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/SubscribableStream.test.js b/libraries/botframework-streaming/tests/SubscribableStream.test.js index 37e1466ba8..f610f7790a 100644 --- a/libraries/botframework-streaming/tests/SubscribableStream.test.js +++ b/libraries/botframework-streaming/tests/SubscribableStream.test.js @@ -1,4 +1,4 @@ -const Stream = require( '../lib/SubscribableStream'); +const Stream = require( '../lib/subscribableStream'); const chai = require( 'chai'); var expect = chai.expect; diff --git a/libraries/botframework-streaming/tests/TransportConstants.test.js b/libraries/botframework-streaming/tests/TransportConstants.test.js index 8af8f177be..d5818141a6 100644 --- a/libraries/botframework-streaming/tests/TransportConstants.test.js +++ b/libraries/botframework-streaming/tests/TransportConstants.test.js @@ -1,4 +1,4 @@ -const Constants = require( '../lib/Payloads/PayloadConstants'); +const Constants = require( '../lib/payloads/payloadConstants'); const chai = require( 'chai'); var expect = chai.expect; describe('TransportConstants', () => { diff --git a/libraries/botframework-streaming/tests/WebSocket.test.js b/libraries/botframework-streaming/tests/WebSocket.test.js index 6bd8fd082a..f5cfb5d2e1 100644 --- a/libraries/botframework-streaming/tests/WebSocket.test.js +++ b/libraries/botframework-streaming/tests/WebSocket.test.js @@ -1,6 +1,6 @@ const ws = require('../lib'); const protocol = require('../lib'); -const wst = require('../lib/WebSocket/WebSocketTransport'); +const wst = require('../lib/webSocket/webSocketTransport'); const chai = require('chai'); var expect = chai.expect; From 797ce57ef6f5ec6498c78727fba9a33bd5f0d973 Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 12:30:57 -0700 Subject: [PATCH 08/32] Streaming: reference streaming without the 'lib' postfix --- libraries/botbuilder/src/botFrameworkAdapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 95d911681f..cc1a99b8be 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -7,7 +7,7 @@ import { Activity, ActivityTypes, BotAdapter, BotCallbackHandlerKey, ChannelAcco import { AuthenticationConstants, ChannelValidation, ConnectorClient, EmulatorApiClient, GovernmentConstants, GovernmentChannelValidation, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider, TokenApiClient, TokenStatus, TokenApiModels } from 'botframework-connector'; import * as os from 'os'; import { TokenResolver } from './tokenResolver'; -import { IStreamingTransportServer, StreamingRequest, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming/lib'; +import { IStreamingTransportServer, StreamingRequest, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming'; import { WebResource, HttpOperationResponse, HttpClient } from 'botframework-connector/node_modules/@azure/ms-rest-js'; import { Request, ServerUpgradeResponse } from 'restify'; import { Watershed } from 'watershed'; From e350bdbe4f6380579a7d5419e64ef4111a8e8306 Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 23:20:34 -0700 Subject: [PATCH 09/32] Streaming: Javascript style comments and documentation --- .../botbuilder/src/botFrameworkAdapter.ts | 53 ++++++++-------- .../src/assemblers/payloadAssembler.ts | 4 +- .../httpContentStreamDisassembler.ts | 3 + .../src/disassemblers/payloadDisassembler.ts | 3 + .../src/disassemblers/requestDisassembler.ts | 3 + .../src/disassemblers/responseDisassembler.ts | 3 + .../src/interfaces/IAssemblerParams.ts | 3 + .../src/interfaces/IHeader.ts | 4 ++ .../src/interfaces/IHttpContentHeaders.ts | 3 + .../src/interfaces/IReceiveRequest.ts | 3 + .../src/interfaces/IReceiveResponse.ts | 3 + .../src/interfaces/IRequestPayload.ts | 3 + .../src/interfaces/IResponsePayload.ts | 3 + .../src/interfaces/ISendPacket.ts | 3 + .../src/interfaces/ISocket.ts | 8 +-- .../src/interfaces/IStreamDescription.ts | 3 + .../src/interfaces/IStreamWrapper.ts | 3 + .../interfaces/IStreamingTransportClient.ts | 7 ++- .../interfaces/IStreamingTransportServer.ts | 7 ++- .../src/interfaces/ITransport.ts | 4 ++ .../src/interfaces/ITransportReceiver.ts | 3 + .../src/interfaces/ITransportSender.ts | 3 + .../src/namedPipe/namedPipeClient.ts | 43 +++++++------ .../src/namedPipe/namedPipeServer.ts | 48 ++++++++------- .../src/namedPipe/namedPipeTransport.ts | 44 ++++++------- .../src/payloadTransport/payloadReceiver.ts | 32 ++++++---- .../src/payloadTransport/payloadSender.ts | 42 +++++++------ .../src/payloads/headerSerializer.ts | 15 +++++ .../src/payloads/payloadAssemblerManager.ts | 3 + .../src/payloads/payloadConstants.ts | 4 ++ .../src/payloads/payloadTypes.ts | 4 ++ .../src/payloads/requestManager.ts | 6 ++ .../src/payloads/sendOperations.ts | 3 + .../src/payloads/streamManager.ts | 3 + .../src/requestHandler.ts | 20 +++--- .../src/streamingRequest.ts | 52 ++++++++-------- .../src/streamingResponse.ts | 31 +++++----- .../src/webSocket/browserWebSocket.ts | 59 +++++++++--------- .../src/webSocket/nodeWebSocket.ts | 61 ++++++++++--------- .../src/webSocket/webSocketClient.ts | 46 +++++++------- .../src/webSocket/webSocketServer.ts | 43 +++++++------ .../src/webSocket/webSocketTransport.ts | 53 +++++++++------- 42 files changed, 444 insertions(+), 300 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index cc1a99b8be..4cf8329c2b 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -37,6 +37,7 @@ class StreamingHttpClient implements HttpClient { /// /// The outgoing request created by the BotframeworkAdapter. /// The streaming transport compatible response to send back to the client. + public async sendRequest(httpRequest: WebResource): Promise { const request = this.mapHttpRequestToProtocolRequest(httpRequest); request.path = request.path.substring(request.path.indexOf('/v3')); @@ -231,10 +232,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide private readonly logger; private streamingLogic: (context: TurnContext) => Promise; - - private isEmulatingOAuthCards: boolean; private streamingServer: IStreamingTransportServer; - + private isEmulatingOAuthCards: boolean; /** @@ -941,12 +940,12 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide ); } - /// - /// Checks the validity of the request and attempts to map it the correct virtual endpoint, - /// then generates and returns a response if appropriate. - /// - /// A ReceiveRequest from the connected channel. - /// A response created by the BotAdapter to be sent to the client that originated the request. + /** + * Checks the validity of the request and attempts to map it the correct virtual endpoint, + * then generates and returns a response if appropriate. + * @param request A ReceiveRequest from the connected channel. + * @returns A response created by the BotAdapter to be sent to the client that originated the request. + */ public async processRequest(request: IReceiveRequest): Promise { let response = new StreamingResponse(); @@ -1017,13 +1016,13 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return response; } - /// - /// Process the initial request to establish a long lived connection via a streaming server. - /// - /// The connection request. - /// The response sent on error or connection termination. - /// Settings to set on the BotframeworkAdapter. - public async useWebSocket(req: Request, res: ServerUpgradeResponse, streamingLogic: (context: TurnContext) => Promise): Promise { + /** + * Process the initial request to establish a long lived connection via a streaming server. + * @param req The connection request. + * @param res The response sent on error or connection termination. + * @param res The logic that will handle incoming requests. + */ + public async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { if (!req.isUpgradeRequest()) { let e = new Error('Upgrade to WebSockets required.'); //this.logger.log(e); @@ -1053,19 +1052,21 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide await this.startWebSocket(new NodeWebSocket(socket)); } - /// - /// Connects the handler to a Named Pipe server and begins listening for incoming requests. - /// - /// The name of the named pipe to use when creating the server. - public async useNamedPipe(pipename: string = defaultPipeName, streamingLogic: (context: TurnContext) => Promise): Promise{ - if (!streamingLogic) { - throw new Error('Streaming logic needs to be provided to `useNamedPipe`'); + + /** + * Connects the handler to a Named Pipe server and begins listening for incoming requests. + * @param pipeName The name of the named pipe to use when creating the server. + * @param logic The logic that will handle incoming requests. + */ + public async useNamedPipe(pipeName: string = defaultPipeName, logic: (context: TurnContext) => Promise): Promise{ + if (!logic) { + throw new Error('Bot logic needs to be provided to `useNamedPipe`'); } - this.streamingLogic = streamingLogic; + this.streamingLogic = logic; - this.streamingServer = new NamedPipeServer(pipename, this); - await this.streamingServer.start(); + this.streamingServer = new NamedPipeServer(pipeName, this); + await this.pipeStreamingServer.start(); } /** diff --git a/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts index 5cb657ca49..8e361badfe 100644 --- a/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts +++ b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts @@ -14,7 +14,9 @@ import { IResponsePayload } from '../interfaces/IResponsePayload'; import { IReceiveResponse, IReceiveRequest } from '../interfaces'; import { IRequestPayload } from '../interfaces/IRequestPayload'; - +/** + * Assembles payloads for streaming library. + */ export class PayloadAssembler { public id: string; public end: boolean; diff --git a/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts index 08c3989978..4087a2d0fc 100644 --- a/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/httpContentStreamDisassembler.ts @@ -12,6 +12,9 @@ import { PayloadTypes } from '../payloads/payloadTypes'; import { PayloadDisassembler } from './payloadDisassembler'; import { IStreamWrapper } from '../interfaces/IStreamWrapper'; +/** + * Disassembler for Http content stream + */ export class HttpContentStreamDisassembler extends PayloadDisassembler { public readonly contentStream: HttpContentStream; public payloadType: PayloadTypes = PayloadTypes.stream; diff --git a/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts index 9c840008ae..13987a751b 100644 --- a/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts @@ -11,6 +11,9 @@ import { PayloadSender } from '../payloadTransport/payloadSender'; import { SubscribableStream } from '../subscribableStream'; import { IStreamWrapper } from '../interfaces/IStreamWrapper'; +/** + * Base class streaming payload disassembling. + */ export abstract class PayloadDisassembler { public abstract payloadType: PayloadTypes; private readonly sender: PayloadSender; diff --git a/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts index 270f24218b..445ed02036 100644 --- a/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts @@ -12,6 +12,9 @@ import { PayloadDisassembler } from './payloadDisassembler'; import { IStreamWrapper } from '../interfaces/IStreamWrapper'; import { IRequestPayload } from '../interfaces/IRequestPayload'; +/** + * Streaming request disassembler. + */ export class RequestDisassembler extends PayloadDisassembler { public request: StreamingRequest; public payloadType: PayloadTypes = PayloadTypes.request; diff --git a/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts index b22771679d..37dfa226b1 100644 --- a/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/responseDisassembler.ts @@ -12,6 +12,9 @@ import { PayloadDisassembler } from './payloadDisassembler'; import { IStreamWrapper } from '../interfaces/IStreamWrapper'; import { IResponsePayload } from '../interfaces/IResponsePayload'; +/** + * Streaming response disassembler. + */ export class ResponseDisassembler extends PayloadDisassembler { public readonly response: StreamingResponse; public readonly payloadType: PayloadTypes = PayloadTypes.response; diff --git a/libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts b/libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts index 4fbc4e3b15..a2ee36092b 100644 --- a/libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts +++ b/libraries/botframework-streaming/src/interfaces/IAssemblerParams.ts @@ -7,6 +7,9 @@ */ import { IHeader } from './IHeader'; +/** + * Parameters for a streaming assembler. + */ export interface IAssemblerParams { header?: IHeader; id?: string; diff --git a/libraries/botframework-streaming/src/interfaces/IHeader.ts b/libraries/botframework-streaming/src/interfaces/IHeader.ts index c41410dd00..bcc9a77d47 100644 --- a/libraries/botframework-streaming/src/interfaces/IHeader.ts +++ b/libraries/botframework-streaming/src/interfaces/IHeader.ts @@ -5,6 +5,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ + + /** + * Streaming payload header definition. + */ export interface IHeader { payloadType: string; payloadLength: number; diff --git a/libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts b/libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts index 14b9a9a637..70a23a88a7 100644 --- a/libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts +++ b/libraries/botframework-streaming/src/interfaces/IHttpContentHeaders.ts @@ -6,6 +6,9 @@ * Licensed under the MIT License. */ +/** + * Streaming Http content header definition. + */ export interface IHttpContentHeaders { type?: string; contentLength?: number; diff --git a/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts b/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts index cfb2a190cd..c6c626f3c8 100644 --- a/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts +++ b/libraries/botframework-streaming/src/interfaces/IReceiveRequest.ts @@ -7,6 +7,9 @@ */ import { ContentStream } from '../contentStream'; +/** + * Streaming receive request definition + */ export interface IReceiveRequest { /// Request verb, null on responses /// diff --git a/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts b/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts index 512bc58278..6fb2a6c31b 100644 --- a/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts +++ b/libraries/botframework-streaming/src/interfaces/IReceiveResponse.ts @@ -7,6 +7,9 @@ */ import { ContentStream } from '../contentStream'; +/** + * Streaming response from a receive request. + */ export interface IReceiveResponse { statusCode?: number; streams: ContentStream[]; diff --git a/libraries/botframework-streaming/src/interfaces/IRequestPayload.ts b/libraries/botframework-streaming/src/interfaces/IRequestPayload.ts index b61df546f9..82ea4afc11 100644 --- a/libraries/botframework-streaming/src/interfaces/IRequestPayload.ts +++ b/libraries/botframework-streaming/src/interfaces/IRequestPayload.ts @@ -7,6 +7,9 @@ */ import { IStreamDescription } from './IStreamDescription'; +/** + * Definition for a streaming request payload. + */ export interface IRequestPayload { verb: string; path: string; diff --git a/libraries/botframework-streaming/src/interfaces/IResponsePayload.ts b/libraries/botframework-streaming/src/interfaces/IResponsePayload.ts index 386622f086..a84969165d 100644 --- a/libraries/botframework-streaming/src/interfaces/IResponsePayload.ts +++ b/libraries/botframework-streaming/src/interfaces/IResponsePayload.ts @@ -7,6 +7,9 @@ */ import { IStreamDescription } from './IStreamDescription'; +/** + * Base class for all dialogs. + */ export interface IResponsePayload { statusCode: number; streams?: IStreamDescription[]; diff --git a/libraries/botframework-streaming/src/interfaces/ISendPacket.ts b/libraries/botframework-streaming/src/interfaces/ISendPacket.ts index 2510a9c92a..e45a7d38cb 100644 --- a/libraries/botframework-streaming/src/interfaces/ISendPacket.ts +++ b/libraries/botframework-streaming/src/interfaces/ISendPacket.ts @@ -8,6 +8,9 @@ import { IHeader } from './IHeader'; import { SubscribableStream } from '../subscribableStream'; +/** + * Streaming send packet definition. + */ export interface ISendPacket { header: IHeader; payload: SubscribableStream; diff --git a/libraries/botframework-streaming/src/interfaces/ISocket.ts b/libraries/botframework-streaming/src/interfaces/ISocket.ts index 15e307ed3c..862e627ea7 100644 --- a/libraries/botframework-streaming/src/interfaces/ISocket.ts +++ b/libraries/botframework-streaming/src/interfaces/ISocket.ts @@ -6,10 +6,10 @@ * Licensed under the MIT License. */ -/// -/// The interface implemented by any compatible socket transport, typically used -/// with the WebSocket server or client. -/// +/** + * The interface implemented by any compatible socket transport, typically used + * with the WebSocket server or client. + */ export interface ISocket { isConnected(): boolean; write(buffer: Buffer); diff --git a/libraries/botframework-streaming/src/interfaces/IStreamDescription.ts b/libraries/botframework-streaming/src/interfaces/IStreamDescription.ts index a91a26a85c..f68449c029 100644 --- a/libraries/botframework-streaming/src/interfaces/IStreamDescription.ts +++ b/libraries/botframework-streaming/src/interfaces/IStreamDescription.ts @@ -6,6 +6,9 @@ * Licensed under the MIT License. */ +/** + * Definition of a stream description. + */ export interface IStreamDescription { id: string; contentType?: string; diff --git a/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts b/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts index 2ea718f721..c26dc54fd2 100644 --- a/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts +++ b/libraries/botframework-streaming/src/interfaces/IStreamWrapper.ts @@ -7,6 +7,9 @@ */ import { SubscribableStream } from '../subscribableStream'; +/** + * Stream with length. + */ export interface IStreamWrapper { stream: SubscribableStream; streamLength?: number; diff --git a/libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts b/libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts index f767e29ae2..ee9304c3a4 100644 --- a/libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts +++ b/libraries/botframework-streaming/src/interfaces/IStreamingTransportClient.ts @@ -8,9 +8,10 @@ import { IReceiveResponse } from './IReceiveResponse'; import { StreamingRequest } from '../StreamingRequest'; -/// -/// Interface implemented by StreamingTransportClient classes for each transport type. -/// +/** + * Abstraction to define the characteristics of a streaming transport client. + * Example possible implementations include WebSocket transport client or NamedPipe transport client. + */ export interface IStreamingTransportClient { connect(): Promise; disconnect(): void; diff --git a/libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts b/libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts index 2b105c1092..7270d7c528 100644 --- a/libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts +++ b/libraries/botframework-streaming/src/interfaces/IStreamingTransportServer.ts @@ -8,9 +8,10 @@ import { IReceiveResponse } from './IReceiveResponse'; import { StreamingRequest } from '../StreamingRequest'; -/// -/// Interface implemented by StreamingTransportServer classes for each transport type. -/// +/** + * Abstraction to define the characteristics of a streaming transport server. + * Example possible implementations include WebSocket transport server or NamedPipe transport server. + */ export interface IStreamingTransportServer { start(): Promise; disconnect(): void; diff --git a/libraries/botframework-streaming/src/interfaces/ITransport.ts b/libraries/botframework-streaming/src/interfaces/ITransport.ts index c0c59750d2..a74323b5cd 100644 --- a/libraries/botframework-streaming/src/interfaces/ITransport.ts +++ b/libraries/botframework-streaming/src/interfaces/ITransport.ts @@ -5,6 +5,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ + + /** + * Abstraction for a generic transport definition. + */ export interface ITransport { isConnected(): boolean; close(); diff --git a/libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts b/libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts index bb174781fe..bdd13e7eb3 100644 --- a/libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts +++ b/libraries/botframework-streaming/src/interfaces/ITransportReceiver.ts @@ -7,6 +7,9 @@ */ import { ITransport } from './ITransport'; +/** + * Definition of a streaming transport that can receive requests. + */ export interface ITransportReceiver extends ITransport { receive(count: number): Promise; } diff --git a/libraries/botframework-streaming/src/interfaces/ITransportSender.ts b/libraries/botframework-streaming/src/interfaces/ITransportSender.ts index d84ac9f8d7..f3e087e370 100644 --- a/libraries/botframework-streaming/src/interfaces/ITransportSender.ts +++ b/libraries/botframework-streaming/src/interfaces/ITransportSender.ts @@ -7,6 +7,9 @@ */ import { ITransport } from './ITransport'; +/** + * Definition of a streaming transport that can send requests. + */ export interface ITransportSender extends ITransport { send(buffer: Buffer): number; } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts index e4310e47d0..396551affe 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts @@ -17,6 +17,9 @@ import { import { NamedPipeTransport } from './NamedPipeTransport'; import { IStreamingTransportClient, IReceiveResponse } from '../interfaces'; +/** + * Streaming transport client implementation that uses named pipes for inter-process communication. + */ export class NamedPipeClient implements IStreamingTransportClient { private readonly _baseName: string; private readonly _requestHandler: RequestHandler; @@ -26,15 +29,14 @@ export class NamedPipeClient implements IStreamingTransportClient { private readonly _protocolAdapter: ProtocolAdapter; private readonly _autoReconnect: boolean; private _isDisconnecting: boolean; - - /// - /// Initializes a new instance of the class. - /// - /// The named pipe to connect to. - /// Optional to process incoming messages received by this client. - /// Optional setting to determine if the client sould attempt to reconnect - /// automatically on disconnection events. Defaults to true. - /// + + /** + * Creates a new instance of the [NamedPipeClient](xref:botbuilder-streaming.NamedPipeClient) class. + * + * @param baseName The named pipe to connect to. + * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this client. + * @param autoReconnect Optional setting to determine if the client sould attempt to reconnect automatically on disconnection events. Defaults to true. + */ public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { this._baseName = baseName; this._requestHandler = requestHandler; @@ -47,9 +49,9 @@ export class NamedPipeClient implements IStreamingTransportClient { this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); } - /// - /// Establish a connection with no custom headers. - /// + /** + * Establish a connection with no custom headers. + */ public async connect(): Promise { let outgoingPipeName: string = NamedPipeTransport.PipePath + this._baseName + NamedPipeTransport.ServerIncomingPath; let outgoing = connect(outgoingPipeName); @@ -59,19 +61,20 @@ export class NamedPipeClient implements IStreamingTransportClient { this._receiver.connect(new NamedPipeTransport(incoming)); } - /// - /// Method used to disconnect this client. - /// + /** + * Disconnect the client. + */ public disconnect(): void { this._sender.disconnect(); this._receiver.disconnect(); } - /// - /// Task used to send data over this client connection. - /// - /// The to send. - /// A that will produce an instance of on completion of the send operation. + /** + * Task used to send data over this client connection. + * + * @param request The [StreamingRequest](xref:botbuilder-streaming.StreamingRequest) to send. + * @returns A promise for an instance of [IReceiveResponse](xref:botbuilder-streaming.IReceiveResponse) on completion of the send operation. + */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts index 53ae5a1308..467cba8acb 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts @@ -17,9 +17,9 @@ import { import { NamedPipeTransport } from './NamedPipeTransport'; import { IStreamingTransportServer, IReceiveResponse } from '../interfaces'; -/// -/// A server for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying Named Pipe transport. -/// +/** +* Streaming transport server implementation that uses named pipes for inter-process communication. +*/ export class NamedPipeServer implements IStreamingTransportServer { private _outgoingServer: Server; private _incomingServer: Server; @@ -32,14 +32,13 @@ export class NamedPipeServer implements IStreamingTransportServer { private readonly _autoReconnect: boolean; private _isDisconnecting: boolean; - /// - /// Initializes a new instance of the class. - /// - /// The named pipe to connect to. - /// A to process incoming messages received by this server. - /// Optional setting to determine if the server sould attempt to reconnect - /// automatically on disconnection events. Defaults to true. - /// + /** + * Creates a new instance of the [NamedPipeServer](xref:botbuilder-streaming.NamedPipeServer) class. + * + * @param baseName The named pipe to connect to. + * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this client. + * @param autoReconnect Optional setting to determine if the client sould attempt to reconnect automatically on disconnection events. Defaults to true. + */ public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { this._baseName = baseName; this._requestHandler = requestHandler; @@ -52,10 +51,11 @@ export class NamedPipeServer implements IStreamingTransportServer { this._receiver.disconnected = this.onConnectionDisconnected.bind(this); } - /// - /// Used to establish the connection used by this server and begin listening for incoming messages. - /// - /// A promised string that will not resolve as long as the server is running. + /** + * Used to establish the connection used by this server and begin listening for incoming messages. + * + * @returns A promised string that will not resolve as long as the server is running. + */ public async start(): Promise { if (this._receiver.isConnected || this._sender.isConnected || this._incomingServer || this._outgoingServer) { this.disconnect(); @@ -91,7 +91,9 @@ export class NamedPipeServer implements IStreamingTransportServer { return 'connected'; } - // Allows for manually disconnecting the server. + /** + * Allows for manually disconnecting the server. + */ public disconnect(): void { this._sender.disconnect(); this._receiver.disconnect(); @@ -106,13 +108,13 @@ export class NamedPipeServer implements IStreamingTransportServer { this._outgoingServer = null; } } - - /// - /// Task used to send data over this server connection. - /// - /// The to send. - /// Optional used to signal this operation should be cancelled. - /// A of type handling the send operation. + + /** + * Task used to send data over this client connection. + * + * @param request The [StreamingRequest](xref:botbuilder-streaming.StreamingRequest) to send. + * @returns A promise for an instance of [IReceiveResponse](xref:botbuilder-streaming.IReceiveResponse) on completion of the send operation. + */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts index 75ec02b6c6..444f999db9 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts @@ -9,6 +9,10 @@ import { Socket } from 'net'; import { ITransportSender } from '../interfaces/ITransportSender'; import { ITransportReceiver } from '../interfaces/ITransportReceiver'; + +/** + * Named pipes based transport sender and receiver abstraction + */ export class NamedPipeTransport implements ITransportSender, ITransportReceiver { public static readonly PipePath: string = '\\\\.\\pipe\\'; public static readonly ServerIncomingPath: string = '.incoming'; @@ -22,10 +26,11 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver private _activeReceiveReject: (reason?: any) => void; private _activeReceiveCount: number; - /// - /// Creates a new instance of the NamedPipeTransport class. - /// - /// The socket object to build this connection on. + /** + * Creates a new instance of the [NamedPipeTransport](xref:botbuilder-streaming.NamedPipeTransport) class. + * + * @param socket The socket object to build this connection on. + */ public constructor(socket: Socket) { this._socket = socket; this._queue = []; @@ -44,10 +49,11 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver } } - /// - /// Writes to the pipe and sends. - /// - /// The buffer full of data to send out across the socket. + /** + * Writes to the pipe and sends. + * + * @param buffer The buffer full of data to send out across the socket. + */ public send(buffer: Buffer): number { if (this._socket && !this._socket.connecting && this._socket.writable) { this._socket.write(buffer); @@ -58,16 +64,16 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver return 0; } - /// - /// Returns true if currently connected. - /// + /** + * Returns true if currently connected. + */ public isConnected(): boolean { return !(!this._socket || this._socket.destroyed || this._socket.connecting); } - /// - /// Closes the transport. - /// + /** + * Closes the transport. + */ public close(): void { if (this._socket) { this._socket.end('end'); @@ -75,9 +81,9 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver } } - // Returns: - // 0 if the socket is closed or no more data can be returned - // 1...count bytes in the buffer + /** + * Receive from the transport into the buffer. + */ public receive(count: number): Promise { if (this._activeReceiveResolve) { throw new Error('Cannot call receive more than once before it has returned.'); @@ -95,10 +101,6 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver return promise; } - /// - /// Creates a new instance of the NamedPipeTransport class. - /// - /// The socket object to build this connection on. private socketReceive(data: Buffer): void { if (this._queue && data && data.length > 0) { this._queue.push(data); diff --git a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts index d6542601ba..a187eb1389 100644 --- a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts @@ -14,6 +14,9 @@ import { TransportDisconnectedEventArgs } from './TransportDisconnectedEventArgs import { ITransportReceiver } from '../interfaces/ITransportReceiver'; import { IHeader } from '../interfaces/IHeader'; +/** + * Payload receiver for straming. + */ export class PayloadReceiver { public isConnected: boolean; public disconnected: TransportDisconnectedEventHandler = function(sender, events){}; @@ -23,10 +26,11 @@ export class PayloadReceiver { private _getStream: (header: IHeader) => SubscribableStream; private _receiveAction: (header: IHeader, stream: SubscribableStream, length: number) => void; - /// - /// Creates a new instance of the PayloadReceiver class. - /// - /// The ITransportReceiver object to pull incoming data from. + /** + * Connects to a transport receiver + * + * @param receiver The [ITransportReceiver](xref:botbuilder-streaming.ITransportReceiver) object to pull incoming data from. + */ public connect(receiver: ITransportReceiver): void { if (this.isConnected) { throw new Error('Already connected.'); @@ -37,20 +41,22 @@ export class PayloadReceiver { } } - /// - /// Allows subscribing to this receiver in order to be notified when new data comes in. - /// - /// Callback when a new stream has been received. - /// Callback when a new message has been received. + /** + * Allows subscribing to this receiver in order to be notified when new data comes in. + * + * @param getStream Callback when a new stream has been received. + * @param receiveAction Callback when a new message has been received. + */ public subscribe(getStream: (header: IHeader) => SubscribableStream, receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void): void { this._getStream = getStream; this._receiveAction = receiveAction; } - /// - /// Force this receiver to disconnect. - /// - /// Event arguments to include when broadcasting disconnection event. + /** + * Force this receiver to disconnect. + * + * @param e Event arguments to include when broadcasting disconnection event. + */ public disconnect(e?: TransportDisconnectedEventArgs): void { let didDisconnect; try { diff --git a/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts b/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts index 061eb830d3..68a1bc95f2 100644 --- a/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadSender.ts @@ -15,40 +15,48 @@ import { ITransportSender } from '../interfaces/ITransportSender'; import { IHeader } from '../interfaces/IHeader'; import { ISendPacket } from '../interfaces/ISendPacket'; +/** + * Streaming payload sender. + */ export class PayloadSender { public disconnected?: TransportDisconnectedEventHandler; private sender: ITransportSender; - /// - /// Returns true if connected to a transport sender. - /// + /** + * Tests whether the transport sender is connected. + * + * @returns true if connected to a transport sender. + */ public get isConnected(): boolean { return !!this.sender; } - /// - /// Connects to the given transport sender. - /// - /// The transport sender to connect this payload sender to. + /** + * Connects to the given transport sender. + * + * @param sender The transport sender to connect this payload sender to. + */ public connect(sender: ITransportSender): void { this.sender = sender; } - /// - /// Sends a payload out over the connected transport sender. - /// - /// The header to attach to the outgoing payload. - /// The stream of buffered data to send. - /// The function to execute when the send has completed. + /** + * Sends a payload out over the connected transport sender. + * + * @param header The header to attach to the outgoing payload. + * @param payload The stream of buffered data to send. + * @param sentCalback The function to execute when the send has completed. + */ public sendPayload(header: IHeader, payload?: SubscribableStream, sentCallback?: () => Promise): void { var packet: ISendPacket = {header, payload, sentCallback}; this.writePacket(packet); } - /// - /// Disconnects this payload sender. - /// - /// The disconnected event arguments to include in the disconnected event broadcast. + /** + * Disconnects this payload sender. + * + * @param e The disconnected event arguments to include in the disconnected event broadcast. + */ public disconnect(e?: TransportDisconnectedEventArgs): void { if (this.isConnected) { this.sender.close(); diff --git a/libraries/botframework-streaming/src/payloads/headerSerializer.ts b/libraries/botframework-streaming/src/payloads/headerSerializer.ts index 8bc851a4ff..07e08a530c 100644 --- a/libraries/botframework-streaming/src/payloads/headerSerializer.ts +++ b/libraries/botframework-streaming/src/payloads/headerSerializer.ts @@ -8,6 +8,9 @@ import { IHeader } from '../interfaces/IHeader'; import { PayloadConstants } from './payloadConstants'; +/** + * Streaming header serializer + */ export class HeaderSerializer { public static readonly Delimiter = '.'; public static readonly Terminator = '\n'; @@ -25,6 +28,12 @@ export class HeaderSerializer { public static readonly TerminatorOffset = 47; public static readonly Encoding = 'utf8'; + /** + * Serializes the header into a buffer + * + * @param header The header to serialize. + * @param buffer The buffer into which to serialize the header. + */ public static serialize(header: IHeader, buffer: Buffer): void { buffer.write(header.payloadType, this.TypeOffset, 1, this.Encoding); buffer.write(this.Delimiter, this.TypeDelimiterOffset, 1, this.Encoding); @@ -36,6 +45,12 @@ export class HeaderSerializer { buffer.write(this.Terminator, this.TerminatorOffset); } + /** + * Deserializes a buffer containing header information. + * + * @param buffer The buffer from which to obtain the data to deserialize. + * @returns The deserialized header from the buffer. + */ public static deserialize(buffer: Buffer): IHeader { let jsonBuffer = buffer.toString(this.Encoding); let headerArray = jsonBuffer.split(this.Delimiter); diff --git a/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts index a53f651dd7..480b292680 100644 --- a/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts +++ b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts @@ -11,6 +11,9 @@ import { StreamManager } from './streamManager'; import { IHeader } from '../interfaces/IHeader'; import { PayloadTypes } from './payloadTypes'; +/** + * Orchestrates assemly of payloads + */ export class PayloadAssemblerManager { private readonly onReceiveRequest; private readonly onReceiveResponse; diff --git a/libraries/botframework-streaming/src/payloads/payloadConstants.ts b/libraries/botframework-streaming/src/payloads/payloadConstants.ts index 8a12645252..9ac5d670c1 100644 --- a/libraries/botframework-streaming/src/payloads/payloadConstants.ts +++ b/libraries/botframework-streaming/src/payloads/payloadConstants.ts @@ -5,6 +5,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ + +/** + * Constants for streaming payloads. + */ export enum PayloadConstants { MaxPayloadLength = 4096, MaxHeaderLength = 48, diff --git a/libraries/botframework-streaming/src/payloads/payloadTypes.ts b/libraries/botframework-streaming/src/payloads/payloadTypes.ts index f389469545..2c98016885 100644 --- a/libraries/botframework-streaming/src/payloads/payloadTypes.ts +++ b/libraries/botframework-streaming/src/payloads/payloadTypes.ts @@ -5,6 +5,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ + +/** + * Typess of payloads supported in the streaming library. + */ export enum PayloadTypes { request = 'A', response = 'B', diff --git a/libraries/botframework-streaming/src/payloads/requestManager.ts b/libraries/botframework-streaming/src/payloads/requestManager.ts index 1fcd6093ca..4463842a2e 100644 --- a/libraries/botframework-streaming/src/payloads/requestManager.ts +++ b/libraries/botframework-streaming/src/payloads/requestManager.ts @@ -7,12 +7,18 @@ */ import { IReceiveResponse } from '../interfaces/IReceiveResponse'; +/** + * A streaming pending request. + */ class PendingRequest { public requestId: string; public resolve: (response: IReceiveResponse) => void; public reject: (reason?: any) => void; } +/** + * Orchestrates and manages pending streaming requests. + */ export class RequestManager { private readonly _pendingRequests = {}; diff --git a/libraries/botframework-streaming/src/payloads/sendOperations.ts b/libraries/botframework-streaming/src/payloads/sendOperations.ts index 2225c81108..0ebe34042b 100644 --- a/libraries/botframework-streaming/src/payloads/sendOperations.ts +++ b/libraries/botframework-streaming/src/payloads/sendOperations.ts @@ -14,6 +14,9 @@ import { RequestDisassembler } from '../disassemblers/requestDisassembler'; import { ResponseDisassembler } from '../disassemblers/responseDisassembler'; import { PayloadTypes } from './payloadTypes'; +/** + * Send operations for streaming payloads. + */ export class SendOperations { private readonly payloadSender: PayloadSender; diff --git a/libraries/botframework-streaming/src/payloads/streamManager.ts b/libraries/botframework-streaming/src/payloads/streamManager.ts index 7fb3612874..bac0bfb1bc 100644 --- a/libraries/botframework-streaming/src/payloads/streamManager.ts +++ b/libraries/botframework-streaming/src/payloads/streamManager.ts @@ -9,6 +9,9 @@ import { IHeader } from '../interfaces/IHeader'; import { SubscribableStream } from '../subscribableStream'; import { PayloadAssembler } from '../assemblers/payloadAssembler'; +/** + * Orchestrates and manages streams. + */ export class StreamManager { private readonly activeAssemblers = []; private readonly onCancelStream: Function; diff --git a/libraries/botframework-streaming/src/requestHandler.ts b/libraries/botframework-streaming/src/requestHandler.ts index ee9438a247..705c0981c4 100644 --- a/libraries/botframework-streaming/src/requestHandler.ts +++ b/libraries/botframework-streaming/src/requestHandler.ts @@ -7,15 +7,17 @@ */ import { IReceiveRequest } from './Interfaces/IReceiveRequest'; import { StreamingResponse } from './streamingResponse'; -/// -/// Implemented by classes used to process incoming requests sent over an and adhering to the Bot Framework Protocol v3 with Streaming Extensions. -/// + +/** + * Implemented by classes used to process incoming streaming requests sent over an [IStreamingTransport](xref:botbuilder-streaming.IStreamingTransport). + */ export abstract class RequestHandler { - /// - /// The method that must be implemented in order to handle incoming requests. - /// - /// A for this handler to process. - /// Logger. - /// A promise that will produce a on successful completion. + + /** + * The method that must be implemented in order to handle incoming requests. + * + * @param request A receipt request for this handler to process. + * @returns A promise that will produce a streaming response on successful completion. + */ public abstract processRequest(request: IReceiveRequest, logger?): Promise; } diff --git a/libraries/botframework-streaming/src/streamingRequest.ts b/libraries/botframework-streaming/src/streamingRequest.ts index 73f37ce37d..22afcc2404 100644 --- a/libraries/botframework-streaming/src/streamingRequest.ts +++ b/libraries/botframework-streaming/src/streamingRequest.ts @@ -9,28 +9,30 @@ import { HttpContent, HttpContentStream } from './httpContentStream'; import { SubscribableStream } from './subscribableStream'; export class StreamingRequest { - /// - /// Request verb, null on responses - /// + + /** + * Request verb, null on responses. + */ public verb: string; - /// - /// Request path; null on responses - /// + /** + * Request path; null on responses. + */ public path: string; - /// - /// List of associated streams - /// + /** + * List of associated streams. + */ public streams: HttpContentStream[] = []; - /// - /// Creates a with the passed in method, path, and body. - /// - /// The HTTP verb to use for this request. - /// Optional path where the resource can be found on the remote server. - /// Optional body to send to the remote server. - /// On success returns a with appropriate status code and body. + /** + * 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. + */ public static create(method: string, path?: string, body?: HttpContent): StreamingRequest { let request = new StreamingRequest(); request.verb = method; @@ -42,10 +44,11 @@ export class StreamingRequest { return request; } - /// - /// Adds a new stream attachment to this . - /// - /// The to include in the new stream attachment. + /** + * Adds a new stream attachment to this streaming request. + * + * @param content The Http content to include in the new stream attachment. + */ public addStream(content: HttpContent): void { if (!content) { throw new Error('Argument Undefined Exception: content undefined.'); @@ -54,10 +57,11 @@ export class StreamingRequest { this.streams.push(new HttpContentStream(content)); } - /// - /// Sets the contents of the body of this streamingRequest. - /// - /// The JSON text to write to the body of the streamingRequest. + /** + * Sets the contents of the body of this streamingRequest. + * + * @param body The JSON text to write to the body of the streamingRequest. + */ public setBody(body: any): void { if (typeof body === 'string') { let stream = new SubscribableStream(); diff --git a/libraries/botframework-streaming/src/streamingResponse.ts b/libraries/botframework-streaming/src/streamingResponse.ts index cc97d801a6..affaed9616 100644 --- a/libraries/botframework-streaming/src/streamingResponse.ts +++ b/libraries/botframework-streaming/src/streamingResponse.ts @@ -12,12 +12,13 @@ export class StreamingResponse { public statusCode: number; public streams: HttpContentStream[] = []; - /// - /// Creates a response using the passed in statusCode and optional body. - /// - /// The to set on the . - /// An optional body containing additional information. - /// A streamingResponse with the appropriate statuscode and passed in body. + /** + * 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. + */ public static create(statusCode: number, body?: HttpContent): StreamingResponse { let response = new StreamingResponse(); response.statusCode = statusCode; @@ -28,18 +29,20 @@ export class StreamingResponse { return response; } - /// - /// Adds a new stream attachment to this . - /// - /// The to include in the new stream attachment. + /** + * Adds a new stream attachment to this streaming request. + * + * @param content The Http content to include in the new stream attachment. + */ public addStream(content: HttpContent): void { this.streams.push(new HttpContentStream(content)); } - /// - /// Sets the contents of the body of this streamingResponse. - /// - /// The JSON text to write to the body of the streamingResponse. + /** + * Sets the contents of the body of this streaming response. + * + * @param body The JSON text to write to the body of the streaming response. + */ public setBody(body: any): void { let stream = new SubscribableStream(); stream.write(JSON.stringify(body), 'utf8'); diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index 85c2e69de6..eba1608cd6 100644 --- a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts @@ -10,20 +10,22 @@ import { ISocket } from '../interfaces/ISocket'; export class BrowserWebSocket implements ISocket { private webSocket: WebSocket; - /// - /// Creates a new instance of the BrowserWebSocket class. - /// - /// The socket object to build this connection on. + /** + * Creates a new instance of the [BrowserWebSocket](xref:botbuilder-streaming.BrowserWebSocket) class. + * + * @param socket The socket object to build this connection on. + */ public constructor(socket?: WebSocket) { if (socket) { this.webSocket = socket; } } - /// - /// Connects to the supporting socket using WebSocket protocol. - /// - /// The address the server is listening on. + /** + * Connects to the supporting socket using WebSocket protocol. + * + * @param serverAddress The address the server is listening on. + */ public async connect(serverAddress: string): Promise { let resolver; let rejector; @@ -47,31 +49,32 @@ export class BrowserWebSocket implements ISocket { } - /// - /// True if the socket is currently connected. - /// + /** + * True if the socket is currently connected. + */ public isConnected(): boolean { return this.webSocket.readyState === 1; } - /// - /// Writes a buffer to the socket and sends it. - /// - /// The buffer of data to send across the connection. + /** + * Writes a buffer to the socket and sends it. + * + * @param buffer The buffer of data to send across the connection. + */ public write(buffer: Buffer): void { this.webSocket.send(buffer); } - /// - /// Close the socket. - /// + /** + * Close the socket. + */ public close(): void { this.webSocket.close(); } - /// - /// Set the handler for text and binary messages received on the socket. - /// + /** + * Set the handler for text and binary messages received on the socket. + */ public setOnMessageHandler(handler: (x: any) => void): void { let packets = []; this.webSocket.onmessage = (evt): void => { @@ -92,16 +95,16 @@ export class BrowserWebSocket implements ISocket { }; } - /// - /// Set the callback to call when encountering errors. - /// + /** + * Set the callback to call when encountering errors. + */ public setOnErrorHandler(handler: (x: any) => void): void { this.webSocket.onerror = (error): void => { if (error) { handler(error); } }; } - - /// - /// Set the callback to call when encountering socket closures. - /// + + /** + * Set the callback to call when encountering socket closures. + */ public setOnCloseHandler(handler: (x: any) => void): void { this.webSocket.onclose = handler; } diff --git a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts index 37b028f9f6..6e9c525634 100644 --- a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts @@ -13,37 +13,40 @@ export class NodeWebSocket implements ISocket { private readonly waterShedSocket: any; private connected: boolean; - /// - /// Creates a new instance of the NodeWebSocket class. - /// - /// The WaterShed socket object to build this connection on. + /** + * Creates a new instance of the [NodeWebSocket](xref:botbuilder-streaming.NodeWebSocket) class. + * + * @param socket The WaterShed socket object to build this connection on. + */ public constructor(waterShedSocket?) { this.waterShedSocket = waterShedSocket; this.connected = !!waterShedSocket; } - /// - /// True if the socket is currently connected. - /// + /** + * True if the socket is currently connected. + */ public isConnected(): boolean { return this.connected; } - /// - /// Writes a buffer to the socket and sends it. - /// - /// The buffer of data to send across the connection. + /** + * Writes a buffer to the socket and sends it. + * + * @param buffer The buffer of data to send across the connection. + */ public write(buffer: Buffer): void { this.waterShedSocket.send(buffer); } - /// - /// Connects to the supporting socket using WebSocket protocol. - /// - /// The address the server is listening on. - /// The port the server is listening on, defaults to 8082. + /** + * Connects to the supporting socket using WebSocket protocol. + * + * @param serverAddress The address the server is listening on. + * @param port The port the server is listening on, defaults to 8082. + */ public async connect(serverAddress, port = 8082): Promise { - // following template from https://github.com/joyent/node-watershed#readme + // Following template from https://github.com/joyent/node-watershed#readme let shed = new WaterShed.Watershed(); let wskey = shed.generateKey(); let options = { @@ -69,33 +72,33 @@ export class NodeWebSocket implements ISocket { }); } - /// - /// Set the handler for text and binary messages received on the socket. - /// + /** + * Set the handler for text and binary messages received on the socket. + */ public setOnMessageHandler(handler: (x: any) => void): void { this.waterShedSocket.on('text', handler); this.waterShedSocket.on('binary', handler); } - /// - /// Close the socket. - /// + /** + * Close the socket. + */ public close(): any { this.connected = false; return this.waterShedSocket.end(); } - /// - /// Set the callback to call when encountering socket closures. - /// + /** + * Set the callback to call when encountering socket closures. + */ public setOnCloseHandler(handler: (x: any) => void): void { this.waterShedSocket.on('end', handler); } - /// - /// Set the callback to call when encountering errors. - /// + /** + * Set the callback to call when encountering errors. + */ public setOnErrorHandler(handler: (x: any) => void): void { this.waterShedSocket.on('error', (error): void => { if (error) { handler(error); } }); } diff --git a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts index 277d6872da..2f3c7e687f 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts @@ -19,9 +19,9 @@ import { NodeWebSocket } from './NodeWebSocket'; import { WebSocketTransport } from './WebSocketTransport'; import { IStreamingTransportClient, IReceiveResponse } from '../interfaces'; -/// -/// A client for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying WebSocket transport. -/// +/** + * Web socket based client to be used as streaming transport. + */ export class WebSocketClient implements IStreamingTransportClient { private readonly _url: string; private readonly _requestHandler: RequestHandler; @@ -31,13 +31,13 @@ export class WebSocketClient implements IStreamingTransportClient { private readonly _protocolAdapter: ProtocolAdapter; private readonly _disconnectionHandler: (message: string) => void; - /// - /// Initializes a new instance of the class. - /// - /// The URL of the remote server to connect to. - /// Optional to process incoming messages received by this server. - /// Optional function to handle the disconnection message - /// + /** + * Creates a new instance of the [WebSocketClient](xref:botbuilder-streaming.WebSocketClient) class. + * + * @param url The URL of the remote server to connect to. + * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this server. + * @param disconnectionHandler Optional function to handle the disconnection message. + */ public constructor({ url, requestHandler, disconnectionHandler = null}) { this._url = url; this._requestHandler = requestHandler; @@ -53,10 +53,11 @@ export class WebSocketClient implements IStreamingTransportClient { this._protocolAdapter = new ProtocolAdapter(this._requestHandler, this._requestManager, this._sender, this._receiver); } - /// - /// Establish a connection with no custom headers. - /// - /// A promise that will not resolve until the client stops listening for incoming messages. + /** + * Establish a connection with no custom headers. + * + * @returns A promise that will not resolve until the client stops listening for incoming messages. + */ public async connect(): Promise { if (typeof WebSocket !== 'undefined') { const ws = new BrowserWebSocket(); @@ -77,19 +78,20 @@ export class WebSocketClient implements IStreamingTransportClient { } } - /// - /// Stop this client from listening. - /// + /** + * Stop this client from listening. + */ public disconnect(): void { this._sender.disconnect(new TransportDisconnectedEventArgs('Disconnect was called.')); this._receiver.disconnect(new TransportDisconnectedEventArgs('Disconnect was called.')); } - /// - /// Task used to send data over this client connection. - /// - /// The to send. - /// A promise that will produce an instance of on completion of the send operation. + /** + * Task used to send data over this client connection. + * + * @param request The streaming request to send. + * @returns A promise that will produce an instance of receive response on completion of the send operation. + */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); } diff --git a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts index e468be11ad..cb246d1a4c 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts @@ -18,9 +18,9 @@ import { ISocket } from '../interfaces/ISocket'; import { WebSocketTransport } from './WebSocketTransport'; import { IStreamingTransportServer, IReceiveResponse } from '../interfaces'; -/// -/// A server for use with the Bot Framework Protocol V3 with Streaming Extensions and an underlying WebSocket transport. -/// +/** + * Web socket based server to be used as streaming transport. + */ export class WebSocketServer implements IStreamingTransportServer { private readonly _url: string; private readonly _requestHandler: RequestHandler; @@ -31,11 +31,12 @@ export class WebSocketServer implements IStreamingTransportServer { private readonly _webSocketTransport: WebSocketTransport; private _closedSignal; - /// - /// Initializes a new instance of the class. - /// - /// The of the underlying connection for this server to be built on top of. - /// A to process incoming messages received by this server. + /** + * Creates a new instance of the [WebSocketServer](xref:botbuilder-streaming.WebSocketServer) class. + * + * @param socket The underlying web socket. + * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this server. + */ public constructor(socket: ISocket, requestHandler?: RequestHandler) { this._webSocketTransport = new WebSocketTransport(socket); this._requestHandler = requestHandler; @@ -52,10 +53,11 @@ export class WebSocketServer implements IStreamingTransportServer { this._closedSignal = (x: string): string => { return x; }; } - /// - /// Used to establish the connection used by this server and begin listening for incoming messages. - /// - /// A promise to handle the server listen operation. This task will not resolve as long as the server is running. + /** + * Used to establish the connection used by this server and begin listening for incoming messages. + * + * @returns A promise to handle the server listen operation. This task will not resolve as long as the server is running. + */ public async start(): Promise { this._sender.connect(this._webSocketTransport); this._receiver.connect(this._webSocketTransport); @@ -63,18 +65,19 @@ export class WebSocketServer implements IStreamingTransportServer { return this._closedSignal; } - /// - /// Used to send data over this server connection. - /// - /// The to send. - /// A promise of type handling the send operation. + /** + * Task used to send data over this server connection. + * + * @param request The streaming request to send. + * @returns A promise that will produce an instance of receive response on completion of the send operation. + */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); } - /// - /// Stop this server. - /// + /** + * Stop this server. + */ public disconnect(): void { this._sender.disconnect(new TransportDisconnectedEventArgs('Disconnect was called.')); this._receiver.disconnect(new TransportDisconnectedEventArgs('Disconnect was called.')); diff --git a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts index ab6ff864fd..69a8b91e2d 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts @@ -9,6 +9,9 @@ import { ISocket } from '../interfaces'; import { ITransportSender } from '../interfaces/ITransportSender'; import { ITransportReceiver } from '../interfaces/ITransportReceiver'; +/** + * Web socket based transport. + */ export class WebSocketTransport implements ITransportSender, ITransportReceiver { private _socket: ISocket; private readonly _queue: Buffer[]; @@ -18,10 +21,11 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver private _activeReceiveReject: (reason?: any) => void; private _activeReceiveCount: number; - /// - /// Creates a new instance of the WebSocketTransport class. - /// - /// The ISocket to build this transport on top of. + /** + * Creates a new instance of the [WebSocketTransport](xref:botbuilder-streaming.WebSocketTransport) class. + * + * @param ws The ISocket to build this transport on top of. + */ public constructor(ws: ISocket) { this._socket = ws; this._queue = []; @@ -38,10 +42,11 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver }); } - /// - /// Sends the given buffer out over the socket's connection. - /// - /// The buffered data to send out over the connection. + /** + * Sends the given buffer out over the socket's connection. + * + * @param buffer The buffered data to send out over the connection. + */ public send(buffer: Buffer): number { if (this._socket && this._socket.isConnected()) { this._socket.write(buffer); @@ -52,27 +57,28 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver return 0; } - /// - /// Returns true if the transport is connected to a socket. - /// + /** + * Returns true if the transport is connected to a socket. + */ public isConnected(): boolean { return this._socket.isConnected(); } - /// - /// Close the socket this transport is connected to. - /// + /** + * Close the socket this transport is connected to. + */ public close(): void { if (this._socket && this._socket.isConnected()) { this._socket.close(); } } - /// - /// Attempt to receive incoming data from the connected socket. - /// - /// The number of bytes to attempt to receive. - /// A buffer populated with the received data. + /** + * Attempt to receive incoming data from the connected socket. + * + * @param count The number of bytes to attempt to receive. + * @returns A buffer populated with the received data. + */ public async receive(count: number): Promise { if (this._activeReceiveResolve) { throw new Error('Cannot call receiveAsync more than once before it has returned.'); @@ -90,10 +96,11 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver return promise; } - /// - /// Sets the transport to attempt to receive incoming data that has not yet arrived. - /// - /// A buffer to store incoming data in. + /** + * Sets the transport to attempt to receive incoming data that has not yet arrived. + * + * @param data A buffer to store incoming data in. + */ public onReceive(data: Buffer): void { if (this._queue && data && data.byteLength > 0) { this._queue.push(Buffer.from(data)); From 84eae25da095d1eed83c21051b8332fd791a90cd Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 23:45:45 -0700 Subject: [PATCH 10/32] Streaming: Remove unnecessary logger, use http response and body to report error info --- .../botbuilder/src/botFrameworkAdapter.ts | 63 ++++++++----------- .../src/payloads/headerSerializer.ts | 10 +-- .../src/payloads/requestManager.ts | 2 +- .../src/requestHandler.ts | 2 +- .../src/webSocket/browserWebSocket.ts | 7 ++- .../src/webSocket/webSocketClient.ts | 2 +- 6 files changed, 38 insertions(+), 48 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 4cf8329c2b..8ca8162ec0 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -229,7 +229,6 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide private readonly credentials: MicrosoftAppCredentials; private readonly credentialsProvider: SimpleCredentialProvider; private readonly settings: BotFrameworkAdapterSettings; - private readonly logger; private streamingLogic: (context: TurnContext) => Promise; private streamingServer: IStreamingTransportServer; @@ -949,13 +948,18 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide public async processRequest(request: IReceiveRequest): Promise { let response = new StreamingResponse(); - if (!request || !request.verb || !request.path) { + if (!request) { response.statusCode = StatusCodes.BAD_REQUEST; - //this.logger.log('Request missing verb and/or path.'); - + response.setBody(`No request provided.`); return response; } + if (!request.verb || !request.path) { + response.statusCode = StatusCodes.BAD_REQUEST; + response.setBody(`Request missing verb and/or path. Verb: ${ request.verb }. Path: ${ request.path }`); + return response; + } + if (request.verb.toLocaleUpperCase() === GET && request.path.toLocaleLowerCase() === VERSION_PATH) { response.statusCode = StatusCodes.OK; response.setBody(this.getUserAgent()); @@ -969,20 +973,19 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide } catch (error) { response.statusCode = StatusCodes.BAD_REQUEST; - //this.logger.log('Unable to read request body. Error: ' + error); - + response.setBody(`Unable to read request body. Error: ${ error }`); return response; } if (request.verb.toLocaleUpperCase() !== POST) { response.statusCode = StatusCodes.METHOD_NOT_ALLOWED; - + response.setBody(`Method ${ request.verb.toLocaleUpperCase() } not allowed. Expected POST.`); return response; } if (request.path.toLocaleLowerCase() !== MESSAGES_PATH) { response.statusCode = StatusCodes.NOT_FOUND; - + response.setBody(`Path ${ request.path.toLocaleLowerCase() } not not found. Expected ${ MESSAGES_PATH }}.`); return response; } @@ -1007,10 +1010,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide } } catch (error) { response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR; - //this.logger.log(error); - + response.setBody(error); return response; - } return response; @@ -1025,24 +1026,21 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide public async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { if (!req.isUpgradeRequest()) { let e = new Error('Upgrade to WebSockets required.'); - //this.logger.log(e); res.status(StatusCodes.UPGRADE_REQUIRED); res.send(e.message); return Promise.resolve(); } - if (!streamingLogic) { + if (!logic) { throw new Error('Streaming logic needs to be provided to `useWebSocket`'); } - this.streamingLogic = streamingLogic; + this.streamingLogic = logic; const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); if (!authenticated) { - //this.logger.log('Unauthorized connection attempt.'); res.status(StatusCodes.UNAUTHORIZED); - return Promise.resolve(); } @@ -1066,7 +1064,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide this.streamingLogic = logic; this.streamingServer = new NamedPipeServer(pipeName, this); - await this.pipeStreamingServer.start(); + await this.streamingServer.start(); } /** @@ -1172,25 +1170,19 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return true; } - try { - let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; - let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; - let credentials = new MicrosoftAppCredentials(appId, appPassword); - let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); - let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); - - return claims.isAuthenticated; - } catch (error) { - //this.logger.log(error); + let authHeader: string = req.headers.authorization || req.headers.Authorization || ''; + let channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || ''; + let credentials = new MicrosoftAppCredentials(appId, appPassword); + let credentialProvider = new SimpleCredentialProvider(credentials.appId, credentials.appPassword); + let claims = await JwtTokenValidation.validateAuthHeader(authHeader, credentialProvider, channelService, channelIdHeader); - return false; - } + return claims.isAuthenticated; } - - /// - /// Connects the handler to a WebSocket server and begins listening for incoming requests. - /// - /// The socket to use when creating the server. + + /** + * Connects the handler to a WebSocket server and begins listening for incoming requests. + * @param socket The socket to use when creating the server. + */ private async startWebSocket(socket: ISocket): Promise{ this.streamingServer = new WebSocketServer(socket, this); await this.streamingServer.start(); @@ -1199,11 +1191,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide private async readRequestBodyAsString(request: IReceiveRequest): Promise { try { let contentStream = request.streams[0]; - return await contentStream.readAsJson(); } catch (error) { - //this.logger.log(error); - return Promise.reject(error); } } diff --git a/libraries/botframework-streaming/src/payloads/headerSerializer.ts b/libraries/botframework-streaming/src/payloads/headerSerializer.ts index 07e08a530c..2e0fb54271 100644 --- a/libraries/botframework-streaming/src/payloads/headerSerializer.ts +++ b/libraries/botframework-streaming/src/payloads/headerSerializer.ts @@ -56,7 +56,7 @@ export class HeaderSerializer { let headerArray = jsonBuffer.split(this.Delimiter); if (headerArray.length !== 4) { - throw Error('Cannot parse header, header is malformed.'); + throw Error(`Cannot parse header, header is malformed. Header: ${ jsonBuffer }`); } const [payloadType, length, id, headerEnd] = headerArray; @@ -67,19 +67,19 @@ export class HeaderSerializer { const header: IHeader = { end, payloadLength, payloadType, id }; if (!(header.payloadLength <= PayloadConstants.MaxPayloadLength && header.payloadLength >= PayloadConstants.MinLength)) { - throw Error('Header Length is missing or malformed.'); + throw Error(`Header length of ${ header.payloadLength } is missing or malformed`); } if (header.payloadType.length !== this.TypeDelimiterOffset) { - throw Error('Header Type is missing or malformed.'); + throw Error(`Header type '${ header.payloadType.length }' is missing or malformed.`); } if (!header.id || !header.id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) || header.id.length !== this.IdLength) { - throw Error('Header ID is missing or malformed.'); + throw Error(`Header ID '${ header.id }' is missing or malformed.`); } if (!(headerEnd === '0\n' || headerEnd === '1\n')) { - throw Error('Header End is missing or not a valid value.'); + throw Error(`Header End is missing or not a valid value. Header end: '${ headerEnd }'`); } return header; diff --git a/libraries/botframework-streaming/src/payloads/requestManager.ts b/libraries/botframework-streaming/src/payloads/requestManager.ts index 4463842a2e..b072fe6c41 100644 --- a/libraries/botframework-streaming/src/payloads/requestManager.ts +++ b/libraries/botframework-streaming/src/payloads/requestManager.ts @@ -43,7 +43,7 @@ export class RequestManager { let pendingRequest = this._pendingRequests[requestId]; if (pendingRequest) { - return Promise.reject('requestId already exists in RequestManager'); + return Promise.reject(`requestId '${ requestId }' already exists in RequestManager`); } pendingRequest = new PendingRequest(); diff --git a/libraries/botframework-streaming/src/requestHandler.ts b/libraries/botframework-streaming/src/requestHandler.ts index 705c0981c4..fba32ce5f6 100644 --- a/libraries/botframework-streaming/src/requestHandler.ts +++ b/libraries/botframework-streaming/src/requestHandler.ts @@ -19,5 +19,5 @@ export abstract class RequestHandler { * @param request A receipt request for this handler to process. * @returns A promise that will produce a streaming response on successful completion. */ - public abstract processRequest(request: IReceiveRequest, logger?): Promise; + public abstract processRequest(request: IReceiveRequest): Promise; } diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index eba1608cd6..691f7519d9 100644 --- a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts @@ -76,6 +76,7 @@ export class BrowserWebSocket implements ISocket { * Set the handler for text and binary messages received on the socket. */ public setOnMessageHandler(handler: (x: any) => void): void { + const bufferKey: string = 'buffer'; let packets = []; this.webSocket.onmessage = (evt): void => { let fileReader = new FileReader(); @@ -83,10 +84,10 @@ export class BrowserWebSocket implements ISocket { packets.push(queueEntry); fileReader.onload = (e): void => { let t: FileReader = e.target as FileReader; - queueEntry['buffer'] = t.result; + queueEntry[bufferKey] = t.result; if (packets[0] === queueEntry) { - while(0 < packets.length && packets[0]['buffer']) { - handler(packets[0]['buffer']); + while(0 < packets.length && packets[0][bufferKey]) { + handler(packets[0][bufferKey]); packets.splice(0, 1); } } diff --git a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts index 2f3c7e687f..5f5475e862 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts @@ -102,6 +102,6 @@ export class WebSocketClient implements IStreamingTransportClient { return; } - throw(new Error(`Unable to re-connect client to Node transport. Sender:` + sender + ' Args:' + args)); + throw(new Error(`Unable to re-connect client to Node transport for url ${ this._url }. Sender: '${ sender }'. Args:' ${ args }`)); } } From bd5b6cfc038c31505a812216dcbcfcfdc67791d5 Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 23:46:16 -0700 Subject: [PATCH 11/32] Streaming: fix quotes --- libraries/botframework-streaming/src/httpContentStream.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botframework-streaming/src/httpContentStream.ts b/libraries/botframework-streaming/src/httpContentStream.ts index 59befea44f..11cd2a42ad 100644 --- a/libraries/botframework-streaming/src/httpContentStream.ts +++ b/libraries/botframework-streaming/src/httpContentStream.ts @@ -17,7 +17,7 @@ export class HttpContentStream { public constructor(content: HttpContent) { this.id = generateGuid(); this.content = content; - this.description = {id: this.id, type: (this.content.headers) ? this.content.headers.type : "unknown", length: (this.content.headers) ? this.content.headers.contentLength : 0}; + this.description = {id: this.id, type: (this.content.headers) ? this.content.headers.type : 'unknown', length: (this.content.headers) ? this.content.headers.contentLength : 0}; } } From 967bc455a664cd54644fd822d81eefa04323267a Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Mon, 14 Oct 2019 23:55:32 -0700 Subject: [PATCH 12/32] Streaming: Improve comments and error messages --- .../botbuilder/src/botFrameworkAdapter.ts | 196 ++++++++++-------- 1 file changed, 105 insertions(+), 91 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 8ca8162ec0..79e7753ffd 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -26,19 +26,33 @@ export enum StatusCodes { 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. - /// - /// The outgoing request created by the BotframeworkAdapter. - /// The streaming transport compatible response to send back to the client. - + /** + * 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 { + 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); @@ -344,7 +358,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * An asynchronous method that creates and starts a conversation with a user on a channel. * * @param reference A reference for the conversation to create. - * @param logic The asynchronous method to call after the adapter middleware runs. If not provided, the adap + * @param logic The asynchronous method to call after the adapter middleware runs. * * @remarks * To use this method, you need both the bot's and the user's account information on a channel. @@ -939,6 +953,79 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide ); } + /** + * Process the initial request to establish a long lived connection via a streaming server. + * @param req The connection request. + * @param res The response sent on error or connection termination. + * @param res The logic that will handle incoming requests. + */ + public async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { + if (!req.isUpgradeRequest()) { + let e = new Error('Upgrade to WebSockets required.'); + res.status(StatusCodes.UPGRADE_REQUIRED); + res.send(e.message); + + return Promise.resolve(); + } + + if (!logic) { + throw new Error('Streaming logic needs to be provided to `useWebSocket`'); + } + + this.streamingLogic = logic; + + const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); + if (!authenticated) { + res.status(StatusCodes.UNAUTHORIZED); + return Promise.resolve(); + } + + const upgrade = res.claimUpgrade(); + const ws = new Watershed(); + const socket = ws.accept(req, upgrade.socket, upgrade.head); + + await this.startWebSocket(new NodeWebSocket(socket)); + } + + /** + * Connects the handler to a Named Pipe server and begins listening for incoming requests. + * @param pipeName The name of the named pipe to use when creating the server. + * @param logic The logic that will handle incoming requests. + */ + public async useNamedPipe(pipeName: string = defaultPipeName, logic: (context: TurnContext) => Promise): Promise{ + if (!logic) { + throw new Error('Bot logic needs to be provided to `useNamedPipe`'); + } + + this.streamingLogic = logic; + + this.streamingServer = new NamedPipeServer(pipeName, this); + await this.streamingServer.start(); + } + + /** + * Creates a connector client. + * + * @param serviceUrl The client's service URL. + * + * @remarks + * Override this in a derived class to create a mock connector client for unit testing. + */ + public createConnectorClient(serviceUrl: string): ConnectorClient { + if (TurnContext.isStreamingServiceUrl(serviceUrl)) { + return new ConnectorClient( + this.credentials, + { + baseUri: serviceUrl, + userAgent: USER_AGENT, + httpClient: new StreamingHttpClient(this.streamingServer) + }); + } + + const client: ConnectorClient = new ConnectorClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT} ); + return client; + } + /** * Checks the validity of the request and attempts to map it the correct virtual endpoint, * then generates and returns a response if appropriate. @@ -1018,53 +1105,16 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide } /** - * Process the initial request to establish a long lived connection via a streaming server. - * @param req The connection request. - * @param res The response sent on error or connection termination. - * @param res The logic that will handle incoming requests. - */ - public async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { - if (!req.isUpgradeRequest()) { - let e = new Error('Upgrade to WebSockets required.'); - res.status(StatusCodes.UPGRADE_REQUIRED); - res.send(e.message); - - return Promise.resolve(); - } - - if (!logic) { - throw new Error('Streaming logic needs to be provided to `useWebSocket`'); - } - - this.streamingLogic = logic; - - const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); - if (!authenticated) { - res.status(StatusCodes.UNAUTHORIZED); - return Promise.resolve(); - } - - const upgrade = res.claimUpgrade(); - const ws = new Watershed(); - const socket = ws.accept(req, upgrade.socket, upgrade.head); - - await this.startWebSocket(new NodeWebSocket(socket)); - } - - /** - * Connects the handler to a Named Pipe server and begins listening for incoming requests. - * @param pipeName The name of the named pipe to use when creating the server. - * @param logic The logic that will handle incoming requests. + * Creates an OAuth API client. + * + * @param serviceUrl The client's service URL. + * + * @remarks + * Override this in a derived class to create a mock OAuth API client for unit testing. */ - public async useNamedPipe(pipeName: string = defaultPipeName, logic: (context: TurnContext) => Promise): Promise{ - if (!logic) { - throw new Error('Bot logic needs to be provided to `useNamedPipe`'); - } - - this.streamingLogic = logic; - - this.streamingServer = new NamedPipeServer(pipeName, this); - await this.streamingServer.start(); + protected createTokenApiClient(serviceUrl: string): TokenApiClient { + const client = new TokenApiClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT} ); + return client; } /** @@ -1081,42 +1131,6 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide if (!claims.isAuthenticated) { throw new Error('Unauthorized Access. Request is not authorized'); } } - /** - * Creates a connector client. - * - * @param serviceUrl The client's service URL. - * - * @remarks - * Override this in a derived class to create a mock connector client for unit testing. - */ - public createConnectorClient(serviceUrl: string): ConnectorClient { - if (TurnContext.isStreamingServiceUrl(serviceUrl)) { - return new ConnectorClient( - this.credentials, - { - baseUri: serviceUrl, - userAgent: USER_AGENT, - httpClient: new StreamingHttpClient(this.streamingServer) - }); - } - - const client: ConnectorClient = new ConnectorClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT} ); - return client; - } - - /** - * Creates an OAuth API client. - * - * @param serviceUrl The client's service URL. - * - * @remarks - * Override this in a derived class to create a mock OAuth API client for unit testing. - */ - protected createTokenApiClient(serviceUrl: string): TokenApiClient { - const client = new TokenApiClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT} ); - return client; - } - /** * Gets the OAuth API endpoint. * From 65adbc21c23dc9fb1a7b21acae05ebf27b1791a8 Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Tue, 15 Oct 2019 00:37:25 -0700 Subject: [PATCH 13/32] Streaming: refactor StreamingHttpClient to a separate file --- .../botbuilder/src/botFrameworkAdapter.ts | 55 ++----------------- .../botbuilder/src/streamingHttpClient.ts | 50 +++++++++++++++++ 2 files changed, 55 insertions(+), 50 deletions(-) create mode 100644 libraries/botbuilder/src/streamingHttpClient.ts diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 79e7753ffd..c0911cb03a 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1,3 +1,6 @@ +/** + * @module botbuilder + */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. @@ -7,10 +10,10 @@ import { Activity, ActivityTypes, BotAdapter, BotCallbackHandlerKey, ChannelAcco import { AuthenticationConstants, ChannelValidation, ConnectorClient, EmulatorApiClient, GovernmentConstants, GovernmentChannelValidation, JwtTokenValidation, MicrosoftAppCredentials, SimpleCredentialProvider, TokenApiClient, TokenStatus, TokenApiModels } from 'botframework-connector'; import * as os from 'os'; import { TokenResolver } from './tokenResolver'; -import { IStreamingTransportServer, StreamingRequest, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming'; -import { WebResource, HttpOperationResponse, HttpClient } from 'botframework-connector/node_modules/@azure/ms-rest-js'; +import { IStreamingTransportServer, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming'; import { Request, ServerUpgradeResponse } from 'restify'; import { Watershed } from 'watershed'; +import { StreamingHttpClient } from './streamingHttpClient'; export enum StatusCodes { OK = 200, @@ -23,54 +26,6 @@ export enum StatusCodes { NOT_IMPLEMENTED = 501, } -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 { - 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); - } -} - /** * Represents an Express or Restify request object. * diff --git a/libraries/botbuilder/src/streamingHttpClient.ts b/libraries/botbuilder/src/streamingHttpClient.ts new file mode 100644 index 0000000000..636a4eddd5 --- /dev/null +++ b/libraries/botbuilder/src/streamingHttpClient.ts @@ -0,0 +1,50 @@ +/** + * @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 'botframework-connector/node_modules/@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 { + 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); + } +} From 6ba6c18629f5d03bf03e7a19108952f248334d2d Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Tue, 15 Oct 2019 00:37:43 -0700 Subject: [PATCH 14/32] Streaming: update tests to richer error messages --- .../tests/HeaderSerializer.test.js | 17 ++++++++++------- .../tests/RequestManager.test.js | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libraries/botframework-streaming/tests/HeaderSerializer.test.js b/libraries/botframework-streaming/tests/HeaderSerializer.test.js index c4c01e4d37..ba217eec56 100644 --- a/libraries/botframework-streaming/tests/HeaderSerializer.test.js +++ b/libraries/botframework-streaming/tests/HeaderSerializer.test.js @@ -68,7 +68,7 @@ describe('HeaderSerializer', () => { buffer.write('ABCDE.000168.68e999ca-a651-40f4-ad8f-3aaf7b4.1\n'); expect(() => HeaderSerializer.HeaderSerializer.deserialize(buffer)) - .throws('Header Type is missing or malformed.'); + .throws('Header type \'5\' is missing or malformed.'); }); it('throws if the header length is malformed', () => { @@ -77,7 +77,7 @@ describe('HeaderSerializer', () => { buffer.write('A.00b168.68e999ca-a651-40f4-ad8f-3aaf781862b4.1\n'); expect(() => HeaderSerializer.HeaderSerializer.deserialize(buffer)) - .throws('Header Length is missing or malformed.'); + .throws('Header length of NaN is missing or malformed'); }); it('throws if the header length is too small', () => { @@ -86,16 +86,16 @@ describe('HeaderSerializer', () => { buffer.write('A.-100000.68e999ca-a651-40f4-ad8f-3aaf781862b4.1\n'); expect(() => HeaderSerializer.HeaderSerializer.deserialize(buffer)) - .throws('Header Length is missing or malformed.'); + .throws('Header length of -100000 is missing or malformed'); }); - it('throws if the header length is to big', () => { + it('throws if the header length is too big', () => { // expect.assertions(1); let buffer = Buffer.alloc(Number(PayloadConstants.PayloadConstants.MaxHeaderLength)); buffer.write('A.1111111.8e999ca-a651-40f4-ad8f-3aaf781862b4.1\n'); expect(() => HeaderSerializer.HeaderSerializer.deserialize(buffer)) - .throws('Header Length is missing or malformed.'); + .throws('Header length of 1111111 is missing or malformed'); }); it('throws if the header terminator is malformed', () => { @@ -109,11 +109,14 @@ describe('HeaderSerializer', () => { it('throws if the header ID is malformed', () => { // expect.assertions(1); + const headerId = 'A.000168.68e9p9ca-a651-40f4-ad8f-3aaf781862b4.1\n'; + const header = `A.000168.${ headerId }.1\n`; + let buffer = Buffer.alloc(Number(PayloadConstants.PayloadConstants.MaxHeaderLength)); - buffer.write('A.000168.68e9p9ca-a651-40f4-ad8f-3aaf781862b4.1\n'); + buffer.write(header); expect(() => HeaderSerializer.HeaderSerializer.deserialize(buffer)) - .throws('Header ID is missing or malformed.'); + .throws(`Header ID \'${ headerId }\' is missing or malformed.`); }); }); diff --git a/libraries/botframework-streaming/tests/RequestManager.test.js b/libraries/botframework-streaming/tests/RequestManager.test.js index 90d79aa4a7..83825ea816 100644 --- a/libraries/botframework-streaming/tests/RequestManager.test.js +++ b/libraries/botframework-streaming/tests/RequestManager.test.js @@ -21,7 +21,7 @@ describe('RequestManager', () => { rm.getResponse(requestId, undefined) .catch((reason) => expect(reason) .to - .equal('requestId already exists in RequestManager')); + .equal(`requestId \'${ requestId }\' already exists in RequestManager`)); }); From face819fe9f00e7ab2655ab6b3df6c735eccbcdb Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Tue, 15 Oct 2019 11:29:49 -0700 Subject: [PATCH 15/32] Streaming: add more validations and test fixes --- .../botbuilder/src/botFrameworkAdapter.ts | 8 ++++++ .../botFrameworkStreamingAdapter.test.js | 26 ++++++++++++------- .../tests/HeaderSerializer.test.js | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index c0911cb03a..0bed2539c0 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -967,7 +967,15 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * Override this in a derived class to create a mock connector client for unit testing. */ public createConnectorClient(serviceUrl: string): ConnectorClient { + if (TurnContext.isStreamingServiceUrl(serviceUrl)) { + + // Check if we have a streaming server. Otherwise, requesting a connector client + // for a non-existent streaming connection results in an error + if (!this.streamingServer) { + throw new Error(`Cannot create streaming connector client for serviceUrl ${serviceUrl} without a streaming connection. Call 'useWebSocket' or 'useNamedPipe' to start a streaming connection.`) + } + return new ConnectorClient( this.credentials, { diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 83b8609d12..ca3601b739 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -152,8 +152,17 @@ describe('BotFrameworkStreamingAdapter tests', () => { it('returns a connector client', () => { let bot = new ActivityHandler.ActivityHandler(); let handler = new Adapter.BotFrameworkAdapter(); - cc = handler.createConnectorClient('www.contoso.com'); - expect(cc.baseUri).to.equal('www.contoso.com'); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + let response = new TestResponse(); + + handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }).then(() => { + cc = handler.createConnectorClient('urn:test'); + expect(cc.baseUri).to.equal('urn:test'); + }); }); it('useWebSocket returns an error when request is not an upgrade request', () => { @@ -171,7 +180,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { expect(response.statusVal).to.equal(426); }); - it('useWebSocket returns status code 401 when request is not authorized', async () => { + it('useWebSocket returns status code 401 when request is not authorized', () => { let bot = new ActivityHandler.ActivityHandler(); let handler = new Adapter.BotFrameworkAdapter(new TestAdapterSettings('appId', 'password')); let request = new TestRequest(); @@ -179,14 +188,13 @@ describe('BotFrameworkStreamingAdapter tests', () => { request.setHeaders({channelid: 'fakechannel', authorization: 'donttrustme'}); let response = new TestResponse(); - await handler.useWebSocket(request, response, async (context) => { + handler.useWebSocket(request, response, async (context) => { // Route to bot await bot.run(context); - }).then(function(){ - return; - }); - expect(response.sendVal).to.equal(undefined); - expect(response.statusVal).to.equal(401); + }).then(() => { + expect(response.sendVal).to.equal(undefined); + expect(response.statusVal).to.equal(401); + }); }); it('useWebSocket connects', async () => { diff --git a/libraries/botframework-streaming/tests/HeaderSerializer.test.js b/libraries/botframework-streaming/tests/HeaderSerializer.test.js index 17d90b902a..247ba25714 100644 --- a/libraries/botframework-streaming/tests/HeaderSerializer.test.js +++ b/libraries/botframework-streaming/tests/HeaderSerializer.test.js @@ -109,7 +109,7 @@ describe('HeaderSerializer', () => { it('throws if the header ID is malformed', () => { // expect.assertions(1); - const headerId = 'A.000168.68e9p9ca-a651-40f4-ad8f-3aaf781862b4.1\n'; + const headerId = '68e9p9ca-a651-40f4-ad8f-3aaf781862b4'; const header = `A.000168.${ headerId }.1\n`; let buffer = Buffer.alloc(Number(PayloadConstants.PayloadConstants.MaxHeaderLength)); From 7294321660c064fffb77d76ab6dfee8fa08dc86b Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Tue, 15 Oct 2019 12:40:02 -0700 Subject: [PATCH 16/32] Streaming: remove obsolete package from lerna.json and fix documentation refs --- lerna.json | 1 - .../src/namedPipe/namedPipeClient.ts | 8 ++++---- .../src/namedPipe/namedPipeServer.ts | 8 ++++---- .../src/namedPipe/namedPipeTransport.ts | 2 +- .../src/payloadTransport/payloadReceiver.ts | 2 +- libraries/botframework-streaming/src/requestHandler.ts | 2 +- .../src/webSocket/browserWebSocket.ts | 2 +- .../botframework-streaming/src/webSocket/nodeWebSocket.ts | 2 +- .../src/webSocket/webSocketClient.ts | 4 ++-- .../src/webSocket/webSocketServer.ts | 4 ++-- .../src/webSocket/webSocketTransport.ts | 2 +- 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lerna.json b/lerna.json index 990d50ae59..1bac614368 100644 --- a/lerna.json +++ b/lerna.json @@ -14,7 +14,6 @@ "libraries/functional-tests", "libraries/testbot", "libraries/botframework-streaming", - "libraries/botbuilder-streaming-extensions", "transcripts" ], "version": "independent", diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts index 396551affe..90651f9b0f 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts @@ -31,10 +31,10 @@ export class NamedPipeClient implements IStreamingTransportClient { private _isDisconnecting: boolean; /** - * Creates a new instance of the [NamedPipeClient](xref:botbuilder-streaming.NamedPipeClient) class. + * Creates a new instance of the [NamedPipeClient](xref:botframework-streaming.NamedPipeClient) class. * * @param baseName The named pipe to connect to. - * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this client. + * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this client. * @param autoReconnect Optional setting to determine if the client sould attempt to reconnect automatically on disconnection events. Defaults to true. */ public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { @@ -72,8 +72,8 @@ export class NamedPipeClient implements IStreamingTransportClient { /** * Task used to send data over this client connection. * - * @param request The [StreamingRequest](xref:botbuilder-streaming.StreamingRequest) to send. - * @returns A promise for an instance of [IReceiveResponse](xref:botbuilder-streaming.IReceiveResponse) on completion of the send operation. + * @param request The [StreamingRequest](xref:botframework-streaming.StreamingRequest) to send. + * @returns A promise for an instance of [IReceiveResponse](xref:botframework-streaming.IReceiveResponse) on completion of the send operation. */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts index 467cba8acb..95bddb92b5 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts @@ -33,10 +33,10 @@ export class NamedPipeServer implements IStreamingTransportServer { private _isDisconnecting: boolean; /** - * Creates a new instance of the [NamedPipeServer](xref:botbuilder-streaming.NamedPipeServer) class. + * Creates a new instance of the [NamedPipeServer](xref:botframework-streaming.NamedPipeServer) class. * * @param baseName The named pipe to connect to. - * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this client. + * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this client. * @param autoReconnect Optional setting to determine if the client sould attempt to reconnect automatically on disconnection events. Defaults to true. */ public constructor(baseName: string, requestHandler?: RequestHandler, autoReconnect: boolean = true) { @@ -112,8 +112,8 @@ export class NamedPipeServer implements IStreamingTransportServer { /** * Task used to send data over this client connection. * - * @param request The [StreamingRequest](xref:botbuilder-streaming.StreamingRequest) to send. - * @returns A promise for an instance of [IReceiveResponse](xref:botbuilder-streaming.IReceiveResponse) on completion of the send operation. + * @param request The [StreamingRequest](xref:botframework-streaming.StreamingRequest) to send. + * @returns A promise for an instance of [IReceiveResponse](xref:botframework-streaming.IReceiveResponse) on completion of the send operation. */ public async send(request: StreamingRequest): Promise { return this._protocolAdapter.sendRequest(request); diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts index 444f999db9..1941334ee8 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts @@ -27,7 +27,7 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver private _activeReceiveCount: number; /** - * Creates a new instance of the [NamedPipeTransport](xref:botbuilder-streaming.NamedPipeTransport) class. + * Creates a new instance of the [NamedPipeTransport](xref:botframework-streaming.NamedPipeTransport) class. * * @param socket The socket object to build this connection on. */ diff --git a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts index a187eb1389..41272187c2 100644 --- a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts @@ -29,7 +29,7 @@ export class PayloadReceiver { /** * Connects to a transport receiver * - * @param receiver The [ITransportReceiver](xref:botbuilder-streaming.ITransportReceiver) object to pull incoming data from. + * @param receiver The [ITransportReceiver](xref:botframework-streaming.ITransportReceiver) object to pull incoming data from. */ public connect(receiver: ITransportReceiver): void { if (this.isConnected) { diff --git a/libraries/botframework-streaming/src/requestHandler.ts b/libraries/botframework-streaming/src/requestHandler.ts index fba32ce5f6..537a3f427d 100644 --- a/libraries/botframework-streaming/src/requestHandler.ts +++ b/libraries/botframework-streaming/src/requestHandler.ts @@ -9,7 +9,7 @@ import { IReceiveRequest } from './Interfaces/IReceiveRequest'; import { StreamingResponse } from './streamingResponse'; /** - * Implemented by classes used to process incoming streaming requests sent over an [IStreamingTransport](xref:botbuilder-streaming.IStreamingTransport). + * Implemented by classes used to process incoming streaming requests sent over an [IStreamingTransport](xref:botframework-streaming.IStreamingTransport). */ export abstract class RequestHandler { diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index 691f7519d9..b7e16041ce 100644 --- a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts @@ -11,7 +11,7 @@ export class BrowserWebSocket implements ISocket { private webSocket: WebSocket; /** - * Creates a new instance of the [BrowserWebSocket](xref:botbuilder-streaming.BrowserWebSocket) class. + * Creates a new instance of the [BrowserWebSocket](xref:botframework-streaming.BrowserWebSocket) class. * * @param socket The socket object to build this connection on. */ diff --git a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts index 6e9c525634..4e8e5f9519 100644 --- a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts @@ -14,7 +14,7 @@ export class NodeWebSocket implements ISocket { private connected: boolean; /** - * Creates a new instance of the [NodeWebSocket](xref:botbuilder-streaming.NodeWebSocket) class. + * Creates a new instance of the [NodeWebSocket](xref:botframework-streaming.NodeWebSocket) class. * * @param socket The WaterShed socket object to build this connection on. */ diff --git a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts index 5f5475e862..aa8b34f349 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketClient.ts @@ -32,10 +32,10 @@ export class WebSocketClient implements IStreamingTransportClient { private readonly _disconnectionHandler: (message: string) => void; /** - * Creates a new instance of the [WebSocketClient](xref:botbuilder-streaming.WebSocketClient) class. + * Creates a new instance of the [WebSocketClient](xref:botframework-streaming.WebSocketClient) class. * * @param url The URL of the remote server to connect to. - * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this server. + * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this server. * @param disconnectionHandler Optional function to handle the disconnection message. */ public constructor({ url, requestHandler, disconnectionHandler = null}) { diff --git a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts index cb246d1a4c..fb46764630 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts @@ -32,10 +32,10 @@ export class WebSocketServer implements IStreamingTransportServer { private _closedSignal; /** - * Creates a new instance of the [WebSocketServer](xref:botbuilder-streaming.WebSocketServer) class. + * Creates a new instance of the [WebSocketServer](xref:botframework-streaming.WebSocketServer) class. * * @param socket The underlying web socket. - * @param requestHandler Optional [RequestHandler](xref:botbuilder-streaming.RequestHandler) to process incoming messages received by this server. + * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this server. */ public constructor(socket: ISocket, requestHandler?: RequestHandler) { this._webSocketTransport = new WebSocketTransport(socket); diff --git a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts index 69a8b91e2d..a0652637ea 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts @@ -22,7 +22,7 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver private _activeReceiveCount: number; /** - * Creates a new instance of the [WebSocketTransport](xref:botbuilder-streaming.WebSocketTransport) class. + * Creates a new instance of the [WebSocketTransport](xref:botframework-streaming.WebSocketTransport) class. * * @param ws The ISocket to build this transport on top of. */ From 8de0e198de80e67b3f020fe839eff9821d9f3413 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 15 Oct 2019 22:50:02 -0700 Subject: [PATCH 17/32] Hide WebSocket connection behind ProcessActivity --- .../botbuilder/src/botFrameworkAdapter.ts | 113 ++++++++++-------- 1 file changed, 61 insertions(+), 52 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 0bed2539c0..052125b99c 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -122,6 +122,11 @@ export interface BotFrameworkAdapterSettings { * Optional. The channel service option for this bot to validate connections from Azure or other channel locations. */ channelService?: string; + + /** + * Optional. The option to determine if this adapter accepts WebSocket connections + */ + enableWebSockets?: boolean; } /** @@ -199,7 +204,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide private readonly credentialsProvider: SimpleCredentialProvider; private readonly settings: BotFrameworkAdapterSettings; - private streamingLogic: (context: TurnContext) => Promise; + private logic: (context: TurnContext) => Promise; private streamingServer: IStreamingTransportServer; private isEmulatingOAuthCards: boolean; @@ -718,6 +723,10 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > without using the `await` keyword. Make sure all async functions use await! */ public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { + if ((req as Request).isUpgradeRequest()) { + return this.useWebSocket(req as Request, res as ServerUpgradeResponse, logic); + } + let body: any; let status: number; let processError: Error; @@ -908,56 +917,6 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide ); } - /** - * Process the initial request to establish a long lived connection via a streaming server. - * @param req The connection request. - * @param res The response sent on error or connection termination. - * @param res The logic that will handle incoming requests. - */ - public async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { - if (!req.isUpgradeRequest()) { - let e = new Error('Upgrade to WebSockets required.'); - res.status(StatusCodes.UPGRADE_REQUIRED); - res.send(e.message); - - return Promise.resolve(); - } - - if (!logic) { - throw new Error('Streaming logic needs to be provided to `useWebSocket`'); - } - - this.streamingLogic = logic; - - const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); - if (!authenticated) { - res.status(StatusCodes.UNAUTHORIZED); - return Promise.resolve(); - } - - const upgrade = res.claimUpgrade(); - const ws = new Watershed(); - const socket = ws.accept(req, upgrade.socket, upgrade.head); - - await this.startWebSocket(new NodeWebSocket(socket)); - } - - /** - * Connects the handler to a Named Pipe server and begins listening for incoming requests. - * @param pipeName The name of the named pipe to use when creating the server. - * @param logic The logic that will handle incoming requests. - */ - public async useNamedPipe(pipeName: string = defaultPipeName, logic: (context: TurnContext) => Promise): Promise{ - if (!logic) { - throw new Error('Bot logic needs to be provided to `useNamedPipe`'); - } - - this.streamingLogic = logic; - - this.streamingServer = new NamedPipeServer(pipeName, this); - await this.streamingServer.start(); - } - /** * Creates a connector client. * @@ -1042,7 +1001,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide try { let context = new TurnContext(this, body); await this.runMiddleware(context, async (turnContext): Promise => { - await this.streamingLogic(context); + await this.logic(context); }); if (body.type === ActivityTypes.Invoke) { @@ -1156,6 +1115,56 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return claims.isAuthenticated; } + /** + * Connects the handler to a Named Pipe server and begins listening for incoming requests. + * @param pipeName The name of the named pipe to use when creating the server. + * @param logic The logic that will handle incoming requests. + */ + private async useNamedPipe(pipeName: string = defaultPipeName, logic: (context: TurnContext) => Promise): Promise{ + if (!logic) { + throw new Error('Bot logic needs to be provided to `useNamedPipe`'); + } + + this.logic = logic; + + this.streamingServer = new NamedPipeServer(pipeName, this); + await this.streamingServer.start(); + } + + /** + * Process the initial request to establish a long lived connection via a streaming server. + * @param req The connection request. + * @param res The response sent on error or connection termination. + * @param res The logic that will handle incoming requests. + */ + private async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { + if (!req.isUpgradeRequest()) { + let e = new Error('Upgrade to WebSockets required.'); + res.status(StatusCodes.UPGRADE_REQUIRED); + res.send(e.message); + + return Promise.resolve(); + } + + if (!logic) { + throw new Error('Streaming logic needs to be provided to `useWebSocket`'); + } + + this.logic = logic; + + const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); + if (!authenticated) { + res.status(StatusCodes.UNAUTHORIZED); + return Promise.resolve(); + } + + const upgrade = res.claimUpgrade(); + const ws = new Watershed(); + const socket = ws.accept(req, upgrade.socket, upgrade.head); + + await this.startWebSocket(new NodeWebSocket(socket)); + } + /** * Connects the handler to a WebSocket server and begins listening for incoming requests. * @param socket The socket to use when creating the server. From b00477564b9a380fa46bf08f87babacbcde41279 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 15 Oct 2019 23:11:25 -0700 Subject: [PATCH 18/32] Change ProcessActivity to accept Union Types and introduce Type Guard to determine if a Request has been passed in. --- libraries/botbuilder/src/botFrameworkAdapter.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 052125b99c..0d223b8666 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -722,9 +722,9 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > in your bot's console output, the likely cause is that an async function was used * > without using the `await` keyword. Make sure all async functions use await! */ - public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { - if ((req as Request).isUpgradeRequest()) { - return this.useWebSocket(req as Request, res as ServerUpgradeResponse, logic); + public async processActivity(req: WebRequest|Request, res: WebResponse|ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { + if (this.isARequest(req) && (req).isUpgradeRequest()) { + return this.useWebSocket(req, res as ServerUpgradeResponse, logic); } let body: any; @@ -1115,6 +1115,10 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return claims.isAuthenticated; } + private isARequest(target: any): target is Request { + return 'isUpgradeRequest' in target; + } + /** * Connects the handler to a Named Pipe server and begins listening for incoming requests. * @param pipeName The name of the named pipe to use when creating the server. From 74343b5666cc5c575a6d762249de00e4df836918 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 15 Oct 2019 23:18:31 -0700 Subject: [PATCH 19/32] Better name. Maybe. --- libraries/botbuilder/src/botFrameworkAdapter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 0d223b8666..141b8d171b 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -723,7 +723,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > without using the `await` keyword. Make sure all async functions use await! */ public async processActivity(req: WebRequest|Request, res: WebResponse|ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { - if (this.isARequest(req) && (req).isUpgradeRequest()) { + if (this.isUpgradeRequest(req) && (req).isUpgradeRequest()) { return this.useWebSocket(req, res as ServerUpgradeResponse, logic); } @@ -1115,7 +1115,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return claims.isAuthenticated; } - private isARequest(target: any): target is Request { + private isUpgradeRequest(target: any): target is Request { return 'isUpgradeRequest' in target; } From dcc185739cf37f292c1f8a3289aebcbc652faedf Mon Sep 17 00:00:00 2001 From: Carlos Castro Date: Wed, 16 Oct 2019 15:31:04 -0700 Subject: [PATCH 20/32] Streaming: remove isFromStreamingConnection out of TurnContext since it will need to be there forever. duplicating for now. We'll unify in 4.7 along with other refactors --- libraries/botbuilder-core/src/turnContext.ts | 22 ---------------- .../src/prompts/oauthPrompt.ts | 8 +++++- .../botbuilder/src/botFrameworkAdapter.ts | 26 +++++++++++++++++-- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index fcf48b84a9..4592711b8b 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -538,26 +538,4 @@ export class TurnContext { return emitNext(0); } - - /** - * Determine if the Activity was sent via an Http/Https connection or Streaming - * This can be determined by looking at the ServiceUrl property: - * (1) All channels that send messages via http/https are not streaming - * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. - * @param activity the activity. - */ - public static isFromStreamingConnection(activity: Activity): boolean { - return activity && this.isStreamingServiceUrl(activity.serviceUrl); - } - - /** - * Determine if the serviceUrl was sent via an Http/Https connection or Streaming - * This can be determined by looking at the ServiceUrl property: - * (1) All channels that send messages via http/https are not streaming - * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. - * @param serviceUrl the serviceUrl provided in the resquest. - */ - public static isStreamingServiceUrl(serviceUrl: string): boolean { - return serviceUrl && !serviceUrl.toLowerCase().startsWith('http'); - } } diff --git a/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts b/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts index 7253855e52..fd9b3a267e 100644 --- a/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts +++ b/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts @@ -250,7 +250,7 @@ export class OAuthPrompt extends Dialog { const cards: Attachment[] = msg.attachments.filter((a: Attachment) => a.contentType === CardFactory.contentTypes.oauthCard); if (cards.length === 0) { let link: string = undefined; - if (TurnContext.isFromStreamingConnection(context.activity)) { + if (OAuthPrompt.isFromStreamingConnection(context.activity)) { link = await (context.adapter as any).getSignInLink(context, this.settings.connectionName); } // Append oauth card @@ -312,12 +312,18 @@ export class OAuthPrompt extends Dialog { return token !== undefined ? { succeeded: true, value: token } : { succeeded: false }; } + private static isFromStreamingConnection(activity: Activity): boolean { + return activity && activity.serviceUrl && !activity.serviceUrl.toLowerCase().startsWith('http'); + } + private isTokenResponseEvent(context: TurnContext): boolean { const activity: Activity = context.activity; return activity.type === ActivityTypes.Event && activity.name === 'tokens/response'; } + + private isTeamsVerificationInvoke(context: TurnContext): boolean { const activity: Activity = context.activity; diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 0bed2539c0..4f93e16207 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -855,7 +855,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide if (!activity.conversation || !activity.conversation.id) { throw new Error(`BotFrameworkAdapter.sendActivity(): missing conversation id.`); } - if (TurnContext.isFromStreamingConnection(activity as Activity)) { + if (BotFrameworkAdapter.isFromStreamingConnection(activity as Activity)) { TokenResolver.checkForOAuthCards(this, context, activity as Activity); } const client: ConnectorClient = this.createConnectorClient(activity.serviceUrl); @@ -968,7 +968,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide */ public createConnectorClient(serviceUrl: string): ConnectorClient { - if (TurnContext.isStreamingServiceUrl(serviceUrl)) { + if (BotFrameworkAdapter.isStreamingServiceUrl(serviceUrl)) { // Check if we have a streaming server. Otherwise, requesting a connector client // for a non-existent streaming connection results in an error @@ -1141,6 +1141,28 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return new TurnContext(this as any, request); } + /** + * Determine if the Activity was sent via an Http/Https connection or Streaming + * This can be determined by looking at the ServiceUrl property: + * (1) All channels that send messages via http/https are not streaming + * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. + * @param activity the activity. + */ + private static isFromStreamingConnection(activity: Activity): boolean { + return activity && this.isStreamingServiceUrl(activity.serviceUrl); + } + + /** + * Determine if the serviceUrl was sent via an Http/Https connection or Streaming + * This can be determined by looking at the ServiceUrl property: + * (1) All channels that send messages via http/https are not streaming + * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https. + * @param serviceUrl the serviceUrl provided in the resquest. + */ + private static isStreamingServiceUrl(serviceUrl: string): boolean { + return serviceUrl && !serviceUrl.toLowerCase().startsWith('http'); + } + private async authenticateConnection(req: WebRequest, appId?: string, appPassword?: string, channelService?: string): Promise { if (!appId || !appPassword) { // auth is disabled From 6fef4573d1e2e957f7aa0b7908c82b9364ac4552 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 16:22:21 -0700 Subject: [PATCH 21/32] Import directly from library instead of third hand --- libraries/botbuilder/src/streamingHttpClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/streamingHttpClient.ts b/libraries/botbuilder/src/streamingHttpClient.ts index 636a4eddd5..132dbb1131 100644 --- a/libraries/botbuilder/src/streamingHttpClient.ts +++ b/libraries/botbuilder/src/streamingHttpClient.ts @@ -7,7 +7,7 @@ */ import { IStreamingTransportServer, StreamingRequest } from 'botframework-streaming'; -import { WebResource, HttpOperationResponse, HttpClient } from 'botframework-connector/node_modules/@azure/ms-rest-js'; +import { WebResource, HttpOperationResponse, HttpClient } from '@azure/ms-rest-js'; export class StreamingHttpClient implements HttpClient { private readonly server: IStreamingTransportServer; From 4867dfef3f34ac1d213528df27e2e708345fd26d Mon Sep 17 00:00:00 2001 From: stgum <14935595+stevengum@users.noreply.github.com> Date: Wed, 16 Oct 2019 18:11:09 -0700 Subject: [PATCH 22/32] fix WebSocketServer.onConnectionDisconnected, fix in StreamingAdapter tests --- .../botbuilder/src/botFrameworkAdapter.ts | 2 +- .../botFrameworkStreamingAdapter.test.js | 673 +++++++++--------- .../src/payloadTransport/payloadReceiver.ts | 2 +- .../src/webSocket/webSocketServer.ts | 15 +- 4 files changed, 342 insertions(+), 350 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index c39f0a9a5b..1c02f56a52 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1161,7 +1161,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * Process the initial request to establish a long lived connection via a streaming server. * @param req The connection request. * @param res The response sent on error or connection termination. - * @param res The logic that will handle incoming requests. + * @param logic The logic that will handle incoming requests. */ private async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { if (!req.isUpgradeRequest()) { diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index ca3601b739..13aa55f744 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -1,107 +1,102 @@ -const Adapter = require('../lib/botFrameworkAdapter'); -const ActivityHandler = require("botbuilder-core"); -const chai = require('chai'); +const { BotFrameworkAdapter, StatusCodes } = require('../'); +const { ActivityHandler } = require('botbuilder-core'); +const chai = require('chai'); var expect = chai.expect; -class FauxSock{ - constructor(contentString){ - if(contentString){ +class FauxSock { + constructor(contentString) { + if (contentString) { this.contentString = contentString; this.position = 0; } this.connected = true; } - isConnected(){ return this.connected; } - write(buffer){ return ; } - connect(serverAddress){ return new Promise(); } - close(){ this.connected = false; return; } - setOnMessageHandler(handler){ return; } //(x: any) => void); - setOnErrorHandler(handler){ return; } - setOnCloseHandler(handler){ return; } + isConnected() { return this.connected; } + write(buffer) { return; } + connect(serverAddress) { return new Promise(); } + close() { this.connected = false; return; } + setOnMessageHandler(handler) { return; } //(x: any) => void); + setOnErrorHandler(handler) { return; } + setOnCloseHandler(handler) { return; } } class TestRequest { - constructor(){ + constructor() { let headers = []; } - isUpgradeRequest(){ + isUpgradeRequest() { return this.upgradeRequestVal; } - setIsUpgradeRequest(value){ + setIsUpgradeRequest(value) { this.upgradeRequestVal = value; } - status(){ + status() { return this.statusVal; } - status(value){ + status(value) { this.statusVal = value; } - path(value){ + path(value) { this.pathVal = value; } - path(){ + path() { return this.pathVal; } - verb(value){ + verb(value) { this.verbVal = value; } - - verb(){ + + verb() { return this.verbVal; } - streams(value){ + streams(value) { this.streamsVal = value; } - streams(){ + streams() { return this.streamsVal; } - setHeaders(){ + setHeaders() { return this.headersVal; } - setHeaders(value){ + setHeaders(value) { this.headers = value; } - + } class TestResponse { - - construtor(){ - } - - send(value){ + send(value) { this.sendVal = value; return this.sendVal; } - status(value){ + status(value) { this.statusVal = value; return this.statusVal; } - setClaimUpgrade(value) - { + setClaimUpgrade(value) { this.claimUpgradeVal = value; } - claimUpgrade(){ + claimUpgrade() { return this.claimUpgradeVal; } } class TestAdapterSettings { - constructor(appId = undefined, appPassword = undefined, channelAuthTenant, oAuthEndpoint, openIdMetadata, channelServce){ + constructor(appId = undefined, appPassword = undefined, channelAuthTenant, oAuthEndpoint, openIdMetadata, channelServce) { this.appId = appId; this.appPassword = appPassword; } @@ -110,24 +105,24 @@ class TestAdapterSettings { describe('BotFrameworkStreamingAdapter tests', () => { it('has the correct status codes', () => { - expect(Adapter.StatusCodes.OK).to.equal(200); - expect(Adapter.StatusCodes.BAD_REQUEST).to.equal(400); - expect(Adapter.StatusCodes.UNAUTHORIZED).to.equal(401); - expect(Adapter.StatusCodes.NOT_FOUND).to.equal(404); - expect(Adapter.StatusCodes.METHOD_NOT_ALLOWED).to.equal(405); - expect(Adapter.StatusCodes.UPGRADE_REQUIRED).to.equal(426); - expect(Adapter.StatusCodes.INTERNAL_SERVER_ERROR).to.equal(500); - expect(Adapter.StatusCodes.NOT_IMPLEMENTED).to.equal(501); + expect(StatusCodes.OK).to.equal(200); + expect(StatusCodes.BAD_REQUEST).to.equal(400); + expect(StatusCodes.UNAUTHORIZED).to.equal(401); + expect(StatusCodes.NOT_FOUND).to.equal(404); + expect(StatusCodes.METHOD_NOT_ALLOWED).to.equal(405); + expect(StatusCodes.UPGRADE_REQUIRED).to.equal(426); + expect(StatusCodes.INTERNAL_SERVER_ERROR).to.equal(500); + expect(StatusCodes.NOT_IMPLEMENTED).to.equal(501); }); it('gets constructed properly', () => { - let handler = new Adapter.BotFrameworkAdapter(); + let handler = new BotFrameworkAdapter(); - expect(handler).to.be.instanceOf(Adapter.BotFrameworkAdapter); + expect(handler).to.be.instanceOf(BotFrameworkAdapter); }); it('starts and stops a namedpipe server', () => { - let handler = new Adapter.BotFrameworkAdapter(); + let handler = new BotFrameworkAdapter(); handler.useNamedPipe('PipeyMcPipeface', async (context) => { // Route to bot @@ -136,268 +131,312 @@ describe('BotFrameworkStreamingAdapter tests', () => { expect(handler.streamingServer.disconnect()).to.not.throw; }); - it('starts and stops a websocket server', (done) => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); + it('starts and stops a websocket server', () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); let request = new TestRequest(); - let response = new TestResponse({claimUpgrade:'anything'}); + let response = new TestResponse({ claimUpgrade: 'anything' }); expect(handler.useWebSocket(request, response, async (context) => { // Route to bot await bot.run(context); })).to.not.throw; - done(); - }); - - it('returns a connector client', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); - let response = new TestResponse(); - - handler.useWebSocket(request, response, async (context) => { - // Route to bot - await bot.run(context); - }).then(() => { - cc = handler.createConnectorClient('urn:test'); - expect(cc.baseUri).to.equal('urn:test'); - }); }); - it('useWebSocket returns an error when request is not an upgrade request', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.setIsUpgradeRequest(false); - let response = new TestResponse(); - - handler.useWebSocket(request, response, async (context) => { - // Route incoming streaming requests to bot - await bot.run(context); - }).catch(); - expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); - expect(response.statusVal).to.equal(426); - }); - - it('useWebSocket returns status code 401 when request is not authorized', () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(new TestAdapterSettings('appId', 'password')); + it('returns a connector client', async () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); let request = new TestRequest(); request.setIsUpgradeRequest(true); - request.setHeaders({channelid: 'fakechannel', authorization: 'donttrustme'}); - let response = new TestResponse(); - - handler.useWebSocket(request, response, async (context) => { - // Route to bot - await bot.run(context); - }).then(() => { - expect(response.sendVal).to.equal(undefined); - expect(response.statusVal).to.equal(401); - }); - }); - - it('useWebSocket connects', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); request.headers = []; request.headers['upgrade'] = 'websocket'; request.headers['sec-websocket-key'] = 'BFlat'; request.headers['sec-websocket-version'] = '13'; request.headers['sec-websocket-protocol'] = ''; let response = new TestResponse(); - let fakeSocket = { - unshift: function(){return true;}, - write: function(value){console.log(value);}, - on: function(value){console.log(value);}, - read: function(){return new Buffer('data', 'utf8');}, - end: function(){return;}, + let fakeSocket = { + unshift: function () { return true; }, + write: function (value) { }, + on: function (value) { }, + read: function () { return new Buffer.from('data', 'utf8'); }, + end: function () { return; }, }; - response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); + response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); await handler.useWebSocket(request, response, async (context) => { // Route to bot await bot.run(context); - }).then(function(){ - return; - }); + }); + const cc = handler.createConnectorClient('urn:test'); + expect(cc.baseUri).to.equal('urn:test'); }); - it('returns a 400 when the request is missing verb', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = undefined; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + describe('useWebSocket()', () => { + it('connects', async () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + request.headers = []; + request.headers['upgrade'] = 'websocket'; + request.headers['sec-websocket-key'] = 'BFlat'; + request.headers['sec-websocket-version'] = '13'; + request.headers['sec-websocket-protocol'] = ''; + let response = new TestResponse(); + let fakeSocket = { + unshift: function () { return true; }, + write: function (value) { }, + on: function (value) { }, + read: function () { return new Buffer.from('data', 'utf8'); }, + end: function () { return; }, + }; + response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); + + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }); + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); - }); + it('returns an error when request is not an upgrade request', async () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.setIsUpgradeRequest(false); + let response = new TestResponse(); - it('returns a 400 when the request is missing path', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = undefined; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + await handler.useWebSocket(request, response, async (context) => { + // Route incoming streaming requests to bot + await bot.run(context); + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); - }); + expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); + expect(response.statusVal).to.equal(426); + }); - it('returns a 400 when the request body is missing', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest( 'POST', '/api/messages'); - request.verb = 'POST'; - request.path = '/api/messages'; - request.streams = undefined; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(400); - }); + it('returns status code 401 when request is not authorized', async () => { + let bot = new ActivityHandler(); + const settings = new TestAdapterSettings('appId', 'password'); + let handler = new BotFrameworkAdapter(settings); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); + request.setHeaders({ channelid: 'fakechannel', authorization: 'donttrustme' }); + let response = new TestResponse(); + + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + throw new Error('useWebSocket should have thrown an error'); + }).catch(err => { + expect(err.message).to.equal('Unauthorized. Is not authenticated'); + }); + }); }); - it('returns user agent information when a GET hits the version endpoint', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'GET'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + describe('processRequest()', () => { + it('returns a 400 when the request is missing verb', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = undefined; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(400); + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - }); + it('returns a 400 when the request is missing path', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = undefined; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(400); + }); - it('returns user agent information from cache when a GET hits the version endpoint more than once', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'GET'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - expect(response.streams[0].content).to.not.be.undefined; - }); - }); + it('returns a 400 when the request body is missing', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest('POST', '/api/messages'); + request.verb = 'POST'; + request.path = '/api/messages'; + request.streams = undefined; - it('returns 405 for unsupported methods', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'UPDATE'; - request.path = '/api/version'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(400); + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(405); - }); - }); + it('returns user agent information when a GET hits the version endpoint', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'GET'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(200); + expect(response.streams[0].content).to.not.be.undefined; + }); - it('returns 404 for unsupported paths', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/supersecretbackdoor'; - let fakeStream = { - readAsJson: function(){ return {type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + it('returns user agent information from cache when a GET hits the version endpoint more than once', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'GET'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(200); + expect(response.streams[0].content).to.not.be.undefined; + + const response2 = await handler.processRequest(request); + expect(response2.statusCode).to.equal(200); + expect(response2.streams[0].content).to.not.be.undefined; + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(404); - }); - }); + it('returns 405 for unsupported methods', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'UPDATE'; + request.path = '/api/version'; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(405); + }); - it('processes a well formed request when there is no middleware with a non-Invoke activity type', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'something', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + it('returns 404 for unsupported paths', async () => { + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/supersecretbackdoor'; + let fakeStream = { + readAsJson: function () { return { type: 'Invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(404); + }); - handler.streamingLogic = async (context) => { - // Route to bot - await bot.run(context); - }; + it('processes a well formed request when there is no middleware with a non-Invoke activity type', async () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function () { return { type: 'something', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + handler.logic = async (context) => { + // Route to bot + await bot.run(context); + }; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(200); + }); - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(200); - }); - }); + it('returns a 501 when activity type is invoke, but the activity is invalid', async () => { + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function () { return { type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + handler.logic = async (context) => { + // Route to bot + await bot.run(context); + }; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(501); + }); - it('returns a 501 when activity type is invoke, but the activity is invalid', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; + it('returns a 500 when bot can not run', async () => { + const MiddleWare = require('botbuilder-core'); + let bot = {}; + let mw = { + async onTurn(context, next) { + console.log('Middleware executed!'); + await next(); + } + }; + let mwset = []; + mwset.push(mw); + let handler = new BotFrameworkAdapter({ bot: bot, middleWare: mwset }); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function () { return { type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(500); + }); - handler.streamingLogic = async (context) => { - // Route to bot - await bot.run(context); - }; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(501); - }); + it('executes middleware', async () => { + var sinon = require('sinon'); + let bot = new ActivityHandler(); + bot.run = function (turnContext) { return Promise.resolve(); }; + + + let mwset = []; + let handler = new BotFrameworkAdapter(); + handler.use(async (context, next) => { + console.log('Middleware executed!'); + return next(); + }); + + var spy = sinon.spy(bot, 'run'); + let request = new TestRequest(); + request.verb = 'POST'; + request.path = '/api/messages'; + let fakeStream = { + readAsJson: function () { return { type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test' }; }, + }; + request.streams[0] = fakeStream; + + handler.logic = async (context) => { + // Route to bot + await bot.run(context); + }; + + const response = await handler.processRequest(request); + expect(response.statusCode).to.equal(501); + expect(spy.called).to.be.true; + }); }); it('sends a request', async () => { - let bot = new ActivityHandler.ActivityHandler(); - let handler = new Adapter.BotFrameworkAdapter(); - let request = new TestRequest(); - request.setIsUpgradeRequest(true); + let bot = new ActivityHandler(); + let handler = new BotFrameworkAdapter(); + let request = new TestRequest(); + request.setIsUpgradeRequest(true); request.headers = []; request.headers['upgrade'] = 'websocket'; request.headers['sec-websocket-key'] = 'BFlat'; @@ -405,85 +444,27 @@ describe('BotFrameworkStreamingAdapter tests', () => { request.headers['sec-websocket-protocol'] = ''; let response = new TestResponse(); let fakeSocket = { - unshift: function(){return true;}, - write: function(){return Promise.resolve; }, - on: function(){return;}, - read: function(){return new Buffer('data', 'utf8');}, - end: function(){return Promise.resolve;}, + unshift: function () { return true; }, + write: function () { return Promise.resolve; }, + on: function () { return; }, + read: function () { return new Buffer.from('data', 'utf8'); }, + end: function () { return Promise.resolve; }, }; - var sinon = require('sinon'); - var spy = sinon.spy(fakeSocket, "write"); - response.setClaimUpgrade( {socket: fakeSocket, head: 'websocket'} ); - - await handler.useWebSocket(request, response, async (context) => { - // Route to bot - await bot.run(context); - }).then(function(){ - return; - }); - + const sinon = require('sinon'); + const spy = sinon.spy(fakeSocket, "write"); + response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); + + try { + await handler.useWebSocket(request, response, async (context) => { + // Route to bot + await bot.run(context); + }) + } catch (err) { + throw err; + } + let connection = handler.createConnectorClient('fakeUrl'); - connection.sendRequest({method: 'POST', url: 'testResultDotCom', body: 'Test body!'}); + connection.sendRequest({ method: 'POST', url: 'testResultDotCom', body: 'Test body!' }); expect(spy.called).to.be.true; }).timeout(2000); - - it('returns a 500 when bot can not run', async () => { - const MiddleWare = require('botbuilder-core'); - let bot = {}; - let mw = { - async onTurn(context, next) - { - console.log('Middleware executed!'); - await next(); - }}; - let mwset = []; - mwset.push(mw); - let handler = new Adapter.BotFrameworkAdapter({ bot: bot, middleWare: mwset}); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(500); - }); - }); - - it('executes middleware', async () => { - var sinon = require('sinon'); - let bot = new ActivityHandler.ActivityHandler(); - bot.run = function(turnContext){return Promise.resolve();}; - - - let mwset = []; - let handler = new Adapter.BotFrameworkAdapter(); - handler.use(async(context, next) => { - console.log('Middleware executed!'); - return next(); - }); - - var spy = sinon.spy(bot, 'run'); - let request = new TestRequest(); - request.verb = 'POST'; - request.path = '/api/messages'; - let fakeStream = { - readAsJson: function(){ return {type: 'invoke', serviceUrl: 'somewhere/', channelId: 'test'};}, - }; - request.streams[0] = fakeStream; - - handler.streamingLogic = async (context) => { - // Route to bot - await bot.run(context); - }; - - await handler.processRequest(request).then( - function(response) { - expect(response.statusCode).to.equal(501); - expect(spy.called).to.be.true; - }); - }); -}); \ No newline at end of file +}); diff --git a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts index 41272187c2..50eb5b28e1 100644 --- a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts @@ -67,7 +67,7 @@ export class PayloadReceiver { } } catch (error) { this.isConnected = false; - this.disconnected(error.message, e); + this.disconnected(this, new TransportDisconnectedEventArgs(error.message)); } this._receiver = null; this.isConnected = false; diff --git a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts index fb46764630..b8e83c87ff 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts @@ -83,7 +83,18 @@ export class WebSocketServer implements IStreamingTransportServer { this._receiver.disconnect(new TransportDisconnectedEventArgs('Disconnect was called.')); } - private onConnectionDisconnected(s: WebSocketServer, sender: object, args: any): void { - s._closedSignal('close'); + private onConnectionDisconnected(sender: PayloadReceiver | PayloadSender, e?: TransportDisconnectedEventArgs): void { + if (this._closedSignal) { + this._closedSignal('close'); + this._closedSignal = null; + } + + if (sender === this._sender) { + this._receiver.disconnect(e); + } + + if (sender === this._receiver) { + this._sender.disconnect(e); + } } } From 7ae544ca3ef0b5d1c2c63df6c7a37d5d4d793e6b Mon Sep 17 00:00:00 2001 From: stgum <14935595+stevengum@users.noreply.github.com> Date: Wed, 16 Oct 2019 18:16:50 -0700 Subject: [PATCH 23/32] move isFromStreamingConnection() tests to BFStreamingAdapter tests --- .../botbuilder-core/tests/turnContext.test.js | 44 +------------------ .../botFrameworkStreamingAdapter.test.js | 42 ++++++++++++++++++ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/libraries/botbuilder-core/tests/turnContext.test.js b/libraries/botbuilder-core/tests/turnContext.test.js index 1f27f9cc35..13368088d5 100644 --- a/libraries/botbuilder-core/tests/turnContext.test.js +++ b/libraries/botbuilder-core/tests/turnContext.test.js @@ -394,46 +394,4 @@ describe(`TurnContext`, function () { assert(text,' test activity'); assert(activity.text,' test activity'); }); - - it ('should identify streaming connections', function() { - let activity = { - type: 'message', - text: 'TestOAuth619 test activity', - recipient: { id: 'TestOAuth619' }, - }; - - const streaming = [ - 'urn:botframework:WebSocket:wss://beep.com', - 'urn:botframework:WebSocket:http://beep.com', - 'URN:botframework:WebSocket:wss://beep.com', - 'URN:botframework:WebSocket:http://beep.com', - ]; - - streaming.forEach(s => - { - activity.serviceUrl = s; - assert(TurnContext.isFromStreamingConnection(activity), 'did not detect streaming'); - }); - }); - - it ('should identify http connections', function() { - let activity = { - type: 'message', - text: 'TestOAuth619 test activity', - recipient: { id: 'TestOAuth619' }, - }; - - const streaming = [ - 'http://yayay.com', - 'https://yayay.com', - 'HTTP://yayay.com', - 'HTTPS://yayay.com', - ]; - - streaming.forEach(s => - { - activity.serviceUrl = s; - assert(!TurnContext.isFromStreamingConnection(activity), 'incorrectly detected streaming'); - }); - }); -}); \ No newline at end of file +}); diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 13aa55f744..0136658157 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -467,4 +467,46 @@ describe('BotFrameworkStreamingAdapter tests', () => { connection.sendRequest({ method: 'POST', url: 'testResultDotCom', body: 'Test body!' }); expect(spy.called).to.be.true; }).timeout(2000); + + describe('private methods', () => { + it('should identify streaming connections', function () { + let activity = { + type: 'message', + text: 'TestOAuth619 test activity', + recipient: { id: 'TestOAuth619' }, + }; + + const streaming = [ + 'urn:botframework:WebSocket:wss://beep.com', + 'urn:botframework:WebSocket:http://beep.com', + 'URN:botframework:WebSocket:wss://beep.com', + 'URN:botframework:WebSocket:http://beep.com', + ]; + + streaming.forEach(s => { + activity.serviceUrl = s; + expect(BotFrameworkAdapter.isFromStreamingConnection(activity)).to.be.true; + }); + }); + + it('should identify http connections', function () { + let activity = { + type: 'message', + text: 'TestOAuth619 test activity', + recipient: { id: 'TestOAuth619' }, + }; + + const streaming = [ + 'http://yayay.com', + 'https://yayay.com', + 'HTTP://yayay.com', + 'HTTPS://yayay.com', + ]; + + streaming.forEach(s => { + activity.serviceUrl = s; + expect(BotFrameworkAdapter.isFromStreamingConnection(activity)).to.be.false; + }); + }); + }); }); From f940dbb701535557a06cdc239ffb87f012f9ab14 Mon Sep 17 00:00:00 2001 From: stgum <14935595+stevengum@users.noreply.github.com> Date: Wed, 16 Oct 2019 18:31:52 -0700 Subject: [PATCH 24/32] fix bug in processRequest() --- .../botbuilder/src/botFrameworkAdapter.ts | 4 +--- .../botFrameworkStreamingAdapter.test.js | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 1c02f56a52..94b1976c1a 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1000,9 +1000,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide try { let context = new TurnContext(this, body); - await this.runMiddleware(context, async (turnContext): Promise => { - await this.logic(context); - }); + await this.runMiddleware(context, this.logic); if (body.type === ActivityTypes.Invoke) { let invokeResponse: any = context.turnState.get(INVOKE_RESPONSE_KEY); diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 0136658157..51e2dc10e4 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -404,15 +404,18 @@ describe('BotFrameworkStreamingAdapter tests', () => { let bot = new ActivityHandler(); bot.run = function (turnContext) { return Promise.resolve(); }; - - let mwset = []; let handler = new BotFrameworkAdapter(); - handler.use(async (context, next) => { - console.log('Middleware executed!'); - return next(); - }); + let middlewareCalled = false; + const middleware = { + async onTurn(context, next) { + middlewareCalled = true; + return next(); + } + } + + handler.use(middleware); - var spy = sinon.spy(bot, 'run'); + const runSpy = sinon.spy(bot, 'run'); let request = new TestRequest(); request.verb = 'POST'; request.path = '/api/messages'; @@ -428,7 +431,8 @@ describe('BotFrameworkStreamingAdapter tests', () => { const response = await handler.processRequest(request); expect(response.statusCode).to.equal(501); - expect(spy.called).to.be.true; + expect(runSpy.called).to.be.true; + expect(middlewareCalled).to.be.true; }); }); From 75261003e38c207d5c1d6032d37bf931b69a584b Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 18:36:48 -0700 Subject: [PATCH 25/32] Remove library specific implementation of websocket handling --- .../botbuilder/src/botFrameworkAdapter.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index c39f0a9a5b..0988234c42 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -42,6 +42,11 @@ export interface WebRequest { */ headers: any; + /*** + * Optional. The request method. + */ + method?: any; + /** * When implemented in a derived class, adds a listener for an event. * The framework uses this method to retrieve the request body when the @@ -722,8 +727,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > in your bot's console output, the likely cause is that an async function was used * > without using the `await` keyword. Make sure all async functions use await! */ - public async processActivity(req: WebRequest|Request, res: WebResponse|ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { - if (this.isUpgradeRequest(req) && (req).isUpgradeRequest()) { + public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { + if (this.settings.enableWebSockets && req.method === 'GET' && req.headers.Contains('Upgrade')) { return this.useWebSocket(req, res as ServerUpgradeResponse, logic); } @@ -1163,15 +1168,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * @param res The response sent on error or connection termination. * @param res The logic that will handle incoming requests. */ - private async useWebSocket(req: Request, res: ServerUpgradeResponse, logic: (context: TurnContext) => Promise): Promise { - if (!req.isUpgradeRequest()) { - let e = new Error('Upgrade to WebSockets required.'); - res.status(StatusCodes.UPGRADE_REQUIRED); - res.send(e.message); - - return Promise.resolve(); - } - + private async useWebSocket(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { if (!logic) { throw new Error('Streaming logic needs to be provided to `useWebSocket`'); } @@ -1184,7 +1181,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return Promise.resolve(); } - const upgrade = res.claimUpgrade(); + const upgrade = (res as ServerUpgradeResponse).claimUpgrade(); const ws = new Watershed(); const socket = ws.accept(req, upgrade.socket, upgrade.head); From 2989994fd39d2d9c6c0df9d614d8bdad5e8bfae5 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 19:15:58 -0700 Subject: [PATCH 26/32] revert changing protecteds to privates --- libraries/botbuilder/src/botFrameworkAdapter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 0678e20d9c..2a70f56733 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -205,9 +205,9 @@ const POST:string = 'POST'; * ``` */ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvider { - private readonly credentials: MicrosoftAppCredentials; - private readonly credentialsProvider: SimpleCredentialProvider; - private readonly settings: BotFrameworkAdapterSettings; + protected readonly credentials: MicrosoftAppCredentials; + protected readonly credentialsProvider: SimpleCredentialProvider; + protected readonly settings: BotFrameworkAdapterSettings; private logic: (context: TurnContext) => Promise; private streamingServer: IStreamingTransportServer; From 52c625dc33fdacfa1a81b4adb414bc0cb56c6388 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 19:42:35 -0700 Subject: [PATCH 27/32] Further cleanup websocket connection --- libraries/botbuilder/src/botFrameworkAdapter.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 2a70f56733..5f3c1dfe0f 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -66,6 +66,12 @@ export interface WebRequest { * > [!NOTE] This interface supports the framework and is not intended to be called directly for your code. */ export interface WebResponse { + /** + * + * Optional. The underlying socket. + */ + socket?: any; + /** * When implemented in a derived class, sends a FIN packet. * @@ -728,8 +734,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > without using the `await` keyword. Make sure all async functions use await! */ public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { - if (this.settings.enableWebSockets && req.method === 'GET' && req.headers.Contains('Upgrade')) { - return this.useWebSocket(req, res as ServerUpgradeResponse, logic); + if (this.settings.enableWebSockets && req.method === 'GET' && (req.headers.Upgrade || req.headers.upgrade)) { + return this.useWebSocket(req, res, logic); } let body: any; @@ -1140,10 +1146,6 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return claims.isAuthenticated; } - private isUpgradeRequest(target: any): target is Request { - return 'isUpgradeRequest' in target; - } - /** * Connects the handler to a Named Pipe server and begins listening for incoming requests. * @param pipeName The name of the named pipe to use when creating the server. @@ -1179,9 +1181,8 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide return Promise.resolve(); } - const upgrade = (res as ServerUpgradeResponse).claimUpgrade(); const ws = new Watershed(); - const socket = ws.accept(req, upgrade.socket, upgrade.head); + const socket = ws.accept(req, res.socket); await this.startWebSocket(new NodeWebSocket(socket)); } From 2f7fda9197804d75460e3058dcd824edee174d03 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 20:07:15 -0700 Subject: [PATCH 28/32] Update tests --- .../tests/botFrameworkStreamingAdapter.test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 51e2dc10e4..3fd255eb3a 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -161,6 +161,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { read: function () { return new Buffer.from('data', 'utf8'); }, end: function () { return; }, }; + response.socket = fakeSocket; response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); await handler.useWebSocket(request, response, async (context) => { @@ -190,6 +191,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { read: function () { return new Buffer.from('data', 'utf8'); }, end: function () { return; }, }; + response.socket = fakeSocket; response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); await handler.useWebSocket(request, response, async (context) => { @@ -203,15 +205,17 @@ describe('BotFrameworkStreamingAdapter tests', () => { let handler = new BotFrameworkAdapter(); let request = new TestRequest(); request.setIsUpgradeRequest(false); + request.headers = []; let response = new TestResponse(); + response.socket = []; await handler.useWebSocket(request, response, async (context) => { // Route incoming streaming requests to bot await bot.run(context); + expect('Should not have gotten here.').to.equal('But we did.'); + }).catch(err => { + expect(err.message).to.equal('Missing Upgrade Header'); }); - - expect(response.sendVal).to.equal('Upgrade to WebSockets required.'); - expect(response.statusVal).to.equal(426); }); it('returns status code 401 when request is not authorized', async () => { @@ -454,6 +458,7 @@ describe('BotFrameworkStreamingAdapter tests', () => { read: function () { return new Buffer.from('data', 'utf8'); }, end: function () { return Promise.resolve; }, }; + response.socket = fakeSocket; const sinon = require('sinon'); const spy = sinon.spy(fakeSocket, "write"); response.setClaimUpgrade({ socket: fakeSocket, head: 'websocket' }); From 5ecceaacbcb8b353ea0ec2dcef202e0abcefd30e Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 20:09:27 -0700 Subject: [PATCH 29/32] Remove no longer used import --- libraries/botbuilder/src/botFrameworkAdapter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 5f3c1dfe0f..64f1d40e19 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -11,7 +11,6 @@ import { AuthenticationConstants, ChannelValidation, ConnectorClient, EmulatorAp import * as os from 'os'; import { TokenResolver } from './tokenResolver'; import { IStreamingTransportServer, IReceiveRequest, StreamingResponse, NamedPipeServer, ISocket, WebSocketServer, NodeWebSocket } from 'botframework-streaming'; -import { Request, ServerUpgradeResponse } from 'restify'; import { Watershed } from 'watershed'; import { StreamingHttpClient } from './streamingHttpClient'; From 772053731477934ca5948ef40070f78ceb3c78d5 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Wed, 16 Oct 2019 20:14:32 -0700 Subject: [PATCH 30/32] Use const GET instead of string GET --- libraries/botbuilder/src/botFrameworkAdapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 64f1d40e19..16c10e1231 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -733,7 +733,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide * > without using the `await` keyword. Make sure all async functions use await! */ public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise): Promise { - if (this.settings.enableWebSockets && req.method === 'GET' && (req.headers.Upgrade || req.headers.upgrade)) { + if (this.settings.enableWebSockets && req.method === GET && (req.headers.Upgrade || req.headers.upgrade)) { return this.useWebSocket(req, res, logic); } From 8c8f93e07ff4e2d18e45bc945e910f8b0d67b689 Mon Sep 17 00:00:00 2001 From: stgum <14935595+stevengum@users.noreply.github.com> Date: Thu, 17 Oct 2019 08:45:53 -0700 Subject: [PATCH 31/32] fix removed internal export --- libraries/botbuilder/src/botFrameworkAdapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 8ce84e4cab..43048dcff0 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -170,7 +170,7 @@ const OAUTH_ENDPOINT = 'https://api.botframework.com'; const US_GOV_OAUTH_ENDPOINT = 'https://api.botframework.azure.us'; // This key is exported internally so that the TeamsActivityHandler will not overwrite any already set InvokeResponses. -const INVOKE_RESPONSE_KEY: symbol = Symbol('invokeResponse'); +export const INVOKE_RESPONSE_KEY: symbol = Symbol('invokeResponse'); const defaultPipeName = 'bfv4.pipes'; const VERSION_PATH:string = '/api/version'; const MESSAGES_PATH:string = '/api/messages'; From 41d2103d3839ec6d70c694965942209d58246d64 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Thu, 17 Oct 2019 12:50:55 -0700 Subject: [PATCH 32/32] Final fixes to websocket connection for DLS compatibility. --- .../botbuilder/src/botFrameworkAdapter.ts | 9 +++++++-- .../tests/botFrameworkStreamingAdapter.test.js | 18 ------------------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 43048dcff0..1f8c031d60 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1176,14 +1176,19 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide this.logic = logic; + if (typeof((res as any).claimUpgrade) !== 'function') { + throw new Error("ClaimUpgrade is required for creating WebSocket connection."); + } + const authenticated = await this.authenticateConnection(req, this.settings.appId, this.settings.appPassword, this.settings.channelService); if (!authenticated) { res.status(StatusCodes.UNAUTHORIZED); return Promise.resolve(); } - + + const upgrade = (res as any).claimUpgrade(); const ws = new Watershed(); - const socket = ws.accept(req, res.socket); + const socket = ws.accept(req, upgrade.socket, upgrade.head); await this.startWebSocket(new NodeWebSocket(socket)); } diff --git a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js index 3fd255eb3a..c3180071be 100644 --- a/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js +++ b/libraries/botbuilder/tests/botFrameworkStreamingAdapter.test.js @@ -200,24 +200,6 @@ describe('BotFrameworkStreamingAdapter tests', () => { }); }); - it('returns an error when request is not an upgrade request', async () => { - let bot = new ActivityHandler(); - let handler = new BotFrameworkAdapter(); - let request = new TestRequest(); - request.setIsUpgradeRequest(false); - request.headers = []; - let response = new TestResponse(); - response.socket = []; - - await handler.useWebSocket(request, response, async (context) => { - // Route incoming streaming requests to bot - await bot.run(context); - expect('Should not have gotten here.').to.equal('But we did.'); - }).catch(err => { - expect(err.message).to.equal('Missing Upgrade Header'); - }); - }); - it('returns status code 401 when request is not authorized', async () => { let bot = new ActivityHandler(); const settings = new TestAdapterSettings('appId', 'password');