TypeScript / JavaScript SDK

Browser and Node.js 22+ client for Asobi. Event-emitter API over WebSocket, typed REST APIs, auto-reconnect.

View on GitHub

Installation

npm install github:widgrensit/asobi-js

Quickstart

Authenticate, open a WebSocket, queue in matchmaker, and subscribe to match.state:

import { Asobi } from "@widgrensit/asobi";

const asobi = new Asobi({ baseUrl: "http://localhost:8084" });
const { access_token } = await asobi.auth.register({
    username: "player1", password: "secret",
});

const ws = asobi.websocket({ token: access_token });
ws.on("match.state", (s) => console.log("tick", s.tick));
await ws.connect();
ws.sendFire("matchmaker.add", { mode: "arena" });

Connect to a world

Use the WebSocket event emitter for world.* events. The world.terrain event delivers base64-encoded chunks at specific grid coordinates - decode once per chunk and cache.

ws.on("world.joined", ({ world_id, player_count }) =>
    console.log(`joined ${world_id} (${player_count})`));
ws.on("world.tick", ({ tick, updates }) => applyDeltas(updates));
ws.on("world.terrain", ({ coords, data }) =>
    loadChunk(coords[0], coords[1], data));

await ws.connect();
ws.sendFire("world.find_or_create", { mode: "open-world" });

Reference

All submodules (auth, players, matches, matchmaker, worlds, dm, leaderboards, economy, inventory, social, chat, tournaments, votes, notifications, storage) are typed and exported from @widgrensit/asobi.