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

Method constructor

packages/socket.io/lib/index.ts:301–340  ·  packages/socket.io/lib/index.ts::Server.constructor
(
    srv: undefined | Partial<ServerOptions> | TServerInstance | number,
    opts: Partial<ServerOptions> = {},
  )

Source from the content-addressed store, hash-verified

299 opts?: Partial<ServerOptions>,
300 );
301 constructor(
302 srv: undefined | Partial<ServerOptions> | TServerInstance | number,
303 opts: Partial<ServerOptions> = {},
304 ) {
305 super();
306 if (
307 class="st">"object" === typeof srv &&
308 srv instanceof Object &&
309 !(srv as Partial<HTTPServer>).listen
310 ) {
311 opts = srv as Partial<ServerOptions>;
312 srv = undefined;
313 }
314 this.path(opts.path || class="st">"/socket.io");
315 this.connectTimeout(opts.connectTimeout || 45000);
316 this.serveClient(false !== opts.serveClient);
317 this._parser = opts.parser || parser;
318 this.encoder = new this._parser.Encoder();
319 this.opts = opts;
320 if (opts.connectionStateRecovery) {
321 opts.connectionStateRecovery = Object.assign(
322 {
323 maxDisconnectionDuration: 2 * 60 * 1000,
324 skipMiddlewares: true,
325 },
326 opts.connectionStateRecovery,
327 );
328 this.adapter(opts.adapter || SessionAwareAdapter);
329 } else {
330 this.adapter(opts.adapter || Adapter);
331 }
332 opts.cleanupEmptyChildNamespaces = !!opts.cleanupEmptyChildNamespaces;
333 this.sockets = this.of(class="st">"/");
334 if (srv || typeof srv == class="st">"number")
335 this.attach(srv as TServerInstance | number);
336
337 if (this.opts.cors) {
338 this._corsMiddleware = corsMiddleware(this.opts.cors);
339 }
340 }
341
342 get _opts() {
343 return this.opts;

Callers

nothing calls this directly

Calls 6

pathMethod · 0.95
connectTimeoutMethod · 0.95
serveClientMethod · 0.95
adapterMethod · 0.95
ofMethod · 0.95
attachMethod · 0.95

Tested by

no test coverage detected