0.1.0 • Published 8 months ago

nengi-bun-server-adapter v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Bun web socket server network adapter for nengi v2

Warning This adapter is written and tested only on nengi v2.0.0-alpha.138, this is an unstable version, the api of which may change in the future

Install

bun add nengi-bun-server-adapter

Usage

Server-side

import { Instance, Context } from "nengi";
import { BunServerAdapter } from "nengi-bun-server-adapter";

const ctx = new Context();
// <...>
const instance = new Instance(ctx);

const adapter = new BunServerAdapter(instance.network);
adapter.listen(PORT);

Adapter internally uses Bun.serve so if you want to pass additional options for the Bun.serve you can pass them as the second argument

const adapter = new BunServerAdapter(instance.network, {
  lowMemoryMode: true,
  websocket: {
    sendPings: false,
  },
});

All available Bun.serve options is described here https://bun.sh/docs/api/websockets

Client-side

For client-side you need any web socket adapter, for example nengi-websocket-client-adapter