socket.io.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*!
  2. * socket.io-node
  3. * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var client = require('socket.io-client');
  10. /**
  11. * Version.
  12. */
  13. exports.version = '0.9.11';
  14. /**
  15. * Supported protocol version.
  16. */
  17. exports.protocol = 1;
  18. /**
  19. * Client that we serve.
  20. */
  21. exports.clientVersion = client.version;
  22. /**
  23. * Attaches a manager
  24. *
  25. * @param {HTTPServer/Number} a HTTP/S server or a port number to listen on.
  26. * @param {Object} opts to be passed to Manager and/or http server
  27. * @param {Function} callback if a port is supplied
  28. * @api public
  29. */
  30. exports.listen = function (server, options, fn) {
  31. if ('function' == typeof server) {
  32. console.warn('Socket.IO\'s `listen()` method expects an `http.Server` instance\n'
  33. + 'as its first parameter. Are you migrating from Express 2.x to 3.x?\n'
  34. + 'If so, check out the "Socket.IO compatibility" section at:\n'
  35. + 'https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x');
  36. }
  37. if ('function' == typeof options) {
  38. fn = options;
  39. options = {};
  40. }
  41. if ('undefined' == typeof server) {
  42. // create a server that listens on port 80
  43. server = 80;
  44. }
  45. if ('number' == typeof server) {
  46. // if a port number is passed
  47. var port = server;
  48. if (options && options.key)
  49. server = require('https').createServer(options);
  50. else
  51. server = require('http').createServer();
  52. // default response
  53. server.on('request', function (req, res) {
  54. res.writeHead(200);
  55. res.end('Welcome to socket.io.');
  56. });
  57. server.listen(port, fn);
  58. }
  59. // otherwise assume a http/s server
  60. return new exports.Manager(server, options);
  61. };
  62. /**
  63. * Manager constructor.
  64. *
  65. * @api public
  66. */
  67. exports.Manager = require('./manager');
  68. /**
  69. * Transport constructor.
  70. *
  71. * @api public
  72. */
  73. exports.Transport = require('./transport');
  74. /**
  75. * Socket constructor.
  76. *
  77. * @api public
  78. */
  79. exports.Socket = require('./socket');
  80. /**
  81. * Static constructor.
  82. *
  83. * @api public
  84. */
  85. exports.Static = require('./static');
  86. /**
  87. * Store constructor.
  88. *
  89. * @api public
  90. */
  91. exports.Store = require('./store');
  92. /**
  93. * Memory Store constructor.
  94. *
  95. * @api public
  96. */
  97. exports.MemoryStore = require('./stores/memory');
  98. /**
  99. * Redis Store constructor.
  100. *
  101. * @api public
  102. */
  103. exports.RedisStore = require('./stores/redis');
  104. /**
  105. * Parser.
  106. *
  107. * @api public
  108. */
  109. exports.parser = require('./parser');