|
1 | 1 | import debugModule from "debug";
|
2 | 2 | import { AttachOptions, BaseServer, Server } from "./server";
|
3 |
| -import { HttpRequest, HttpResponse } from "uWebSockets.js"; |
| 3 | +import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js"; |
4 | 4 | import transports from "./transports-uws";
|
5 | 5 |
|
6 | 6 | const debug = debugModule("engine:uws");
|
7 | 7 |
|
| 8 | +export interface uOptions { |
| 9 | + /** |
| 10 | + * What permessage-deflate compression to use. uWS.DISABLED, uWS.SHARED_COMPRESSOR or any of the uWS.DEDICATED_COMPRESSOR_xxxKB. |
| 11 | + * @default uWS.DISABLED |
| 12 | + */ |
| 13 | + compression?: number; |
| 14 | + /** |
| 15 | + * Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes. Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest. Disable by using 0. |
| 16 | + * @default 120 |
| 17 | + */ |
| 18 | + idleTimeout?: number; |
| 19 | + /** |
| 20 | + * Maximum length of allowed backpressure per socket when publishing or sending messages. Slow receivers with too high backpressure will be skipped until they catch up or timeout. |
| 21 | + * @default 1024 * 1024 |
| 22 | + */ |
| 23 | + maxBackpressure?: number; |
| 24 | +} |
| 25 | + |
8 | 26 | export class uServer extends BaseServer {
|
9 | 27 | protected init() {}
|
10 | 28 | protected cleanup() {}
|
@@ -43,13 +61,18 @@ export class uServer extends BaseServer {
|
43 | 61 | * @param app
|
44 | 62 | * @param options
|
45 | 63 | */
|
46 |
| - public attach(app /* : TemplatedApp */, options: AttachOptions = {}) { |
| 64 | + public attach( |
| 65 | + app /* : TemplatedApp */, |
| 66 | + options: AttachOptions & uOptions = {} |
| 67 | + ) { |
47 | 68 | const path = (options.path || "/engine.io").replace(/\/$/, "") + "/";
|
48 |
| - |
49 |
| - app |
| 69 | + (app as TemplatedApp) |
50 | 70 | .any(path, this.handleRequest.bind(this))
|
51 | 71 | //
|
52 | 72 | .ws(path, {
|
| 73 | + compression: options.compression, |
| 74 | + idleTimeout: options.idleTimeout, |
| 75 | + maxBackpressure: options.maxBackpressure, |
53 | 76 | maxPayloadLength: this.opts.maxHttpBufferSize,
|
54 | 77 | upgrade: this.handleUpgrade.bind(this),
|
55 | 78 | open: ws => {
|
|
0 commit comments