Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
c4332419f6 Expose maxLifetime from uWebSockets 2024-08-23 01:12:11 -07:00
2 changed files with 33 additions and 0 deletions

View File

@@ -2214,6 +2214,17 @@ declare module "bun" {
*/
idleTimeout?: number;
/**
* Total minutes of activity before a client is automatically disconnected.
*
* `0` disables this feature.
* Must be a number between 0 and 240.
*
* @default 0
* @since Bun v1.1.26
*/
maxLifetime?: number;
/**
* Should `ws.publish()` also send a message to `ws` (itself), if it is subscribed?
*

View File

@@ -3940,6 +3940,28 @@ pub const WebSocketServer = struct {
server.idleTimeout = idleTimeout;
}
}
if (object.get(globalObject, "maxLifetime")) |value| {
if (!value.isUndefinedOrNull()) {
if (!value.isAnyInt()) {
globalObject.throwInvalidArguments("websocket expects maxLifetime to be an integer", .{});
return null;
}
var maxLifetime: u16 = @truncate(@max(value.toInt64(), 0));
if (maxLifetime > 240) {
globalObject.throwInvalidArguments("websocket expects maxLifetime to be 240 minutes or less (4 hours). To disable maxLifetime, set it to 0.", .{});
return null;
} else if (maxLifetime > 0) {
// uws does not allow maxLifetime to be between (0, 8),
// since its timer is not that accurate, therefore round up.
maxLifetime = @max(maxLifetime, 8);
}
server.maxLifetime = maxLifetime;
}
}
if (object.get(globalObject, "backpressureLimit")) |value| {
if (!value.isUndefinedOrNull()) {
if (!value.isAnyInt()) {