Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

engine.io.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Module dependencies.
  3. */
  4. const http = require("http");
  5. const Server = require("./server");
  6. /**
  7. * Invoking the library as a function delegates to attach if the first argument
  8. * is an `http.Server`.
  9. *
  10. * If there are no arguments or the first argument is an options object, then
  11. * a new Server instance is returned.
  12. *
  13. * @param {http.Server} server (if specified, will be attached to by the new Server instance)
  14. * @param {Object} options
  15. * @return {Server} engine server
  16. * @api public
  17. */
  18. exports = module.exports = function() {
  19. // backwards compatible use as `.attach`
  20. // if first argument is an http server
  21. if (arguments.length && arguments[0] instanceof http.Server) {
  22. return attach.apply(this, arguments);
  23. }
  24. // if first argument is not an http server, then just make a regular eio server
  25. return new Server(...arguments);
  26. };
  27. /**
  28. * Protocol revision number.
  29. *
  30. * @api public
  31. */
  32. exports.protocol = 1;
  33. /**
  34. * Expose Server constructor.
  35. *
  36. * @api public
  37. */
  38. exports.Server = Server;
  39. /**
  40. * Expose Socket constructor.
  41. *
  42. * @api public
  43. */
  44. exports.Socket = require("./socket");
  45. /**
  46. * Expose Transport constructor.
  47. *
  48. * @api public
  49. */
  50. exports.Transport = require("./transport");
  51. /**
  52. * Expose mutable list of available transports.
  53. *
  54. * @api public
  55. */
  56. exports.transports = require("./transports");
  57. /**
  58. * Exports parser.
  59. *
  60. * @api public
  61. */
  62. exports.parser = require("engine.io-parser");
  63. /**
  64. * Creates an http.Server exclusively used for WS upgrades.
  65. *
  66. * @param {Number} port
  67. * @param {Function} callback
  68. * @param {Object} options
  69. * @return {Server} websocket.io server
  70. * @api public
  71. */
  72. exports.listen = listen;
  73. function listen(port, options, fn) {
  74. if ("function" === typeof options) {
  75. fn = options;
  76. options = {};
  77. }
  78. const server = http.createServer(function(req, res) {
  79. res.writeHead(501);
  80. res.end("Not Implemented");
  81. });
  82. // create engine server
  83. const engine = exports.attach(server, options);
  84. engine.httpServer = server;
  85. server.listen(port, fn);
  86. return engine;
  87. }
  88. /**
  89. * Captures upgrade requests for a http.Server.
  90. *
  91. * @param {http.Server} server
  92. * @param {Object} options
  93. * @return {Server} engine server
  94. * @api public
  95. */
  96. exports.attach = attach;
  97. function attach(server, options) {
  98. const engine = new Server(options);
  99. engine.attach(server, options);
  100. return engine;
  101. }