Quickstart
This is the “hello room”: connect two peers to a shared room and watch their presence sync live. No server code — the default room is a pure relay.
-
Install the client
@silt/clientis vanilla TypeScript with no framework dependency.Terminal window npm install @silt/clientTerminal window pnpm add @silt/clientTerminal window yarn add @silt/clientTerminal window bun add @silt/client -
Join a room
joinRoomresolves once you’re connected and the join snapshot has arrived, soroom.peersis already populated with everyone else in the room.import { joinRoom } from "@silt/client";const room = await joinRoom("https://demo.silt.run/room/graveyard", {id: "alice", // stable, client-supplied identity});console.log(room.peers); // [{ id, state }] — the peers already hereThe
idis yours to choose and must be stable: reconnecting is just callingjoinRoomagain with the sameid. -
Send and receive presence
Presence is the unreliable, latest-wins lane — perfect for cursor positions, camera state, or anything you publish many times a second. Set your own state with
presence.set, and listen for everyone else’s withon("presence").// listen for other peers' latest presenceroom.on("presence", (peerId, state) => {console.log(peerId, "is at", state);});// publish your own (call this as often as you like — droppable, latest-wins)room.presence.set({ x: 10, y: 20, heading: 90 }); -
Send reliable events (optional)
When you can’t afford to drop a message — a chat line, a discrete action — use the reliable, ordered events lane.
room.on("event", (peerId, event) => {console.log(peerId, "did", event);});room.events.send({ type: "absorb", target: "bob" }); -
React to peers joining and leaving
room.on("join", (peer) => console.log(peer.id, "joined"));room.on("leave", (peerId, reason) => {// reason: "left" (clean) | "timeout" (session died)console.log(peerId, "left:", reason);});
The whole thing
Section titled “The whole thing”Open this in two browser tabs (over HTTPS / a secure context) and you have a live two-peer room:
import { joinRoom } from "@silt/client";
const room = await joinRoom("https://demo.silt.run/room/graveyard", { id: "alice" });
room.on("presence", (peerId, state) => { console.log(peerId, "is at", state);});
room.presence.set({ x: 10, y: 20, heading: 90 });When you’re done, release the connection:
room.close();Next steps
Section titled “Next steps”- The two-lane model — when to use presence vs events.
- API reference — every method, event, and option.
- Run your own — self-host the relay locally.