Permalink
Browse files

Linting

  • Loading branch information...
1 parent 6b92c52 commit 4a1eae449f50b291750f58a9e7cfe4b420160c1b @miksago miksago committed Mar 25, 2011
Showing with 65 additions and 61 deletions.
  1. +2 −2 lib/_events.js
  2. +40 −36 lib/ws/connection.js
  3. +10 −10 lib/ws/manager.js
  4. +1 −1 lib/ws/parser.js
  5. +12 −12 lib/ws/server.js
View
@@ -1,5 +1,5 @@
var util = require('./_util'),
- events = require('events');
+ events = require('events');
EventEmitter = exports.EventEmitter = function() {
events.EventEmitter.call(this);
@@ -9,7 +9,7 @@ util.inherits(EventEmitter, events.EventEmitter);
EventEmitter.prototype.emit = function(type) {
if (type !== 'newListener' && (!this._events || !this._events[type]) &&
- this._bubbleTarget && this._bubbleTarget[type]) {
+ this._bubbleTarget && this._bubbleTarget[type]) {
this._bubbleTarget[type].emit.apply(this._bubbleTarget[type], arguments);
} else {
events.EventEmitter.prototype.emit.apply(this, arguments);
View
@@ -4,11 +4,11 @@
var debug = function() {};
var util = require('../_util'),
- events = require('events'),
- Url = require('url'),
- Buffer = require('buffer').Buffer,
- Crypto = require('crypto'),
- Constants = require('constants');
+ events = require('events'),
+ Url = require('url'),
+ Buffer = require('buffer').Buffer,
+ Crypto = require('crypto'),
+ Constants = require('constants');
var _events = require('../_events');
var Mixin = require('../lang/mixin');
@@ -38,9 +38,10 @@ function Connection(manager, options, req, socket, upgradeHead) {
if (connection._options.debug) {
debug = function() {
- util.error('\033[90mWS: ' +
- Array.prototype.join.call(arguments, ' ') +
- '\033[39m'
+ util.error(
+ '\033[90mWS: ' +
+ Array.prototype.join.call(arguments, ' ') +
+ '\033[39m'
);
process.stdout.flush();
};
@@ -50,7 +51,7 @@ function Connection(manager, options, req, socket, upgradeHead) {
version: {
get: function() {
if (req.headers['sec-websocket-key1'] &&
- req.headers['sec-websocket-key2']) {
+ req.headers['sec-websocket-key2']) {
return 'draft76';
}
return 'draft75';
@@ -65,7 +66,10 @@ function Connection(manager, options, req, socket, upgradeHead) {
connection.state(1);
// Setup the connection manager's state change listeners:
connection.on('stateChange', function(state, laststate) {
- if (connection._options.debug) debug(connection.id, 'stateChange: ', laststate, '->', state);
+ if (connection._options.debug) {
+ debug(connection.id, 'stateChange: ', laststate, '->', state);
+ }
+
if (state === 4) {
manager.attach(connection);
// Handle first frame breakages.
@@ -101,8 +105,8 @@ function Connection(manager, options, req, socket, upgradeHead) {
connection.emit('message', message);
});
- parser.on("close", function() {
- debug(connection.id, "requested close");
+ parser.on('close', function() {
+ debug(connection.id, 'requested close');
// Timer to catch clients that don't send close packets.
// I'm looking at you safari and chrome.
@@ -131,7 +135,7 @@ function Connection(manager, options, req, socket, upgradeHead) {
socket.on('error', function(e) {
debug(connection.id, 'error', e);
if (e.errno != constants.EPIPE ||
- e.errno != connection.ECONNRESET) {
+ e.errno != connection.ECONNRESET) {
connection.emit('error', e);
}
connection.state(5);
@@ -232,9 +236,9 @@ function websocket_location(connection) {
}
var location = '',
- secure = connection._socket.secure,
- host = connection._req.headers.host.split(':'),
- port = host[1] !== undefined ? host[1] : (secure ? 443 : 80);
+ secure = connection._socket.secure,
+ host = connection._req.headers.host.split(':'),
+ port = host[1] !== undefined ? host[1] : (secure ? 443 : 80);
location += secure ? 'wss://' : 'ws://';
location += host[0];
@@ -303,7 +307,7 @@ Connection.prototype.close = function() {
}
// Add a two second timeout for closing connections.
- connection._closeTimer = setTimeout(function(){
+ connection._closeTimer = setTimeout(function() {
connection.state(5);
}, 15 * 1000);
};
@@ -337,13 +341,13 @@ var handshakes = {
if (location) {
res = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
- 'Upgrade: WebSocket\r\n' +
- 'Connection: Upgrade\r\n' +
- 'WebSocket-Origin: ' + websocket_origin(connection) + '\r\n' +
- 'WebSocket-Location: ' + location;
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ 'WebSocket-Origin: ' + websocket_origin(connection) + '\r\n' +
+ 'WebSocket-Location: ' + location;
if (connection._options.subprotocol &&
- typeof connection._options.subprotocol == 'string') {
+ typeof connection._options.subprotocol == 'string') {
res += '\r\nWebSocket-Protocol: ' + connection._options.subprotocol;
}
@@ -361,31 +365,31 @@ var handshakes = {
if (location) {
res = 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n' +
- 'Upgrade: WebSocket\r\n' +
- 'Connection: Upgrade\r\n' +
- 'Sec-WebSocket-Origin: ' + websocket_origin(connection) + '\r\n' +
- 'Sec-WebSocket-Location: ' + location;
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ 'Sec-WebSocket-Origin: ' + websocket_origin(connection) + '\r\n' +
+ 'Sec-WebSocket-Location: ' + location;
if (connection._options.subprotocol &&
- typeof connection._options.subprotocol == 'string') {
+ typeof connection._options.subprotocol == 'string') {
res += '\r\nSec-WebSocket-Protocol: ' + connection._options.subprotocol;
}
var strkey1 = connection._req.headers['sec-websocket-key1'],
- strkey2 = connection._req.headers['sec-websocket-key2'],
- numkey1 = parseInt(strkey1.replace(/[^\d]/g, ''), 10),
- numkey2 = parseInt(strkey2.replace(/[^\d]/g, ''), 10),
- spaces1 = strkey1.replace(/[^\ ]/g, '').length,
- spaces2 = strkey2.replace(/[^\ ]/g, '').length;
+ strkey2 = connection._req.headers['sec-websocket-key2'],
+ numkey1 = parseInt(strkey1.replace(/[^\d]/g, ''), 10),
+ numkey2 = parseInt(strkey2.replace(/[^\d]/g, ''), 10),
+ spaces1 = strkey1.replace(/[^\ ]/g, '').length,
+ spaces2 = strkey2.replace(/[^\ ]/g, '').length;
if (spaces1 == 0 || spaces2 == 0 ||
- numkey1 % spaces1 != 0 || numkey2 % spaces2 != 0) {
+ numkey1 % spaces1 != 0 || numkey2 % spaces2 != 0) {
connection.reject('WebSocket Handshake contained an invalid key');
} else {
var hash = Crypto.createHash('md5'),
- key1 = pack(parseInt(numkey1 / spaces1)),
- key2 = pack(parseInt(numkey2 / spaces2));
+ key1 = pack(parseInt(numkey1 / spaces1)),
+ key2 = pack(parseInt(numkey2 / spaces2));
hash.update(key1);
hash.update(key2);
@@ -419,7 +423,7 @@ util.inherits(Parser, events.EventEmitter);
Parser.prototype.write = function(data) {
var pkt, msg;
- debug('parse.write', (new Buffer(data)).inspect())
+ debug('parse.write', (new Buffer(data)).inspect());
for (var i = 0, len = data.length; i < len; i++) {
if (this.order == 0) {
View
@@ -1,7 +1,7 @@
var debug = function() {};
var util = require('../_util'),
- events = require('../_events');
+ events = require('../_events');
/*-----------------------------------------------
Connection Manager
@@ -16,13 +16,13 @@ function Manager(options) {
debug = function(msg, connection) {
if (connection && connection.id) {
util.error('\033[31mManager: ' + msg +
- ': <Connection ' + connection.id + '> ' +
- '(' + self._length + ')\033[39m'
+ ': <Connection ' + connection.id + '> ' +
+ '(' + self._length + ')\033[39m'
);
} else {
util.error('\033[31mManager: ' +
- Array.prototype.join.call(arguments, ' ') +
- ' (' + self._length + ')\033[39m'
+ Array.prototype.join.call(arguments, ' ') +
+ ' (' + self._length + ')\033[39m'
);
}
};
@@ -73,7 +73,7 @@ Manager.prototype.attach = function(connection) {
Manager.prototype.detach = function(connection) {
var previous = current = this._head,
- id = connection.id;
+ id = connection.id;
while (current !== null) {
if (current.id === id) {
@@ -129,8 +129,8 @@ Manager.prototype.forEach = function(callback, thisArg) {
Manager.prototype.map = function(callback, thisArg) {
var current = this._head,
- result = [],
- len = 0;
+ result = [],
+ len = 0;
while (current !== null) {
result.push(callback.call(thisArg, current.connection, len, this._head));
@@ -143,8 +143,8 @@ Manager.prototype.map = function(callback, thisArg) {
Manager.prototype.filter = function(callback, thisArg) {
var current = this._head,
- result = [],
- len = 0;
+ result = [],
+ len = 0;
while (current !== null) {
if (Boolean(callback.call(thisArg, current.connection, len, this._head))) {
View
@@ -3,7 +3,7 @@
http.Server IncomingMessage
-----------------------------------------------*/
var sys = require('sys'),
- events = require('events');
+ events = require('events');
module.exports = Parser;
View
@@ -2,23 +2,23 @@
Requirements:
-----------------------------------------------*/
var http = require('http'),
- path = require('path');
+ path = require('path');
var util = require('../_util'),
- events = require('../_events');
+ events = require('../_events');
var Manager = require('./manager'),
- Connection = require('./connection'),
- Mixin = require('../lang/mixin');
+ Connection = require('./connection'),
+ Mixin = require('../lang/mixin');
/*-----------------------------------------------
Reflectors:
-----------------------------------------------*/
function reflectEvent(sEmitter, sType, tEmitter, tType) {
sEmitter.addListener(sType, function() {
tEmitter.emit.apply(
- tEmitter,
- [tType || sType].concat(Array.prototype.slice.call(arguments))
+ tEmitter,
+ [tType || sType].concat(Array.prototype.slice.call(arguments))
);
});
}
@@ -55,20 +55,20 @@ function Server(o) {
}, o);
var manager = new Manager(options),
- server = options.server;
+ server = options.server;
if (options.datastore) {
throw new Error(
- 'Built-in DataStore has been removed, ' +
- 'see: http://github.com/miksago/nws-memstore'
+ 'Built-in DataStore has been removed, ' +
+ 'see: http://github.com/miksago/nws-memstore'
);
}
server.on('upgrade', function(req, socket, upgradeHead) {
if (req.method == 'GET' &&
- (req.headers['upgrade'] && req.headers['connection']) &&
- req.headers.upgrade.toLowerCase() == 'websocket' &&
- req.headers.connection.toLowerCase() == 'upgrade') {
+ (req.headers['upgrade'] && req.headers['connection']) &&
+ req.headers.upgrade.toLowerCase() == 'websocket' &&
+ req.headers.connection.toLowerCase() == 'upgrade') {
new Connection(manager, options, req, socket, upgradeHead);
}
});

0 comments on commit 4a1eae4

Please sign in to comment.