Skip to content

Commit

Permalink
Removed extra pong tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphenslee committed Oct 14, 2015
1 parent fecf8c5 commit f092826
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Coverage Status](https://coveralls.io/repos/philliphenslee/smartslack/badge.svg?branch=master&service=github)](https://coveralls.io/github/philliphenslee/smartslack?branch=master)
[![Current Version](https://img.shields.io/badge/version-0.0.1-red.svg)](https://github.com/philliphenslee/smartslack)

# Summary
##Summary
***SmartSlack*** is a node.js module for [*Slack's*](https://slack.com) Real Time Messaging API.


Expand Down
20 changes: 2 additions & 18 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var bole = require('bole')
var pretty = require('bistre')({ time: true })
var WebSocket = require('ws');


// Bole
bole.output({
level: process.env.LOG_LEVEL || 'debug'
Expand All @@ -32,7 +31,6 @@ var errors = {
invalid_token: 'Error invalid access token, please provide a valid token.',
missing_options_arg: 'Error missing required argument object options',
missing_required_arg: 'Error missing required argument'

}

/**
Expand Down Expand Up @@ -69,7 +67,6 @@ var SmartSlack = function (options) {

this._messageId = 0;
this._lastPong = null;
this._avgLatency = [];
}

util.inherits(SmartSlack, EventEmitter)
Expand Down Expand Up @@ -249,7 +246,6 @@ SmartSlack.prototype.login = function () {
*/
SmartSlack.prototype.onRtmEvent = function (message) {
var _this = this;
var latency;

this.emit('rawmessage', message);
this.log.debug({ 'Slack Event': message });
Expand All @@ -273,24 +269,13 @@ SmartSlack.prototype.onRtmEvent = function (message) {
break;

case 'pong':

this._lastPong = _.now();

// Save recent response latency to array
latency = (this._lastPong - message.time);
this.log.debug('Current Latency = ' + (this._lastPong - message.time) + 'ms');
this._avgLatency.push(latency);

// Save only the last minute of values
if (this._avgLatency.length > 12) {
this._avgLatency.shift();
}

this.log.debug('Average Latency = ' + Math.round((_.sum(this._avgLatency) / this._avgLatency.length)) + 'ms');
break;
}

}

/**
* Post a message to the Slack API
* @param id
Expand All @@ -313,7 +298,6 @@ SmartSlack.prototype.postMessage = function (channelId, text, params, callback)
} else {
throw new Error(errors.missing_required_arg);
}

};

/**
Expand Down Expand Up @@ -452,4 +436,4 @@ SmartSlack.prototype._apiCall = function (method, params, callback) {
req.end();
}

module.exports = SmartSlack
module.exports = SmartSlack;

0 comments on commit f092826

Please sign in to comment.