Docs

Quickstart

From an API key to a live subscription in a few minutes.

Foony Realtime is a managed realtime messaging API. You connect over WebSocket, attach to named channels, and publish JSON messages that fan out to every subscriber in milliseconds.

Create an API key

Sign in to the dashboard, create an app, and copy an API key. A key looks like this:

myapp.kid_a1b2c3:sk_secretpart

The part before the colon is the public key id. The part after is the private half, so treat the whole string like a password. Keys work from servers and trusted contexts right away and never expire. For untrusted browsers you will mint short-lived tokens later, but you do not need them to get started.

Install the SDK

npm install @foony/realtime

The package ships browser and Node builds, TypeScript types included.

Connect and subscribe

import { Realtime } from '@foony/realtime';

const realtime = new Realtime({
  key: 'myapp.kid_a1b2c3:sk_secretpart',
  clientId: 'user-123',
});

const channel = realtime.channels.get('chat:lobby');

channel.subscribe((message) => {
  console.log(message.name, message.data, message.clientId);
});

Subscribing attaches the channel automatically. Channel names use colons for hierarchy, like chat:lobby or game:4821.

Publish

await channel.publish('chat', { text: 'hello' });

Every subscriber on chat:lobby receives the message, including this connection. The promise resolves once the service has accepted the message.

Add presence

channel.presence.on((event) => {
  console.log(event.action, event.clientId, event.data);
});

await channel.presence.enter({ name: 'Acorn' });

Presence tracks which clients are on the channel. Listeners receive the current members first, then live enter, update, and leave transitions.

Next steps