TypeScript / JavaScript SDK

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

View on GitHub

Installation

npm install @asobi/client

Quickstart

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

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

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

const ws = asobi.websocket();
ws.on("match.state", (s) => console.log("tick", s.tick));
await ws.connect();
await asobi.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 @asobi/client.