Skip to content

Change ws engine of server to bun #227

Description

@Exeloo

Scope

  • TCPServer and UDPServer move from ws + node:https to Bun.serve()
  • The TLS/non-TLS branches collapse into one call with optional tls; the duplicated
    startWebSocketServer helper is removed
  • Per-connection state moves to ws.data; server.requestIP() replaces
    request.socket.remoteAddress
  • Remove ws and @types/ws; add @types/bun
  • tsconfig.server.json gets types: ["bun"] and skipLibCheck: true (the latter is a
    real loosening — node-datachannel's .d.ts conflicts with the DOM lib)
  • __clear() teardown is implemented so the servers actually release their ports
  • Tests move from vi.mock("ws") to vi.stubGlobal("Bun", …)Bun is a global, so
    vi.mock cannot intercept it

Breaking change

@nanoforge-dev/network/server now requires Bun and no longer runs on Node, as accepted
in this issue. The client entry point is unaffected. Note @nanoforge-dev/loader-server
is currently built with bun build --target node, so it must move before nf start
works with this.

Scope boundary

Bun.serve() speeds up signalling only. The UDP data channel is libdatachannel's own
C++ sockets and never touches Bun's networking — benchmarked at 20k msgs × 200 B, three
runs each: Bun 52.8/49.8/51.5k msg/s vs Node 46.8/48.3/49.9k msg/s. The ranges overlap;
there is no meaningful difference on the media path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions