- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/socket.io/dist/index.js
r59329aa re29cc2e 30 30 const stream_1 = require("stream"); 31 31 const path = require("path"); 32 const engine = require("engine.io");32 const engine_io_1 = require("engine.io"); 33 33 const client_1 = require("./client"); 34 34 const events_1 = require("events"); … … 41 41 const socket_1 = require("./socket"); 42 42 Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_1.Socket; } }); 43 const debug = debug_1.default("socket.io:server"); 43 const typed_events_1 = require("./typed-events"); 44 const uws_js_1 = require("./uws.js"); 45 const debug = (0, debug_1.default)("socket.io:server"); 44 46 const clientVersion = require("../package.json").version; 45 47 const dotMapRegex = /\.map/; 46 class Server extends events_1.EventEmitter {48 class Server extends typed_events_1.StrictEventEmitter { 47 49 constructor(srv, opts = {}) { 48 50 super(); … … 66 68 this.sockets = this.of("/"); 67 69 this.opts = opts; 68 if (srv )70 if (srv || typeof srv == "number") 69 71 this.attach(srv); 70 72 } … … 95 97 nextFn.value(name, auth, (err, allow) => { 96 98 if (err || !allow) { 97 r un();99 return run(); 98 100 } 99 else { 100 fn(this.parentNsps.get(nextFn.value).createChild(name)); 101 if (this._nsps.has(name)) { 102 // the namespace was created in the meantime 103 debug("dynamic namespace %s already exists", name); 104 return fn(this._nsps.get(name)); 101 105 } 106 const namespace = this.parentNsps.get(nextFn.value).createChild(name); 107 debug("dynamic namespace %s was created", name); 108 // @ts-ignore 109 this.sockets.emitReserved("new_namespace", namespace); 110 fn(namespace); 102 111 }); 103 112 }; … … 111 120 this.clientPathRegex = new RegExp("^" + 112 121 escapedPath + 113 "/socket\\.io(\\.m in|\\.msgpack\\.min)?\\.js(\\.map)?$");122 "/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)"); 114 123 return this; 115 124 } … … 174 183 return this; 175 184 } 185 attachApp(app /*: TemplatedApp */, opts = {}) { 186 // merge the options passed to the Socket.IO server 187 Object.assign(opts, this.opts); 188 // set engine.io path to `/socket.io` 189 opts.path = opts.path || this._path; 190 // initialize engine 191 debug("creating uWebSockets.js-based engine with opts %j", opts); 192 const engine = new engine_io_1.uServer(opts); 193 engine.attach(app, opts); 194 // bind to engine events 195 this.bind(engine); 196 if (this._serveClient) { 197 // attach static file serving 198 app.get(`${this._path}/*`, (res, req) => { 199 if (!this.clientPathRegex.test(req.getUrl())) { 200 req.setYield(true); 201 return; 202 } 203 const filename = req 204 .getUrl() 205 .replace(this._path, "") 206 .replace(/\?.*$/, "") 207 .replace(/^\//, ""); 208 const isMap = dotMapRegex.test(filename); 209 const type = isMap ? "map" : "source"; 210 // Per the standard, ETags must be quoted: 211 // https://tools.ietf.org/html/rfc7232#section-2.3 212 const expectedEtag = '"' + clientVersion + '"'; 213 const weakEtag = "W/" + expectedEtag; 214 const etag = req.getHeader("if-none-match"); 215 if (etag) { 216 if (expectedEtag === etag || weakEtag === etag) { 217 debug("serve client %s 304", type); 218 res.writeStatus("304 Not Modified"); 219 res.end(); 220 return; 221 } 222 } 223 debug("serve client %s", type); 224 res.writeHeader("cache-control", "public, max-age=0"); 225 res.writeHeader("content-type", "application/" + (isMap ? "json" : "javascript")); 226 res.writeHeader("etag", expectedEtag); 227 const filepath = path.join(__dirname, "../client-dist/", filename); 228 (0, uws_js_1.serveFile)(res, filepath); 229 }); 230 } 231 (0, uws_js_1.patchAdapter)(app); 232 } 176 233 /** 177 234 * Initialize engine … … 184 241 // initialize engine 185 242 debug("creating engine.io instance with opts %j", opts); 186 this.eio = engine.attach(srv, opts);243 this.eio = (0, engine_io_1.attach)(srv, opts); 187 244 // attach static file serving 188 245 if (this._serveClient) … … 222 279 */ 223 280 serve(req, res) { 224 const filename = req.url.replace(this._path, "") ;281 const filename = req.url.replace(this._path, "").replace(/\?.*$/, ""); 225 282 const isMap = dotMapRegex.test(filename); 226 283 const type = isMap ? "map" : "source"; … … 242 299 res.setHeader("Content-Type", "application/" + (isMap ? "json" : "javascript")); 243 300 res.setHeader("ETag", expectedEtag); 244 if (!isMap) {245 res.setHeader("X-SourceMap", filename.substring(1) + ".map");246 }247 301 Server.sendFile(filename, req, res); 248 302 } … … 254 308 */ 255 309 static sendFile(filename, req, res) { 256 const readStream = fs_1.createReadStream(path.join(__dirname, "../client-dist/", filename));310 const readStream = (0, fs_1.createReadStream)(path.join(__dirname, "../client-dist/", filename)); 257 311 const encoding = accepts(req).encodings(["br", "gzip", "deflate"]); 258 312 const onError = (err) => { … … 264 318 case "br": 265 319 res.writeHead(200, { "content-encoding": "br" }); 266 readStream.pipe( zlib_1.createBrotliCompress()).pipe(res);267 stream_1.pipeline(readStream, zlib_1.createBrotliCompress(), res, onError);320 readStream.pipe((0, zlib_1.createBrotliCompress)()).pipe(res); 321 (0, stream_1.pipeline)(readStream, (0, zlib_1.createBrotliCompress)(), res, onError); 268 322 break; 269 323 case "gzip": 270 324 res.writeHead(200, { "content-encoding": "gzip" }); 271 stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError);325 (0, stream_1.pipeline)(readStream, (0, zlib_1.createGzip)(), res, onError); 272 326 break; 273 327 case "deflate": 274 328 res.writeHead(200, { "content-encoding": "deflate" }); 275 stream_1.pipeline(readStream, zlib_1.createDeflate(), res, onError);329 (0, stream_1.pipeline)(readStream, (0, zlib_1.createDeflate)(), res, onError); 276 330 break; 277 331 default: 278 332 res.writeHead(200); 279 stream_1.pipeline(readStream, res, onError);333 (0, stream_1.pipeline)(readStream, res, onError); 280 334 } 281 335 } … … 338 392 nsp = new namespace_1.Namespace(this, name); 339 393 this._nsps.set(name, nsp); 394 if (name !== "/") { 395 // @ts-ignore 396 this.sockets.emitReserved("new_namespace", nsp); 397 } 340 398 } 341 399 if (fn) … … 354 412 } 355 413 this.engine.close(); 414 // restore the Adapter prototype 415 (0, uws_js_1.restoreAdapter)(); 356 416 if (this.httpServer) { 357 417 this.httpServer.close(fn); … … 374 434 * Targets a room when emitting. 375 435 * 436 * @param room 437 * @return self 438 * @public 439 */ 440 to(room) { 441 return this.sockets.to(room); 442 } 443 /** 444 * Targets a room when emitting. 445 * 446 * @param room 447 * @return self 448 * @public 449 */ 450 in(room) { 451 return this.sockets.in(room); 452 } 453 /** 454 * Excludes a room when emitting. 455 * 376 456 * @param name 377 457 * @return self 378 458 * @public 379 459 */ 380 to(name) { 381 this.sockets.to(name); 382 return this; 383 } 384 /** 385 * Targets a room when emitting. 386 * 387 * @param name 388 * @return self 389 * @public 390 */ 391 in(name) { 392 this.sockets.in(name); 393 return this; 460 except(name) { 461 return this.sockets.except(name); 394 462 } 395 463 /** … … 414 482 } 415 483 /** 484 * Emit a packet to other Socket.IO servers 485 * 486 * @param ev - the event name 487 * @param args - an array of arguments, which may include an acknowledgement callback at the end 488 * @public 489 */ 490 serverSideEmit(ev, ...args) { 491 return this.sockets.serverSideEmit(ev, ...args); 492 } 493 /** 416 494 * Gets a list of socket ids. 417 495 * … … 429 507 */ 430 508 compress(compress) { 431 this.sockets.compress(compress); 432 return this; 509 return this.sockets.compress(compress); 433 510 } 434 511 /** … … 441 518 */ 442 519 get volatile() { 443 this.sockets.volatile; 444 return this; 520 return this.sockets.volatile; 445 521 } 446 522 /** … … 451 527 */ 452 528 get local() { 453 this.sockets.local; 454 return this; 529 return this.sockets.local; 530 } 531 /** 532 * Returns the matching socket instances 533 * 534 * @public 535 */ 536 fetchSockets() { 537 return this.sockets.fetchSockets(); 538 } 539 /** 540 * Makes the matching socket instances join the specified rooms 541 * 542 * @param room 543 * @public 544 */ 545 socketsJoin(room) { 546 return this.sockets.socketsJoin(room); 547 } 548 /** 549 * Makes the matching socket instances leave the specified rooms 550 * 551 * @param room 552 * @public 553 */ 554 socketsLeave(room) { 555 return this.sockets.socketsLeave(room); 556 } 557 /** 558 * Makes the matching socket instances disconnect 559 * 560 * @param close - whether to close the underlying connection 561 * @public 562 */ 563 disconnectSockets(close = false) { 564 return this.sockets.disconnectSockets(close); 455 565 } 456 566 } … … 469 579 module.exports = (srv, opts) => new Server(srv, opts); 470 580 module.exports.Server = Server; 581 module.exports.Namespace = namespace_1.Namespace; 582 module.exports.Socket = socket_1.Socket;
Note:
See TracChangeset
for help on using the changeset viewer.