Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Indention fixes

  • Loading branch information...
commit ff8c4f09a04835193949161b4959773ffb103693 1 parent 88c196c
@rauchg rauchg authored
View
3  lib/socket.io.js
@@ -1,7 +1,8 @@
require.paths.unshift(__dirname + '/vendor/js-oo/lib');
require('oo');
+
var sys = require('sys'),
- Listener = require('./socket.io/listener').Listener;
+ Listener = require('./socket.io/listener').Listener;
this.listen = function(server, options){
return new Listener(server, options);
View
30 lib/socket.io/client.js
@@ -1,33 +1,33 @@
var sys = require('sys');
this.Client = Class({
-
+
init: function(listener, req, res){
this.listener = listener;
this.connections = 0;
this.connected = false;
this._onConnect(req, res);
},
-
+
send: function(message){
if (!this.connected || !(this.connection.readyState == 'open' || this.connection.readyState == 'writeOnly')) return this._queue(message);
this._write(JSON.stringify({messages: [message]}));
return this;
},
-
+
broadcast: function(message){
if (!('sessionId' in this)) return this;
this.listener.broadcast(message, this.sessionId);
return this;
},
-
+
_onMessage: function(data){
var messages = JSON.parse(data);
for (var i = 0, l = messages.length; i < l; i++){
this.listener._onClientMessage(messages[i], this);
}
},
-
+
_onConnect: function(req, res){
var self = this;
this.request = req;
@@ -35,13 +35,13 @@ this.Client = Class({
this.connection = this.request.connection;
if (this._disconnectTimeout) clearTimeout(this._disconnectTimeout);
},
-
+
_payload: function(){
var payload = [];
-
+
this.connections++;
this.connected = true;
-
+
if (!this.handshaked){
this._generateSessionId();
payload.push(JSON.stringify({
@@ -49,14 +49,14 @@ this.Client = Class({
}));
this.handshaked = true;
}
-
+
payload = payload.concat(this._writeQueue || []);
this._writeQueue = [];
-
+
if (payload.length) this._write(JSON.stringify({messages: payload}));
if (this.connections == 1) this.listener._onClientConnect(this);
},
-
+
_onClose: function(){
var self = this;
this.connected = false;
@@ -64,7 +64,7 @@ this.Client = Class({
self._onDisconnect();
}, this.listener.options.timeout);
},
-
+
_onDisconnect: function(){
if (!this.finalized){
this._writeQueue = [];
@@ -73,17 +73,17 @@ this.Client = Class({
if (this.handshaked) this.listener._onClientDisconnect(this);
}
},
-
+
_queue: function(message){
if (!('_writeQueue' in this)) this._writeQueue = [];
this._writeQueue.push(message);
return this;
},
-
+
_generateSessionId: function(){
if (this.sessionId) return this.listener.options.log('This client already has a session id');
this.sessionId = Math.random().toString().substr(2);
return this;
}
-
+
});
View
10 lib/socket.io/transports/flashsocket.js
@@ -1,6 +1,6 @@
var websocket = require('./websocket').websocket,
- tcp = require('tcp'),
- listeners = [];
+ tcp = require('tcp'),
+ listeners = [];
this.flashsocket = websocket.extend({});
@@ -12,14 +12,14 @@ tcp.createServer(function(socket){
socket.write('<?xml version="1.0"?>\n');
socket.write('<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">\n');
socket.write('<cross-domain-policy>\n');
-
+
listeners.forEach(function(l){
[].concat(l.options.origins).forEach(function(origin){
var parts = origin.split(':');
socket.write('<allow-access-from domain="' + parts[0] + '" to-ports="'+ parts[1] +'"/>\n');
});
});
-
+
socket.write('</cross-domain-policy>\n');
- socket.close();
+ socket.close();
}).listen(843);
View
2  lib/socket.io/transports/htmlfile.js
@@ -1,5 +1,5 @@
var Client = require('../client').Client,
- qs = require('querystring');
+ qs = require('querystring');
this['htmlfile'] = Client.extend({
View
2  lib/socket.io/transports/server-events.js
@@ -1,5 +1,5 @@
var Client = require('../client').Client,
- qs = require('querystring');
+ qs = require('querystring');
this['server-events'] = Client.extend({
View
26 lib/socket.io/transports/websocket.js
@@ -1,6 +1,6 @@
var Client = require('../client').Client,
- url = require('url'),
- sys = require('sys');
+ url = require('url'),
+ sys = require('sys');
this.websocket = Client.extend({
@@ -25,23 +25,23 @@ this.websocket = Client.extend({
self.connection.setTimeout(0);
self.connection.setNoDelay(true);
self.connection.addListener('end', function(){ self._onClose(); });
- self.connection.addListener('data', function(data) {
- if (data[0] !== '\u0000' && data[data.length - 1] !== '\ufffd'){
- self.connection.close();
- } else {
+ self.connection.addListener('data', function(data){
+ if (data[0] !== '\u0000' && data[data.length - 1] !== '\ufffd'){
+ self.connection.close();
+ } else {
self._onMessage(data.substr(1, data.length - 2));
}
- });
+ });
});
this.response.use_chunked_encoding_by_default = false;
- this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
+ this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
'Upgrade': 'WebSocket',
'Connection': 'Upgrade',
'WebSocket-Origin': this.request.headers.origin,
'WebSocket-Location': 'ws://' + this.request.headers.host + this.request.url
- });
- this.response.flush();
+ });
+ this.response.flush();
this._payload();
},
@@ -49,9 +49,9 @@ this.websocket = Client.extend({
_verifyOrigin: function(origin){
var parts = url.parse(origin);
return this.listener.options.origins.indexOf('*:*') !== -1
- || this.listener.options.origins.indexOf(parts.host + ':' + parts.port) !== -1
- || this.listener.options.origins.indexOf(parts.host + ':*') !== -1
- || this.listener.options.origins.indexOf('*:' + parts.port) !== -1;
+ || this.listener.options.origins.indexOf(parts.host + ':' + parts.port) !== -1
+ || this.listener.options.origins.indexOf(parts.host + ':*') !== -1
+ || this.listener.options.origins.indexOf('*:' + parts.port) !== -1;
},
_write: function(message){
View
2  lib/socket.io/transports/xhr-multipart.js
@@ -1,5 +1,5 @@
var Client = require('../client').Client,
- qs = require('querystring');
+ qs = require('querystring');
this['xhr-multipart'] = Client.extend({
View
4 lib/socket.io/transports/xhr-polling.js
@@ -1,6 +1,6 @@
var Client = require('../client').Client,
- qs = require('querystring'),
- sys = require('sys');
+ qs = require('querystring'),
+ sys = require('sys');
this['xhr-polling'] = Client.extend({
View
42 lib/socket.io/util/object.js
@@ -2,34 +2,34 @@
// Copyright (c) 2006-2009 Valerio Proietti, <http://mad4milk.net/>
var clone = this.clone = function(item){
- var clone;
- if (item instanceof Array){
- clone = [];
- for (var i = 0; i < item.length; i++) clone[i] = clone(item[i]);
- return clone;
- } else if (typeof item == 'object') {
- clone = {};
- for (var key in object) clone[key] = clone(object[key]);
- return clone;
- } else {
- return item;
- }
+ var clone;
+ if (item instanceof Array){
+ clone = [];
+ for (var i = 0; i < item.length; i++) clone[i] = clone(item[i]);
+ return clone;
+ } else if (typeof item == 'object') {
+ clone = {};
+ for (var key in object) clone[key] = clone(object[key]);
+ return clone;
+ } else {
+ return item;
+ }
},
mergeOne = function(source, key, current){
- if (current instanceof Array){
- source[key] = clone(current);
- } else if (typeof current == 'object'){
- if (typeof source[key] == 'object') object.merge(source[key], current);
+ if (current instanceof Array){
+ source[key] = clone(current);
+ } else if (typeof current == 'object'){
+ if (typeof source[key] == 'object') object.merge(source[key], current);
else source[key] = clone(current);
- } else {
- source[key] = current;
- }
- return source;
+ } else {
+ source[key] = current;
+ }
+ return source;
};
this.merge = function(source, k, v){
- if (typeof k == 'string') return mergeOne(source, k, v);
+ if (typeof k == 'string') return mergeOne(source, k, v);
for (var i = 1, l = arguments.length; i < l; i++){
var object = arguments[i];
for (var key in object) mergeOne(source, key, object[key]);
Please sign in to comment.
Something went wrong with that request. Please try again.