folkwaysDocs

JavaScript SDK

@folkwaysio/realtime connects web, mobile and Node.js apps to Folkways: publish and subscribe to live events with reconnects, token refresh and replay handled for you.

@folkwaysio/realtime is the JavaScript and TypeScript client for Folkways, published on npm. The shorter @folkways/realtime package name was not available on npm, so we publish under the @folkwaysio scope.

Your app connects once, then publishes and subscribes to topics. The SDK keeps the connection alive for you: it picks a transport, reconnects after network drops, refreshes tokens before they expire and resumes every subscription where it left off.

It runs in browsers, Node.js 20+, Deno, Bun and React Native. It ships ESM, CommonJS, TypeScript types and a browser bundle.

import { Folkways } from '@folkwaysio/realtime';

const client = new Folkways.Realtime({ url: 'https://rte.example.com', authUrl: '/api/realtime-token' });
await client.connect();

const room = client.topic('chat/lobby');
room.subscribe((msg) => console.log(msg.publisher, msg.data));
await room.publish('message', { text: 'hello' });

What you need

  1. A Folkways account with a segment, a signing key and topic rules. Set up the dashboard.
  2. A small endpoint on your backend that signs a token for the signed-in user. The SDK's server part does this in a few lines: see Issue tokens from your backend.
  3. The SDK in your app.

Apps that only display public data, such as a live scoreboard, can skip the backend and use a publishable key instead.

Start here

On this page