MCPcopy
hub / github.com/socketio/socket.io / attach

Method attach

packages/socket.io/lib/index.ts:482–516  ·  packages/socket.io/lib/index.ts::Server.attach

* Attaches socket.io to a server or port. * * @param srv - server or port * @param opts - options passed to engine.io * @return self

(
    srv: TServerInstance | number,
    opts: Partial<ServerOptions> = {},
  )

Source from the content-addressed store, hash-verified

480 * @return self
481 */
482 public attach(
483 srv: TServerInstance | number,
484 opts: Partial<ServerOptions> = {},
485 ): this {
486 if (class="st">"function" == typeof srv) {
487 const msg =
488 class="st">"You are trying to attach socket.io to an express " +
489 class="st">"request handler function. Please pass a http.Server instance.";
490 throw new Error(msg);
491 }
492
493 class="cm">// handle a port as a string
494 if (Number(srv) == srv) {
495 srv = Number(srv);
496 }
497
498 if (class="st">"number" == typeof srv) {
499 debug(class="st">"creating http server and binding to %d", srv);
500 const port = srv;
501 srv = createServer((_req, res) => {
502 res.writeHead(404);
503 res.end();
504 });
505 srv.listen(port);
506 }
507
508 class="cm">// merge the options passed to the Socket.IO server
509 Object.assign(opts, this.opts);
510 class="cm">// set engine.io path to `/socket.io`
511 opts.path = opts.path || this._path;
512
513 this.initEngine(srv, opts);
514
515 return this;
516 }
517
518 /**
519 * Attaches socket.io to a uWebSockets.js app.

Callers 8

constructorMethod · 0.95
listenMethod · 0.95
redis.tsFile · 0.45
in-memory.tsFile · 0.45
worker.jsFile · 0.45
initServerFunction · 0.45
server.jsFile · 0.45

Calls 6

initEngineMethod · 0.95
debugFunction · 0.85
createServerFunction · 0.85
listenMethod · 0.80
writeHeadMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected