Skip to content

Commit 39ecafc

Browse files
mingweiwcwhitten
authored andcommitted
Change reconnect delay to be a random amount between 3s and 15s (#164)
1 parent f876daa commit 39ecafc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/directLine.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,16 @@ export class DirectLine implements IBotConnection {
807807
// WebSockets can be closed by the server or the browser. In the former case we need to
808808
// retrieve a new streamUrl. In the latter case we could first retry with the current streamUrl,
809809
// but it's simpler just to always fetch a new one.
810-
.retryWhen(error$ => error$.delay(3000).mergeMap(error => this.reconnectToConversation()))
810+
.retryWhen(error$ => error$.delay(this.getRetryDelay()).mergeMap(error => this.reconnectToConversation()))
811811
)
812812
.flatMap(activityGroup => this.observableFromActivityGroup(activityGroup))
813813
}
814814

815+
// Returns the delay duration in milliseconds
816+
private getRetryDelay() {
817+
return Math.floor(3000 + Math.random() * 12000);
818+
}
819+
815820
// Originally we used Observable.webSocket, but it's fairly opionated and I ended up writing
816821
// a lot of code to work around their implemention details. Since WebChat is meant to be a reference
817822
// implementation, I decided roll the below, where the logic is more purposeful. - @billba

0 commit comments

Comments
 (0)