Skip to content

Commit 96118b5

Browse files
authored
Merge pull request #7 from andrejs-mamontovs/master
Add optional field - pollingInterval
2 parents 58b9c1b + 2f4f3fa commit 96118b5

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var directLine = new DirectLine({
5656
token: /* or put your Direct Line token here (supply secret OR token, not both) */,
5757
domain: /* optional: if you are not using the default Direct Line endpoint, e.g. if you are using a region-specific endpoint, put its full URL here */
5858
webSocket: /* optional: false if you want to use polling GET to receive messages. Defaults to true (use WebSocket). */,
59+
pollingInterval: /* optional: set polling interval in milliseconds. Default to 1000 */,
5960
});
6061
```
6162

directLine.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export interface DirectLineOptions {
209209
token?: string;
210210
domain?: string;
211211
webSocket?: boolean;
212+
pollingInterval?: number;
212213
}
213214
export declare class DirectLine implements IBotConnection {
214215
constructor(options: DirectLineOptions);

src/directLine.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ export interface DirectLineOptions {
221221
secret?: string,
222222
token?: string
223223
domain?: string,
224-
webSocket?: boolean
224+
webSocket?: boolean,
225+
pollingInterval?: number
225226
}
226227

227228
const lifetimeRefreshToken = 30 * 60 * 1000;
@@ -261,6 +262,8 @@ export class DirectLine implements IBotConnection {
261262
private watermark = '';
262263
private streamUrl: string;
263264

265+
private pollingInterval: number = 1000;
266+
264267
private tokenRefreshSubscription: Subscription;
265268

266269
constructor(options: DirectLineOptions) {
@@ -271,6 +274,9 @@ export class DirectLine implements IBotConnection {
271274
if (options.webSocket !== undefined)
272275
this.webSocket = options.webSocket;
273276

277+
if (options.pollingInterval !== undefined)
278+
this.pollingInterval = options.pollingInterval;
279+
274280
this.activity$ = this.webSocket && typeof WebSocket !== 'undefined' && WebSocket
275281
? this.webSocketActivity$()
276282
: this.pollingGetActivity$();
@@ -481,7 +487,7 @@ export class DirectLine implements IBotConnection {
481487
}
482488

483489
private pollingGetActivity$() {
484-
return Observable.interval(1000)
490+
return Observable.interval(this.pollingInterval)
485491
.combineLatest(this.checkConnection())
486492
.flatMap(_ =>
487493
Observable.ajax({

0 commit comments

Comments
 (0)