Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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