source: trip-planner-front/node_modules/engine.io/lib/engine.io.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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