Commit 5d50f46f authored by Wandenberg's avatar Wandenberg

add autoReconnect configuration to allow disable the automatic reconnect on...

add autoReconnect configuration to allow disable the automatic reconnect on javascript client when a failure happens
parent 7e67c0f0
......@@ -41,6 +41,7 @@ Example:
| pingtimeout | 30000 | number | the amount of time to consider that a connection does not receive a ping message (in milliseconds) |
| reconnectOnTimeoutInterval | 3000 | number | the amount of time to do a new connection after a timeout happens (in milliseconds) |
| reconnectOnChannelUnavailableInterval | 60000 | number | the amount of time to do a new connection after receives a 403, indicating that a channel is unavailable (in milliseconds) |
| autoReconnect | true | boolean | enable / disable the internal routine to reconnect the client after a failure |
| messagesPublishedAfter | - | number/date | get messages published at less than this time, on the first connection |
| lastEventId | - | string | get messages published after the message with this event id |
| messagesControlByArgument | true | boolean | when to use time and tag values by headers instead of arguments on long polling connections |
......
......@@ -890,6 +890,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
this.pingtimeout = settings.pingtimeout || 30000;
this.reconnectOnTimeoutInterval = settings.reconnectOnTimeoutInterval || 3000;
this.reconnectOnChannelUnavailableInterval = settings.reconnectOnChannelUnavailableInterval || 60000;
this.autoReconnect = (settings.autoReconnect !== false);
this.lastEventId = settings.lastEventId || null;
this.messagesPublishedAfter = settings.messagesPublishedAfter;
......@@ -1098,7 +1099,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
},
_reconnect: function(timeout) {
if (this._keepConnected && !this._reconnecttimer && (this.readyState !== PushStream.CONNECTING)) {
if (this.autoReconnect && this._keepConnected && !this._reconnecttimer && (this.readyState !== PushStream.CONNECTING)) {
Log4js.info("trying to reconnect in", timeout);
this._reconnecttimer = window.setTimeout(linker(this._connect, this), timeout);
}
......
......@@ -425,6 +425,85 @@ describe("PushStream", function() {
);
});
});
describe("when reconnecting", function() {
it("should reconnect after disconnected by the server", function(done) {
var status = [];
pushstream = new PushStream({
modes: mode,
port: port,
useJSONP: jsonp,
urlPrefixLongpolling: urlPrefixLongpolling,
reconnectOnTimeoutInterval: 500,
reconnectOnChannelUnavailableInterval: 500,
onstatuschange: function(st) {
if (PushStream.OPEN === st) {
status.push(st);
}
}
});
pushstream.addChannel(channelName);
pushstream.connect();
waitsForAndRuns(
function() { return status.length >= 2; },
function() {
expect(status).toEqual([PushStream.OPEN, PushStream.OPEN]);
setTimeout(function() {
$.ajax({
url: "http://" + nginxServer + "/pub?id=" + channelName,
success: function(data) {
expect(data.subscribers).toBe("1");
done();
}
});
}, 1000);
},
7000
);
});
it("should not reconnect after disconnected by the server if autoReconnect is off", function(done) {
var status = [];
pushstream = new PushStream({
modes: mode,
port: port,
useJSONP: jsonp,
urlPrefixLongpolling: urlPrefixLongpolling,
reconnectOnTimeoutInterval: 500,
reconnectOnChannelUnavailableInterval: 500,
autoReconnect: false,
onstatuschange: function(st) {
status.push(st);
}
});
pushstream.addChannel(channelName);
pushstream.connect();
waitsForAndRuns(
function() { return status.length >= 3; },
function() {
expect(status).toEqual([PushStream.CONNECTING, PushStream.OPEN, PushStream.CLOSED]);
setTimeout(function() {
$.ajax({
url: "http://" + nginxServer + "/pub?id=" + channelName,
success: function(data) {
expect(data.subscribers).toBe("0");
done();
}
});
}, 2000);
},
7000
);
});
});
}
describe("when adding a new channel", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment