Get started with Pubb

Your first realtime event.

Start with a prompt. Give your AI coding tool the Pubb guide and let it build the integration around your project.

Build with AI

Copy the prompt into your coding tool. It includes the integration guide, your channel, and the instructions to connect a client and publish from your backend.

Read the Guide

After pasting, change the first line to describe your feature. If your tool cannot open links, attach the Markdown guide instead.

When you’re ready to connect, add your application credentials below. The connection and publishing examples are here whenever you need a reference.

Create an application

Create an application in the Pubb dashboard to get an app ID, a public app key, and an app secret. The public key goes in your client; the secret stays on your server.

Server environment
PUBB_APP_ID=YOUR_APP_ID
PUBB_APP_KEY=YOUR_APP_KEY
PUBB_APP_SECRET=YOUR_APP_SECRET

Keep the secret out of browser code and public environment variables. Replace the placeholders locally with your own credentials.

Connect a client

No package is needed for a native WebSocket connection. This example listens on notifications and prints the events sent to that channel.

client.js
const channel = "notifications";
const socket = new WebSocket(
  "wss://ws.pubb.io/socket?appKey=YOUR_APP_KEY"
);

socket.onopen = () => {
  socket.send(JSON.stringify({ action: "subscribe", channel }));
};

socket.onmessage = ({ data }) => {
  try {
    const packet = JSON.parse(data);
    if (packet.event === "subscription_error") {
      console.error("Subscription failed", packet.data);
      return;
    }
    if (packet.channel !== channel || packet.event) return;
    const event = JSON.parse(packet.data);
    console.log(event.name, event.data);
  } catch (error) {
    console.error("Could not read event", error);
  }
};

socket.onerror = () => console.error("Connection failed");
socket.onclose = () => console.log("Disconnected");
// When your view unmounts: socket.close();

In React, open the socket in an effect and close it in the cleanup. For production, add reconnect backoff, resubscribe after reconnecting, and refresh durable state from your backend.

Publish an event

Run this on your server after checking that the current user is allowed to perform the action. An HTTP request delivers the event to connected clients listening on the channel.

server.js
const response = await fetch(
  `https://api.pubb.io/api/apps/${process.env.PUBB_APP_ID}/events`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.PUBB_APP_SECRET}`,
    },
    body: JSON.stringify({
      channel: "notifications",
      name: "order.created",
      data: { orderId: "1042", message: "On its way!" },
    }),
  }
);
if (!response.ok) throw new Error("Event publish failed");
if (response.status === 207) {
  console.error("Partial delivery", await response.json());
}

channel accepts one name or an array of names. A successful request returns { "success": true, "channels": [...] }. A 207 response includes a failed list when delivery fails for some channels.

Events are delivered to currently connected subscribers. Store message history and other persistent data in your own database.

Choose who can listen

A channel groups the clients that should receive an event. Channel names are isolated by application.

ChannelAccess
notificationsPublic. Anyone with the app key can subscribe.
private-user-42Requires a signature from your backend.
presence-designRequires a signature and a user identity; includes membership events.

For restricted channels, authenticate the user in your backend and check access to the requested channel. Send the socket ID and channel name to the authorization endpoint with your app secret.

Authorization request
POST https://api.pubb.io/api/apps/YOUR_APP_ID/auth
Authorization: Bearer YOUR_APP_SECRET
Content-Type: application/json

{
  "socket_id": "CLIENT_SOCKET_ID",
  "channel_name": "private-user-42"
}

Return the signature to your client and include it in the subscription. Presence authorization also needs a user ID. The complete integration guide covers the protocol and presence payloads.

SDKs for your stack

Dedicated SDK releases and guides are planned for these platforms. Start building today with the AI integration prompt and the WebSocket and HTTP references above.

  • JavaScript / TypeScriptWeb & Node.js
    Coming Soon
  • .NETC# & ASP.NET Core
    Coming Soon
  • SwiftiOS & macOS
    Coming Soon
  • KotlinAndroid & JVM
    Coming Soon
  • PythonPython backends
    Coming Soon
  • GoGo services
    Coming Soon
  • PHPPHP & Laravel
    Coming Soon
  • JavaJava & Spring
    Coming Soon
  • Flutter / DartMobile, web & desktop
    Coming Soon
  • RubyRuby & Rails
    Coming Soon
JavaScript workspace preview

The @pubb/sdk package is available in the Pubb source workspace. Until the renamed package is published to the registry, use the native WebSocket example in other projects.

realtime.ts
import { Pubb } from "@pubb/sdk";

const pubb = new Pubb("YOUR_APP_KEY");
const channel = pubb.subscribe("notifications");
channel.bind("order.created", console.log);
pubb.connect();

More ways to build

Give your coding assistant the integration guide, or use the .NET guide for your C# application. Both include the connection protocol, publishing, and channel authorization.