From 6ffe60a09a5a6311a55f5feaa783b23362f04a63 Mon Sep 17 00:00:00 2001 From: William Wong Date: Thu, 24 Oct 2019 17:11:59 -0700 Subject: [PATCH] Revert #171 and #172 (#240) * Reverting #171 and #172 * Add entry --- CHANGELOG.md | 4 ++++ src/directLine.ts | 22 ++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fa3bd455..f2cb13434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Reverting PR [#171](https://github.com/Microsoft/BotFramework-DirectLineJS/pull/171) and PR [#172](https://github.com/Microsoft/BotFramework-DirectLineJS/pull/172), which caused infinite loop of reconnections, by [@compulim](https://github.com/compulim) in PR [#240](https://github.com/Microsoft/BotFramework-DirectLineJS/pull/240) + ## [0.11.5] - 2019-09-30 ### Breaking Changes diff --git a/src/directLine.ts b/src/directLine.ts index 491e857ff..54c426c64 100644 --- a/src/directLine.ts +++ b/src/directLine.ts @@ -410,8 +410,6 @@ export class DirectLine implements IBotConnection { private tokenRefreshSubscription: Subscription; - private ending: boolean; - constructor(options: DirectLineOptions) { this.secret = options.secret; this.token = options.secret || options.token; @@ -497,10 +495,7 @@ export class DirectLine implements IBotConnection { .flatMap(connectionStatus => { switch (connectionStatus) { case ConnectionStatus.Ended: - if (this.ending) - return Observable.of(connectionStatus); - else - return Observable.throw(errorConversationEnded); + return Observable.throw(errorConversationEnded); case ConnectionStatus.FailedToConnect: return Observable.throw(errorFailedToConnect); @@ -624,8 +619,13 @@ export class DirectLine implements IBotConnection { end() { if (this.tokenRefreshSubscription) this.tokenRefreshSubscription.unsubscribe(); - this.ending = true; - this.connectionStatus$.next(ConnectionStatus.Ended); + try { + this.connectionStatus$.next(ConnectionStatus.Ended); + } catch (e) { + if (e === errorConversationEnded) + return; + throw(e); + } } getSessionId(): Observable { @@ -863,12 +863,6 @@ export class DirectLine implements IBotConnection { ws.onmessage = message => message.data && subscriber.next(JSON.parse(message.data)); - ws.onerror = error => { - konsole.log("WebSocket error", error); - if (sub) sub.unsubscribe(); - subscriber.error(error); - } - // This is the 'unsubscribe' method, which is called when this observable is disposed. // When the WebSocket closes itself, we throw an error, and this function is eventually called. // When the observable is closed first (e.g. when tearing down a WebChat instance) then