Only send ping messages for EventSource if the user specifies an interval, for symmetry with WebSocket.
This commit is contained in:
@@ -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() });
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user