From 397dfbc51db34d28b4f74a4019663e3af79252be Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Tue, 21 Jun 2011 09:44:26 +0200 Subject: [PATCH 1/3] Naming --- lib/transports/flashsocket.js | 1 + lib/transports/htmlfile.js | 3 ++- lib/transports/http-polling.js | 3 ++- lib/transports/http.js | 3 ++- lib/transports/jsonp-polling.js | 3 ++- lib/transports/websocket.js | 10 ++++++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/transports/flashsocket.js b/lib/transports/flashsocket.js index 790fe141..fa88a4d1 100644 --- a/lib/transports/flashsocket.js +++ b/lib/transports/flashsocket.js @@ -25,6 +25,7 @@ exports = module.exports = FlashSocket; function FlashSocket () { WebSocket.apply(this, arguments); + this.name = 'FlashSocket'; } /** diff --git a/lib/transports/htmlfile.js b/lib/transports/htmlfile.js index 943c233f..1ea5b5e8 100644 --- a/lib/transports/htmlfile.js +++ b/lib/transports/htmlfile.js @@ -25,6 +25,7 @@ exports = module.exports = HTMLFile; function HTMLFile (mng, data) { HTTPTransport.call(this, mng, data); + this.name = 'HTMLFile'; }; /** @@ -66,5 +67,5 @@ HTMLFile.prototype.write = function (data) { this.drained = true; } - this.log.debug('htmlfile writing', data); + this.log.debug(this.name + ' writing', data); }; diff --git a/lib/transports/http-polling.js b/lib/transports/http-polling.js index 174a9d9a..078f93e5 100644 --- a/lib/transports/http-polling.js +++ b/lib/transports/http-polling.js @@ -25,6 +25,7 @@ exports = module.exports = HTTPPolling; function HTTPPolling (mng, data) { HTTPTransport.call(this, mng, data); + this.name = 'HTTPPolling'; }; /** @@ -57,7 +58,7 @@ HTTPPolling.prototype.handleRequest = function (req) { this.pollTimeout = setTimeout(function () { self.close(); - self.log.debug('polling closed due to exceeded duration'); + self.log.debug(self.name + ' closed due to exceeded duration'); }, this.manager.get('polling duration') * 1000); this.log.debug('setting poll timeout'); diff --git a/lib/transports/http.js b/lib/transports/http.js index 69fa473f..06e492b2 100644 --- a/lib/transports/http.js +++ b/lib/transports/http.js @@ -27,6 +27,7 @@ exports = module.exports = HTTPTransport; function HTTPTransport (mng, data) { Transport.call(this, mng, data); + this.name = 'HTTPTransport'; }; /** @@ -85,7 +86,7 @@ HTTPTransport.prototype.onData = function (data) { var messages = parser.decodePayload(data); for (var i = 0, l = messages.length; i < l; i++) { - this.log.debug('xhr received data packet', data); + this.log.debug(this.name + ' received data packet', data); this.onMessage(messages[i]); } }; diff --git a/lib/transports/jsonp-polling.js b/lib/transports/jsonp-polling.js index 696ea89c..5ecd9014 100644 --- a/lib/transports/jsonp-polling.js +++ b/lib/transports/jsonp-polling.js @@ -25,6 +25,7 @@ exports = module.exports = JSONPPolling; function JSONPPolling (mng, data) { HTTPPolling.call(this, mng, data); + this.name = 'JSONPPolling'; this.head = 'io.j[0]('; this.foot = ');'; @@ -65,5 +66,5 @@ JSONPPolling.prototype.doWrite = function (data) { }); this.response.write(data); - this.log.debug('json-p writing', data); + this.log.debug(this.name + ' writing', data); }; diff --git a/lib/transports/websocket.js b/lib/transports/websocket.js index 6eda320c..57144e33 100644 --- a/lib/transports/websocket.js +++ b/lib/transports/websocket.js @@ -31,9 +31,11 @@ function WebSocket (mng, data) { // parser var self = this; + this.name = 'WebSocket'; + this.parser = new Parser(); this.parser.on('data', function (packet) { - self.log.debug('websocket received data packet', packet); + self.log.debug(self.name + ' received data packet', packet); self.onMessage(parser.decodePacket(packet)); }); this.parser.on('close', function () { @@ -67,7 +69,7 @@ WebSocket.prototype.onSocketConnect = function () { this.buffered = []; if (this.req.headers.upgrade !== 'WebSocket') { - this.log.warn('WebSocket connection invalid'); + this.log.warn(this.name + ' connection invalid'); this.end(); return; } @@ -180,7 +182,7 @@ WebSocket.prototype.write = function (data) { this.end(); } - this.log.debug('websocket writing', data); + this.log.debug(this.name + ' writing', data); } }; @@ -217,7 +219,7 @@ WebSocket.prototype.proveReception = function (headers) { , spaces = k.replace(/[^ ]/g, '').length; if (spaces === 0 || n % spaces !== 0){ - self.log.warn('Invalid WebSocket key: "' + k + '".'); + self.log.warn('Invalid ' + self.name + ' key: "' + k + '".'); self.end(); return false; } From a62bced0817110740d40b0d8467a2d230867faea Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Tue, 21 Jun 2011 10:00:13 +0200 Subject: [PATCH 2/3] this.name > prototype.name --- lib/transports/flashsocket.js | 9 ++++++++- lib/transports/htmlfile.js | 9 ++++++++- lib/transports/http-polling.js | 9 ++++++++- lib/transports/http.js | 9 ++++++++- lib/transports/jsonp-polling.js | 9 ++++++++- lib/transports/websocket.js | 10 ++++++++-- lib/transports/xhr-polling.js | 10 +++++++++- 7 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/transports/flashsocket.js b/lib/transports/flashsocket.js index fa88a4d1..b352f8da 100644 --- a/lib/transports/flashsocket.js +++ b/lib/transports/flashsocket.js @@ -25,7 +25,6 @@ exports = module.exports = FlashSocket; function FlashSocket () { WebSocket.apply(this, arguments); - this.name = 'FlashSocket'; } /** @@ -34,6 +33,14 @@ function FlashSocket () { FlashSocket.prototype.__proto__ = WebSocket.prototype; +/** + * Transport name + * + * @api public + */ + +FlashSocket.prototype.name = 'flashsocket'; + /** * Listens for new configuration changes of the Manager * this way we can enable and disable the flash server. diff --git a/lib/transports/htmlfile.js b/lib/transports/htmlfile.js index 1ea5b5e8..3ab849f5 100644 --- a/lib/transports/htmlfile.js +++ b/lib/transports/htmlfile.js @@ -25,7 +25,6 @@ exports = module.exports = HTMLFile; function HTMLFile (mng, data) { HTTPTransport.call(this, mng, data); - this.name = 'HTMLFile'; }; /** @@ -34,6 +33,14 @@ function HTMLFile (mng, data) { HTMLFile.prototype.__proto__ = HTTPTransport.prototype; +/** + * Transport name + * + * @api public + */ + +HTMLFile.prototype.name = 'htmlfile'; + /** * Handles the request. * diff --git a/lib/transports/http-polling.js b/lib/transports/http-polling.js index 078f93e5..71ddd648 100644 --- a/lib/transports/http-polling.js +++ b/lib/transports/http-polling.js @@ -25,7 +25,6 @@ exports = module.exports = HTTPPolling; function HTTPPolling (mng, data) { HTTPTransport.call(this, mng, data); - this.name = 'HTTPPolling'; }; /** @@ -36,6 +35,14 @@ function HTTPPolling (mng, data) { HTTPPolling.prototype.__proto__ = HTTPTransport.prototype; +/** + * Transport name + * + * @api public + */ + +HTTPPolling.prototype.name = 'httppolling'; + /** * Removes heartbeat timeouts for polling. */ diff --git a/lib/transports/http.js b/lib/transports/http.js index 06e492b2..5404037a 100644 --- a/lib/transports/http.js +++ b/lib/transports/http.js @@ -27,7 +27,6 @@ exports = module.exports = HTTPTransport; function HTTPTransport (mng, data) { Transport.call(this, mng, data); - this.name = 'HTTPTransport'; }; /** @@ -36,6 +35,14 @@ function HTTPTransport (mng, data) { HTTPTransport.prototype.__proto__ = Transport.prototype; +/** + * Transport name + * + * @api public + */ + +HTTPTransport.prototype.name = 'httptransport'; + /** * Handles a request. * diff --git a/lib/transports/jsonp-polling.js b/lib/transports/jsonp-polling.js index 5ecd9014..4b16bb69 100644 --- a/lib/transports/jsonp-polling.js +++ b/lib/transports/jsonp-polling.js @@ -25,7 +25,6 @@ exports = module.exports = JSONPPolling; function JSONPPolling (mng, data) { HTTPPolling.call(this, mng, data); - this.name = 'JSONPPolling'; this.head = 'io.j[0]('; this.foot = ');'; @@ -41,6 +40,14 @@ function JSONPPolling (mng, data) { JSONPPolling.prototype.__proto__ = HTTPPolling.prototype; +/** + * Transport name + * + * @api public + */ + +JSONPPolling.prototype.name = 'jsonppolling'; + /** * Make sure POST are decoded. */ diff --git a/lib/transports/websocket.js b/lib/transports/websocket.js index 57144e33..c6f2bbd7 100644 --- a/lib/transports/websocket.js +++ b/lib/transports/websocket.js @@ -31,8 +31,6 @@ function WebSocket (mng, data) { // parser var self = this; - this.name = 'WebSocket'; - this.parser = new Parser(); this.parser.on('data', function (packet) { self.log.debug(self.name + ' received data packet', packet); @@ -54,6 +52,14 @@ function WebSocket (mng, data) { WebSocket.prototype.__proto__ = Transport.prototype; +/** + * Transport name + * + * @api public + */ + +WebSocket.prototype.name = 'websocket'; + /** * Called when the socket connects. * diff --git a/lib/transports/xhr-polling.js b/lib/transports/xhr-polling.js index 3a11fc40..8a624538 100644 --- a/lib/transports/xhr-polling.js +++ b/lib/transports/xhr-polling.js @@ -33,6 +33,14 @@ function XHRPolling (mng, data) { XHRPolling.prototype.__proto__ = HTTPPolling.prototype; +/** + * Transport name + * + * @api public + */ + +XHRPolling.prototype.name = 'xhrpolling'; + /** * Frames data prior to write. * @@ -60,5 +68,5 @@ XHRPolling.prototype.doWrite = function (data) { this.response.writeHead(200, headers); this.response.write(data); - this.log.debug('xhr-polling writing', data); + this.log.debug(this.name + ' writing', data); }; From 1bddfc45dd36f8d2b1fae57437b8acca13a77b82 Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Tue, 21 Jun 2011 21:09:41 +0200 Subject: [PATCH 3/3] Added client handler to the options, just for the sake of consistency --- lib/manager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/manager.js b/lib/manager.js index 24ac4379..4d8836d6 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -79,6 +79,7 @@ function Manager (server) { , 'browser client': true , 'browser client minification': false , 'browser client etag': false + , 'browser client handler': false }; // reset listeners