Bound admission, work, and slow peers

Documentation for Redweb 0.13.3. Install that exact version when following these examples.

Production controls are opt-in and route-local. Authenticate before upgrade, cap every queue, and use one heartbeat scheduler for the whole route.

This pattern demonstrates one API area. Application-specific names, credentials, assets, and policies may need to be supplied. Complete starter recipes include all required application files.

js
class MatchRoute extends SocketRoute {
  constructor() {
    super({
      path: '/match',
      handlers: [InputHandler],
      admission: {
        origins: ['https://game.example'],
        timeoutMs: 3000,
        authenticate: (request, { signal }) =>
          verifyPlayer(request, signal),
      },
      maxPendingUpgrades: 64,
      limits: {
        maxConnections: 5000,
        maxBufferedBytes: 1024 * 1024,
        maxPendingMessages: 64,
        messageRate: { capacity: 60, refillPerSecond: 30 },
      },
      orderedMessages: true,
      heartbeat: { intervalMs: 30000, timeoutMs: 10000 },
      websocketOptions: { maxPayload: 64 * 1024 },
    })
  }
}

Notes and boundaries

  • Authentication completes before onInitialContact.
  • Ordered overflow closes pending work synchronously.
  • Disabled controls add no per-connection queue or timer.