diff --git a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts b/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts
index a30f7ecd0d..2cf43351a6 100644
--- a/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts
+++ b/libraries/botframework-streaming-extensions/src/WebSocket/WebSocketClient.ts
@@ -29,20 +29,19 @@ export class WebSocketClient implements IStreamingTransportClient {
private readonly _receiver: PayloadReceiver;
private readonly _requestManager: RequestManager;
private readonly _protocolAdapter: ProtocolAdapter;
- private readonly _autoReconnect: boolean;
+ 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 setting to determine if the server sould attempt to reconnect
- /// automatically on disconnection events. Defaults to true.
+ /// Optional function to handle the disconnection message
///
- public constructor({ url, requestHandler, autoReconnect = true }) {
+ public constructor({ url, requestHandler, disconnectionHandler = null}) {
this._url = url;
this._requestHandler = requestHandler;
- this._autoReconnect = autoReconnect;
+ this._disconnectionHandler = disconnectionHandler;
this._requestManager = new RequestManager();
@@ -96,10 +95,11 @@ export class WebSocketClient implements IStreamingTransportClient {
}
private onConnectionDisconnected(sender: object, args: any): void {
- if (this._autoReconnect) {
- this.connect()
- .catch((): void => { throw(new Error(`Unable to re-connect client to Node transport. Sender:` + sender + ' Args:' + args)); });
+ if (this._disconnectionHandler != null) {
+ this._disconnectionHandler("Disconnected");
+ return;
}
- }
+ throw(new Error(`Unable to re-connect client to Node transport. Sender:` + sender + ' Args:' + args));
+ }
}
diff --git a/libraries/botframework-streaming-extensions/tests/WebSocket.test.js b/libraries/botframework-streaming-extensions/tests/WebSocket.test.js
index 2fda31b760..6bd8fd082a 100644
--- a/libraries/botframework-streaming-extensions/tests/WebSocket.test.js
+++ b/libraries/botframework-streaming-extensions/tests/WebSocket.test.js
@@ -244,13 +244,13 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
describe('WebSocket Client Tests', () => {
it('creates a new client', () => {
- let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler(), false);
+ let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler());
expect(client).to.be.instanceOf(ws.WebSocketClient);
expect(client.disconnect()).to.not.throw;
});
it('selects the right websocket and attempts to connect to the transport layer', (done) => {
- let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler(), false);
+ let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler());
expect(client).to.be.instanceOf(ws.WebSocketClient);
client.connect()
.catch(
@@ -261,7 +261,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
});
it('sends', (done) => {
- let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler(), false);
+ let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler());
expect(client).to.be.instanceOf(ws.WebSocketClient);
let req = new protocol.StreamingRequest();
req.Verb = 'POST';
@@ -271,7 +271,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
});
it('disconnects', (done) => {
- let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler(), false);
+ let client = new ws.WebSocketClient('fakeURL', new protocol.RequestHandler());
expect(client).to.be.instanceOf(ws.WebSocketClient);
expect(client.disconnect()).to.not.throw;
done();