Tablebox Docs

Get started

You install the CLI and run tablebox init in your app's folder, which makes a project with no account and prints the token your pages connect with. You write a browser page that makes a call between everyone who opens it, open it in two tabs, and look at the call from outside the app. Then you keep the project by claiming it in a browser, add a teammate, and add a backend that signs tokens. Overview says how Tablebox behaves, and Reference gives every command and value.

1. Install the CLI

The CLI, tablebox, is one executable for macOS, Linux and Windows. The install script puts it in ~/.tablebox/bin:

curl -fsSL https://www.stg.tablebox.io/cli/install.sh | sh

The script needs no sudo. When ~/.tablebox/bin is not on PATH already, it adds it in zsh's and bash's startup files (~/.zshenv, ~/.bashrc and ~/.profile), so new shells find tablebox, and prints the executable's path last. In a shell that was open before, or another shell, run the CLI by that path, ~/.tablebox/bin/tablebox.

On Windows (x64), the PowerShell script beside it does the same, putting tablebox.exe in ~\.tablebox\bin. In PowerShell:

irm https://www.stg.tablebox.io/cli/install.ps1 | iex

tablebox help lists its commands, and Reference gives each of them. The npm package named tablebox is not Tablebox's CLI: do not install it or run it with npx.

2. Start a project

In your app's folder:

tablebox init

init needs no account. It makes a key in the folder, and Manager makes a temporary project of it, named after the folder; only the key's public key leaves the folder. init writes the key, which names the project, into .env.local as TABLEBOX_KEY, and prints a token for your pages, signed with the key (Projects, owners and keys).

TABLEBOX_KEY is the folder's key, and the only secret your app holds: keep .env.local out of version control (init says so when the folder is a git repository that does not ignore it) and out of the folder you serve (step 3). The token is no secret: it sits in your pages.

A temporary project has small ceilings, 1 GB a month and 10 connections, and every Relay deletes it 72 hours after init. init prints when, and step 6 keeps it. While Tablebox holds as many temporary projects as it takes, init says it is busy and makes nothing: run it again later.

The token lets a page into any room the page names, for trying: whoever opens a page that carries it enters that room, reads it and publishes at {kind}/{name}/{their ID} there (Connecting). tablebox token --room 'rooms/*' --publish prints a narrower one, for rooms such as rooms/42, signed with the same key; leave out --publish for a token that only reads. Every token for pages works until the key that signed it is replaced (step 8).

In a folder whose .env.local already has TABLEBOX_KEY, init says so and does nothing else; tablebox token --room '**' --publish prints a token like the first.

3. A page in a call

The SDK is the package tablebox.io. Install it in your app's folder, with esbuild to bundle and serve the page:

npm install esbuild https://www.stg.tablebox.io/sdk/tablebox.io-0.1.0-6e04b9a1e8b9.tgz

npm may say that esbuild's install script is not covered by allowScripts and did not run. esbuild works without it: its program comes in a package of its own for your platform.

The SDK runs in browsers, and in Node 22.18 or later, the versions its engines name (npm warns with EBADENGINE on others).

Save the page as page.ts, with the token init printed in place of …the token init printed…. The page's room is the call named after # in its address:

TypeScript, browser · page.ts
// Shows a call between everyone who opens the page: each person sends their camera and microphone,
// and the page shows everyone, each in a video of their own, this person's own without sound.
//
// This is the sample of Get started. It connects with the token `tablebox init` printed, which lets
// a page into any room it names and gives each tab an ID of its own. The room is the call named
// after `#` in the address, a new one when there is none. Media.show plays each person's picture at
// once and the others' sound as soon as the browser lets the page play it.
import { connect, Media } from 'tablebox.io';

if (!location.hash) location.hash = crypto.randomUUID();
const connection = await connect('…the token init printed…', { room: `calls/${location.hash.slice(1)}` });
document.getElementById('me')!.textContent = connection.id;
addEventListener('pagehide', () => connection.close());

Media.publish(connection, 'call', await navigator.mediaDevices.getUserMedia({ video: true, audio: true }));

const videos = new Map<string, HTMLVideoElement>();
Media.subscribe(connection, 'call', (id, stream) => {
  let video = videos.get(id);
  if (!stream) return void (video?.remove(), videos.delete(id));
  if (!video) {
    video = document.body.appendChild(document.createElement('video'));
    video.dataset.id = id;
    videos.set(id, video);
  }
  // This person's own plays without sound, so that they do not hear themselves.
  Media.show(video, stream);
});

Each person sends their camera and microphone under the name call, and the page shows everyone who does, each in a <video> of their own, with Media.show (Media).

.env.local sits in the app's folder and holds the folder's key, so the page is served from a folder of its own, public/, and only that folder is served. Save this as page.html in public/:

<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>video { width: 320px; max-width: 100%; }</style>
<p id="me"></p>
<script type="module" src="page.js"></script>

One command bundles page.ts into public/page.js, serves public/, and bundles again whenever a file changes:

npx esbuild page.ts --bundle --format=esm --outdir=public --servedir=public --serve=127.0.0.1:3000 --watch=forever

It serves page.js from memory, writing no file, until you stop it. --watch=forever keeps it serving where nothing reads its input, as when an AI tool runs it: without it, esbuild stops serving once its standard input closes. To stop it, press Ctrl-C where it runs, or:

kill $(lsof -ti tcp:3000 -sTCP:LISTEN)

Stopping only npx, as kill -9 of its process does, leaves esbuild serving.

To publish the page, the same command without --servedir, --serve and --watch writes public/page.js; put public/ on any host that serves files over https://. For that host and for the server above, browsers without WebCodecs audio also need three files of the SDK's in public/, beside page.js (Reference).

A page with no bundler can load the SDK from a CDN instead (Reference).

4. Open it in two tabs

Open http://127.0.0.1:3000/page.html in a tab. The page names a new call after # in its address: open that address in a second tab. Each shows both people, its own without sound, and a tab with another call after # is in a room of its own. The address is 127.0.0.1, not localhost: where another server already listens on port 3000 over IPv6, localhost can reach that one instead, and you would see another app. Browsers give WebTransport, the camera and the microphone to secure pages only: https:// pages, and pages of 127.0.0.1 and localhost. So a phone, which cannot reach your machine's 127.0.0.1, opens the page through a host that serves it over https://, or through a tunnel that gives a port of your machine an https:// address.

The picture shows at once. Most browsers play a page's sound, and run its microphone, only after the first click, tap or key press in it, so click once anywhere in each tab (Media).

#me shows the tab's ID, connection.id, which is set once connect() resolves. Each tab has its own, and a reload keeps it (Connecting). Close one tab: it leaves the other's page at once. One whose connection drops leaves once the connection has gone silent for a while (Disconnects and departures).

5. Look from outside the app

The CLI looks at a room of the folder's project as a participant reading it. While the two tabs are open, where {call} is what follows # in their address:

tablebox ls calls/{call}

prints the paths published in the room, one per line, here media/call/{id} for each tab, then exits. --watch keeps printing + {path} and - {path} as paths come and go. Reference gives what else the CLI shows, and when a connection is refused, Close codes say what to do.

6. Keep the project

A person keeps the project by claiming it, in a browser. In the app's folder:

tablebox claim

prints an address on Console, with a code that works for 15 minutes, or until Manager restarts. Open it, sign in with GitHub, and accept the project it shows. You then own the project: it is no longer deleted, gets an owned project's ceilings (100 GB a month and 100 connections), and counts against your ceiling of projects, 3 (Reference). The folder's key stays, and .env.local does not change. Run tablebox claim again: it names who claimed the project, or, while nobody has, prints a new address. Console, at its address in Reference, lists the projects you own once you sign in.

7. Add a teammate

A teammate's copy of the app uses the same TABLEBOX_KEY line: give it to them as your team shares its other secrets. When someone leaves, tablebox key (step 8) replaces the key for everyone: give the others the new line.

A project's owners are people, and every owner may do everything with it (Projects, owners and keys). Once you own the project, a teammate signs in to Console once, and you add them by their GitHub login with tablebox api POST /projects/{project}/owners '{"user": "{login}"}', where {project} is the project's ID, project of TABLEBOX_KEY. They then see the project in Console. tablebox api GET /projects/{project}/owners lists the owners with their user IDs, and tablebox api DELETE /projects/{project}/owners/{user} removes one; a project keeps at least one owner.

8. A backend that signs tokens

The token init printed lets in whoever opens the page, each tab with an ID that says nothing of who they are. When your app decides who someone is and which room they enter, your backend signs a token for each person instead, with the folder's key, TABLEBOX_KEY (the token's form).

Whoever loads a page has its token, so the rooms your backend guards must lie outside the rooms of every token for pages, and init's lets into any room. tablebox key replaces the folder's key in .env.local with a new one and deletes the old, which stops every token the old key signed, init's among them: pages still open with them close with invalid-token. Make your pages' tokens after it, for rooms outside the backend's. The backend runs on the Node of step 3, which runs the TypeScript file below once the folder's package.json makes it an ES module:

tablebox key
npm pkg set type=module

This backend serves public/, and nothing outside it, so never .env.local, and at /token gives a user a token for a room with sign of tablebox.io/server. The ID is the user, ~ and the tab's own (Tokens and rights):

TypeScript, Node · backend.ts
// Runs the developer's own backend: it serves the page from public/, and gives each user a token
// for a room, with which each of their tabs publishes at its own ID and reads the room.
//
// It listens on 127.0.0.1:8000 and signs with TABLEBOX_KEY, the folder's key in .env.local.
// It serves the files of public/ and nothing outside it, so never .env.local.
import { readFile } from 'node:fs/promises';
import { createServer } from 'node:http';
import { extname, resolve, sep } from 'node:path';
import { sign } from 'tablebox.io/server';

const served = resolve('public');
const types: Record<string, string> = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript', '.wasm': 'application/wasm', '.json': 'application/json' };

createServer(async (request, response) => {
  const url = new URL(request.url!, 'http://localhost');
  if (url.pathname === '/token') {
    // Decide here who is asking, with your own sign-in, and whether they may enter the room; this sample trusts the query.
    const [user, room] = ['user', 'room'].map(name => url.searchParams.get(name) ?? '');
    const token = await sign(process.env.TABLEBOX_KEY!, { user, room: `rooms/${room}` }).catch(() => '');
    return void (token ? response.end(token) : response.writeHead(400).end());
  }
  const file = resolve(served, `.${url.pathname}`);
  const body = file.startsWith(served + sep) ? await readFile(file).catch(() => undefined) : undefined;
  if (!body) return void response.writeHead(404).end();
  response.writeHead(200, { 'content-type': types[extname(file)] ?? 'application/octet-stream' }).end(body);
}).listen(8000, '127.0.0.1');

Stop the server of step 3, and run the backend with the values of .env.local:

node --env-file=.env.local backend.ts

It prints nothing, and serves at 127.0.0.1:8000 until you stop it. Run it again after each tablebox key, which it reads only when it starts.

In the page, connect with a function that asks the backend for a token, so that the SDK asks it before each connection attempt (Connecting); connection.id is the user, ~ and the tab's own:

TypeScript, browser · connect.ts
// Shows how a web page connects as the person its backend decides, asking the backend for a fresh
// token before every attempt, and reports the connection's state as it changes.
//
// The token names the room and the Relays, so the page needs nothing else. Its ID is the user, `~`
// and the tab's own, which the SDK makes from a secret it keeps for each tab.
import { connect } from 'tablebox.io';

export async function connectAs(user: string, room: string) {
  const query = new URLSearchParams({ user, room });
  const connection = await connect(async () => {
    const reply = await fetch(`/token?${query}`);
    if (!reply.ok) throw new Error(`token: ${reply.status}`);
    return reply.text();
  });
  connection.onStatus(status => console.log(`${connection.id}: ${status} ${connection.reason?.name ?? ''}`.trim()));
  return connection;
}

In page.ts, import connectAs from ./connect.ts, and connect with connectAs('alice', '42') in place of connect(…), giving the user your app signed in and their room. The backend serves the page, so bundle it into public/ with the command of step 3 without --servedir, --serve and --watch, again after each change:

npx esbuild page.ts --bundle --format=esm --outdir=public

Then open http://127.0.0.1:8000/page.html.

Running the samples

Every sample on these pages runs in the app's folder of these steps. board.ts, hall.ts and stage.ts are pages of their own, each with the token it names in place of …the token…, as in page.ts. Once step 8 has replaced the key, give board.ts one from tablebox token --room 'boards/*' --publish, and hall.ts one for 'halls/*'. The command of step 3 bundles them too when they are named after page.ts (npx esbuild page.ts board.ts …), and each needs an HTML file of its name in public/, which loads its .js as page.html loads page.js. nearby.ts and connect.ts are imported by a page, as page.ts imports connect.ts in step 8. Node samples sign their tokens with TABLEBOX_KEY, which names the project, the Relays and Manager, so run them with node --env-file=.env.local status.ts. The Node samples of the Overview meet in the room rooms/lobby; manage.ts acts on rooms/42 and rooms/41, and backend.ts signs for rooms/{room}. They run on the Node of step 3, as ES modules in a folder whose package.json has "type": "module" (step 8).