Skip to content
Open
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
15 changes: 11 additions & 4 deletions src/transports/bosh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { sleep, timeoutPromise } from '../Utils';
class RequestChannel {
public rid!: number;
public maxTimeout: number;
public maxRetries = 5;
public active = false;

private stream: BOSH;
private maxRetries = 5;

constructor(stream: BOSH) {
this.stream = stream;
Expand Down Expand Up @@ -50,7 +50,7 @@ class RequestChannel {

return result;
} catch (err) {
if (attempts === 1) {
if (this.maxRetries !== 0 && attempts === 1) {
continue;
} else if (attempts < this.maxRetries) {
const backoff = Math.min(this.maxTimeout, Math.pow(attempts, 2) * 1000);
Expand All @@ -76,6 +76,7 @@ export default class BOSH extends Duplex implements Transport {
public sid?: string = '';
public maxHoldOpen = 2;
public maxWaitTime = 30;
public maxRetries = 5;
public contentType = 'text/xml; charset=utf-8';

private channels: RequestChannel[] = [new RequestChannel(this), new RequestChannel(this)];
Expand Down Expand Up @@ -200,6 +201,12 @@ export default class BOSH extends Duplex implements Transport {
if (opts.maxHoldOpen) {
this.maxHoldOpen = opts.maxHoldOpen;
}
if (opts.maxRetries !== undefined) {
this.maxRetries = opts.maxRetries;
this.channels.forEach(channel => {
channel.maxRetries = this.maxRetries;
});
}

if (this.sid) {
this.hasStream = true;
Expand Down Expand Up @@ -293,7 +300,7 @@ export default class BOSH extends Duplex implements Transport {
this.process(result);
})
.catch(err => {
this.end(err);
this.destroy(err);
});
this.toggleChannel();
}
Expand All @@ -319,7 +326,7 @@ export default class BOSH extends Duplex implements Transport {
this.process(result);
})
.catch(err => {
this.end(err);
this.destroy(err);
});
}

Expand Down