Skip to content

Commit 49bb7cf

Browse files
yosiatdarrachequesne
authored andcommitted
fix(uws): expose additional uWebSockets.js options (#634)
You can now pass additional options: ```js const { App } = require("uWebSockets.js"); const { uServer } = require("engine.io"); const app = new App(); const server = new uServer(); server.attach(app, { compression: uWS.DEDICATED_COMPRESSOR_128KB, // defaults to none idleTimeout: 60, // defaults to 120 maxBackpressure: 8 * 1024 // defaults to 1024 * 1024 }); app.listen(3000); ``` Related: #633
1 parent 8b4d6a8 commit 49bb7cf

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

lib/userver.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
import debugModule from "debug";
22
import { AttachOptions, BaseServer, Server } from "./server";
3-
import { HttpRequest, HttpResponse } from "uWebSockets.js";
3+
import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js";
44
import transports from "./transports-uws";
55

66
const debug = debugModule("engine:uws");
77

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+
826
export class uServer extends BaseServer {
927
protected init() {}
1028
protected cleanup() {}
@@ -43,13 +61,18 @@ export class uServer extends BaseServer {
4361
* @param app
4462
* @param options
4563
*/
46-
public attach(app /* : TemplatedApp */, options: AttachOptions = {}) {
64+
public attach(
65+
app /* : TemplatedApp */,
66+
options: AttachOptions & uOptions = {}
67+
) {
4768
const path = (options.path || "/engine.io").replace(/\/$/, "") + "/";
48-
49-
app
69+
(app as TemplatedApp)
5070
.any(path, this.handleRequest.bind(this))
5171
//
5272
.ws(path, {
73+
compression: options.compression,
74+
idleTimeout: options.idleTimeout,
75+
maxBackpressure: options.maxBackpressure,
5376
maxPayloadLength: this.opts.maxHttpBufferSize,
5477
upgrade: this.handleUpgrade.bind(this),
5578
open: ws => {

0 commit comments

Comments
 (0)