* Attach the engine to a µWebSockets.js server * @param app * @param options
(
app /* : TemplatedApp */,
options: AttachOptions & uOptions = {},
)
| 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, |