From d158a593accf438dbf8c315fd24abe95400361ec Mon Sep 17 00:00:00 2001 From: William Wong Date: Thu, 17 Oct 2019 22:13:38 -0700 Subject: [PATCH] Reverting #171 and #172 --- src/directLine.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) 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