RealPeha / nengi-bun-server-adapter

Bun web socket server network adapter for nengi v2

Home Page:https://npmjs.com/package/nengi-bun-server-adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Bun web socket server network adapter for nengi v2

https://npmjs.com/package/nengi-bun-server-adapter


Languages

Language:TypeScript 100.0%