Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #274 from selfcontained/close-error-reconnect
Browse files Browse the repository at this point in the history
Reconnect when websocket closes abnormally
  • Loading branch information
Ben Brown authored Jun 16, 2016
2 parents 93a151e + c380c28 commit 714788d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Slackbot_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ module.exports = function(botkit, config) {
});

bot.rtm.on('open', function() {
botkit.log.notice('RTM websocket opened');

pingIntervalId = setInterval(function() {
if (lastPong && lastPong + 12000 < Date.now()) {
Expand Down Expand Up @@ -204,11 +205,21 @@ module.exports = function(botkit, config) {
botkit.trigger('rtm_close', [bot, err]);
});

bot.rtm.on('close', function() {
bot.rtm.on('close', function(code, message) {
botkit.log.notice('RTM close event: ' + code + ' : ' + message);
if (pingIntervalId) {
clearInterval(pingIntervalId);
}
botkit.trigger('rtm_close', [bot]);

/**
* CLOSE_ABNORMAL error
* wasn't closed explicitly, should attempt to reconnect
*/
if (code === 1006) {
botkit.log.error('Abnormal websocket close event, attempting to reconnect');
reconnect();
}
});
});

Expand Down

0 comments on commit 714788d

Please sign in to comment.