5 var http = require('http');
8 * Invoking the library as a function delegates to attach if the first argument
11 * If there are no arguments or the first argument is an options object, then
12 * a new Server instance is returned.
14 * @param {http.Server} server (if specified, will be attached to by the new Server instance)
15 * @param {Object} options
16 * @return {Server} engine server
20 exports = module.exports = function () {
21 // backwards compatible use as `.attach`
22 // if first argument is an http server
23 if (arguments.length && arguments[0] instanceof http.Server) {
24 return attach.apply(this, arguments);
27 // if first argument is not an http server, then just make a regular eio server
28 return exports.Server.apply(null, arguments);
32 * Protocol revision number.
40 * Expose Server constructor.
45 exports.Server = require('./server');
48 * Expose Socket constructor.
53 exports.Socket = require('./socket');
56 * Expose Transport constructor.
61 exports.Transport = require('./transport');
64 * Expose mutable list of available transports.
69 exports.transports = require('./transports');
77 exports.parser = require('engine.io-parser');
80 * Creates an http.Server exclusively used for WS upgrades.
82 * @param {Number} port
83 * @param {Function} callback
84 * @param {Object} options
85 * @return {Server} websocket.io server
89 exports.listen = listen;
91 function listen (port, options, fn) {
92 if ('function' === typeof options) {
97 var server = http.createServer(function (req, res) {
99 res.end('Not Implemented');
102 // create engine server
103 var engine = exports.attach(server, options);
104 engine.httpServer = server;
106 server.listen(port, fn);
112 * Captures upgrade requests for a http.Server.
114 * @param {http.Server} server
115 * @param {Object} options
116 * @return {Server} engine server
120 exports.attach = attach;
122 function attach (server, options) {
123 var engine = new exports.Server(options);
124 engine.attach(server, options);