Skip to content

Commit

Permalink
Lazy loading of transports. Thanks @technoweenie
Browse files Browse the repository at this point in the history
Fixed README transports list
  • Loading branch information
rauchg committed Dec 24, 2010
1 parent 3029d0c commit 45f1712
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Options:

- *transports*

['websocket', 'server-events', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling',
'jsonp-polling']
A list of the accepted transports.

Expand Down
21 changes: 9 additions & 12 deletions lib/socket.io/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ var url = require('url')
, options = require('./utils').options
, Client = require('./client')
, clientVersion = require('./../../support/socket.io-client/lib/io').io.version
, transports = {
'flashsocket': require('./transports/flashsocket')
, 'htmlfile': require('./transports/htmlfile')
, 'websocket': require('./transports/websocket')
, 'xhr-multipart': require('./transports/xhr-multipart')
, 'xhr-polling': require('./transports/xhr-polling')
, 'jsonp-polling': require('./transports/jsonp-polling')
};
, transports = {};

var Listener = module.exports = function(server, options){
process.EventEmitter.call(this);
Expand All @@ -21,7 +14,8 @@ var Listener = module.exports = function(server, options){
origins: '*:*',
resource: 'socket.io',
flashPolicyServer: true,
transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling'],
transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart',
'xhr-polling', 'jsonp-polling'],
transportOptions: {},
log: util.log
}, options);
Expand Down Expand Up @@ -49,9 +43,12 @@ var Listener = module.exports = function(server, options){
}
});

for (var i in transports)
if ('init' in transports[i]) transports[i].init(this);

this.options.transports.forEach(function(name) {
if (!(name in transports))
transports[name] = require('./transports/' + name);
if ('init' in transports[name]) transports[name].init(self);
});

this.options.log('socket.io ready - accepting connections');
};

Expand Down

0 comments on commit 45f1712

Please sign in to comment.