Only send ping messages for EventSource if the user specifies an interval, for symmetry with WebSocket.

This commit is contained in:
James Coglan
2012-02-12 23:59:20 +00:00
parent c958c5ead9
commit 74b76e56b7
2 changed files with 7 additions and 7 deletions
+2 -1
View File
@@ -31,7 +31,8 @@ var EventSource = function(request, response, options) {
this._sendBuffer = [];
process.nextTick(function() { self._open() });
this._pingLoop = setInterval(function() { self.ping() }, this._ping * 1000);
if (this._ping)
this._pingLoop = setInterval(function() { self.ping() }, this._ping * 1000);
['close', 'end', 'error'].forEach(function(event) {
self._stream.addListener(event, function() { self.close() });
+5 -6
View File
@@ -34,6 +34,8 @@ var isSecureConnection = function(request) {
var WebSocket = function(request, socket, head, supportedProtos, options) {
this.request = request;
this._stream = request.socket;
this._ping = options && options.ping;
this._pingId = 0;
this._stream.setTimeout(0);
this._stream.setNoDelay(true);
@@ -55,18 +57,15 @@ var WebSocket = function(request, socket, head, supportedProtos, options) {
if (this._parser.isOpen()) this.readyState = API.OPEN;
this.protocol = this._parser.protocol || '';
this.version = this._parser.getVersion();
this._ping = options && options.ping;
this._pingId = 0;
if (this._ping)
this._pingLoop = setInterval(function() {
self._pingId += 1;
self.ping(self._pingId.toString());
}, this._ping * 1000);
this.protocol = this._parser.protocol || '';
this.version = this._parser.getVersion();
this._stream.addListener('data', function(data) {
var response = self._parser.parse(data);
if (!response) return;