A small TypeScript library for TV and web games
Players scan a QR code on the TV and their phone becomes a gamepad. Input streams over a WebRTC DataChannel, and when the network blocks that, a WebSocket relay carries it instead. Your game never has to know which one it got.
npm install github:MaanavKrishna/couchpadScroll through four networks and watch what couchpad sends. Every line in the log is a real couchpad message.
Phones lock, refresh and wander between rooms. These are the numbers couchpad uses to keep a seat alive, straight from the source.
peer.ts: OPEN_TIMEOUT_MSutil.ts: RELAY_CHUNK_BYTESclient.ts: INPUT_HZclient.ts: KEEPALIVE_MSclient.ts: PING_INTERVAL_MSsignaling.ts: BACKOFF_MSclient.ts: RELIABLE_QUEUE_MAXutil.ts: MAX_DRAW_BYTESThis joystick runs the same rules as CouchClient.sendInput(): moves are coalesced to 30 Hz, a button edge goes out at once, and a held control is resent every 100 ms.
The TV creates a room and tells each phone which controls to show. The phone renders them and streams input back.
import { CouchHost } from 'couchpad';
const host = new CouchHost({ wsUrl: 'wss://your-server/ws', household: 'living-room' });
const { code } = await host.create(); // show a QR to https://your-site/?room=CODE
host.on('player', (id: string) => host.sendTo(id, {
t: 'screen', name: 'play',
data: { widgets: [{ kind: 'joystick', id: 'move' }, { kind: 'button', id: 'jump', label: 'JUMP' }] },
}));
host.on('input', (id: string, frame) => console.log(id, frame.axes, frame.buttons));import { CouchClient, mountController, type ControlWidget } from 'couchpad';
const client = new CouchClient({ wsUrl: 'wss://your-server/ws' });
client.onMessage((m) => {
if (m.t !== 'screen') return;
const { widgets } = m.data as { widgets: ControlWidget[] };
mountController(document.body, widgets, (f) => client.sendInput(f));
});
const room = new URLSearchParams(location.search).get('room')!;
await client.join(room, 'Asha'); // client.mode is now 'direct' or 'relay'npm install github:MaanavKrishna/couchpadCadabra is a Fire TV party game where the room invents the game and then plays it. Every phone joins by QR and becomes the controller through couchpad.
It carries input from up to 4 phones to a Fire TV Stick HD, measured at 13 to 16 ms on a home network. Its production signaling runs on API Gateway WebSocket, Lambda and DynamoDB, which is where the 28 KB chunking came from.
See Cadabra on GitHub