Skip to content

Commit db9d160

Browse files
committed
Minimal change to fix the problem with pollingGetActivity$ that "completes"
when we get a 403 from the server. The problem was that the checkConnection() call threw an exception when the connectionStatus was ExpiredToken. This resulted in the outer catch in the pollingGetActivity() function getting called which returned an empty Observable that "completed" the activity$ stream. A temporary fix for this problem is to not throw from the checkConnection function - Also, we must not make AJAX calls while the connection status is not online.
1 parent e5bf646 commit db9d160

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/directLine.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ const errorFailedToConnect = new Error("failed to connect");
279279

280280
const konsole = {
281281
log: (message?: any, ... optionalParams: any[]) => {
282-
if (typeof(window) !== 'undefined' && window["botchatDebug"] && message)
282+
if (typeof(window) !== 'undefined' && (window as any)["botchatDebug"] && message)
283283
console.log(message, ... optionalParams);
284284
}
285285
}
@@ -298,7 +298,7 @@ export class DirectLine implements IBotConnection {
298298
public activity$: Observable<Activity>;
299299

300300
private domain = "https://directline.botframework.com/v3/directline";
301-
private webSocket;
301+
private webSocket: boolean;
302302

303303
private conversationId: string;
304304
private secret: string;
@@ -384,10 +384,10 @@ export class DirectLine implements IBotConnection {
384384
return Observable.throw(errorFailedToConnect);
385385

386386
case ConnectionStatus.ExpiredToken:
387-
return Observable.throw(errorExpiredToken);
387+
return Observable.of(connectionStatus);
388388

389389
default:
390-
return Observable.of(null);
390+
return Observable.of(connectionStatus);
391391
}
392392
})
393393

@@ -598,8 +598,11 @@ export class DirectLine implements IBotConnection {
598598
private pollingGetActivity$() {
599599
return Observable.interval(this.pollingInterval)
600600
.combineLatest(this.checkConnection())
601-
.flatMap(_ =>
602-
Observable.ajax({
601+
.flatMap(([_, connectionStatus]) => {
602+
if (connectionStatus !== ConnectionStatus.Online)
603+
return Observable.empty<Activity>()
604+
605+
return Observable.ajax({
603606
method: "GET",
604607
url: `${this.domain}/conversations/${this.conversationId}/activities?watermark=${this.watermark}`,
605608
timeout,
@@ -622,7 +625,7 @@ export class DirectLine implements IBotConnection {
622625
// .do(ajaxResponse => konsole.log("getActivityGroup ajaxResponse", ajaxResponse))
623626
.map(ajaxResponse => ajaxResponse.response as ActivityGroup)
624627
.flatMap(activityGroup => this.observableFromActivityGroup(activityGroup))
625-
)
628+
})
626629
.catch(error => Observable.empty<Activity>());
627630
}
628631

0 commit comments

Comments
 (0)