|
|
@@ -46,7 +46,8 @@ var
|
|
|
|
|
|
setInterval(function() {
|
|
|
SLACK_SESSIONS.forEach(function(slackInst) {
|
|
|
- slackInst.closeIfInnactive();
|
|
|
+ if (!slackInst.closeIfInnactive())
|
|
|
+ slackInst.ping();
|
|
|
});
|
|
|
}, 60000);
|
|
|
|
|
|
@@ -203,14 +204,17 @@ Slack.prototype.onMessage = function(msg) {
|
|
|
Slack.prototype.connectRtm = function(url, cb) {
|
|
|
var _this = this;
|
|
|
|
|
|
+ this.rtmId = 0;
|
|
|
this.rtm = new WebSocket(url);
|
|
|
this.rtm.on("message", function(msg) {
|
|
|
if (!_this.connected && cb) {
|
|
|
cb();
|
|
|
}
|
|
|
- _this.connected = true;
|
|
|
+ if (!_this.connected) {
|
|
|
+ _this.connected = true;
|
|
|
+ SLACK_SESSIONS.push(_this);
|
|
|
+ }
|
|
|
_this.onMessage(JSON.parse(msg));
|
|
|
- SLACK_SESSIONS.push(_this);
|
|
|
});
|
|
|
this.rtm.once("error", function(e) {
|
|
|
_this.connected = false;
|
|
|
@@ -224,8 +228,19 @@ Slack.prototype.connectRtm = function(url, cb) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * @return {boolean} true if innactive and closeding
|
|
|
+**/
|
|
|
Slack.prototype.closeIfInnactive = function() {
|
|
|
//TODO
|
|
|
+ return false;
|
|
|
+};
|
|
|
+
|
|
|
+Slack.prototype.ping = function() {
|
|
|
+ this.rtm.send(JSON.stringify({
|
|
|
+ "id": ++this.rtmId
|
|
|
+ ,"type": "ping"
|
|
|
+ }));
|
|
|
};
|
|
|
|
|
|
Slack.prototype.close = function() {
|