Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Oct 18, 2019
1 parent 992fc6d commit d158a59
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/directLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string> {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d158a59

Please sign in to comment.