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

Method attach

packages/engine.io/lib/userver.ts:71–100  ·  packages/engine.io/lib/userver.ts::uServer.attach

* Attach the engine to a µWebSockets.js server * @param app * @param options

(
    app /* : TemplatedApp */,
    options: AttachOptions & uOptions = {},
  )

Source from the content-addressed store, hash-verified

69 * @param options
70 */
71 public attach(
72 app /* : TemplatedApp */,
73 options: AttachOptions & uOptions = {},
74 ) {
75 const path = this._computePath(options);
76 (app as TemplatedApp)
77 .any(path, this.handleRequest.bind(this))
78 class="cm">//
79 .ws<{ transport: any }>(path, {
80 compression: options.compression,
81 idleTimeout: options.idleTimeout,
82 maxBackpressure: options.maxBackpressure,
83 maxPayloadLength: this.opts.maxHttpBufferSize,
84 upgrade: this.handleUpgrade.bind(this),
85 open: (ws) => {
86 const transport = ws.getUserData().transport;
87 transport.socket = ws;
88 transport.writable = true;
89 transport.emit(class="st">"ready");
90 },
91 message: (ws, message, isBinary) => {
92 ws.getUserData().transport.onData(
93 isBinary ? message : Buffer.from(message).toString(),
94 );
95 },
96 close: (ws, code, message) => {
97 ws.getUserData().transport.onClose(code, message);
98 },
99 });
100 }
101
102 override _applyMiddlewares(
103 req: any,

Callers 1

attachAppMethod · 0.95

Calls 4

bindMethod · 0.80
emitMethod · 0.65
onDataMethod · 0.45
onCloseMethod · 0.45

Tested by

no test coverage detected