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.
After pasting, change the first line to describe your feature. If your tool cannot open links, attach the Markdown guide instead.
Download guide for AI (.md)When you’re ready to connect, add your application credentials below. The connection and publishing examples are here whenever you need a reference.
Connect your assistant with MCP
Add pubb’s hosted MCP URL to your coding assistant, sign in and select your application. The assistant can read its public settings and integration guide without an MCP package installation.
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.
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.
const channel = "notifications";
const socket = new WebSocket(
"wss://ws.pubb.io/socket?appKey=YOUR_APP_KEY&protocol=2"
);
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.
Read the complete wire protocol for authentication, subscribe/unsubscribe messages, publishing, heartbeat, reconnection and error handling without an SDK.
Publish an event
Run this on your server after checking that the current user is allowed to perform the action. Pubb accepts the event for processing and sends it to currently connected subscribers.
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.status !== 202) throw new Error("Event publish failed");
const result = await response.json();
console.log("Accepted publication", result.publicationId);
channel accepts one name or up to 100 names. HTTP 202 returns success, accepted, channels, publicationId and duplicate. Acceptance is not a delivery receipt. Event data is limited to 10 KiB of UTF-8 JSON.
Use an Idempotency-Key header when retrying the same publication. Optional socket_id excludes one connection from delivery.
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.
| Channel | Access |
|---|---|
notifications | Public. Anyone with the app key can subscribe. |
private-user-42 | Requires a signature from your backend. |
presence-design | Requires 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.
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. Choose your language in the SDK guides for authorization examples.
SDKs for your stack
Choose your language or engine for installation steps, examples and channel authorization. Client SDKs subscribe in your app; server SDKs publish and sign subscriptions in your trusted backend.
Install JavaScript 0.3.0 from npm, .NET 0.3.0 from NuGet, or download Unity 0.2.0. Follow each SDK guide for the remaining platforms.
- UnityUnity · C# · WebGL · ClientGitHub
- JavaScript / TypeScriptWeb & Node.js · Client & serverGitHub
- .NETC# & ASP.NET Core · ServerGitHub
- SwiftiOS, macOS, tvOS & watchOS · ClientGitHub
- KotlinAndroid & JVM · ClientGitHub
- PythonPython backends · ServerGitHub
- GoGo services · ServerGitHub
- PHPPHP & Laravel · ServerGitHub
- JavaJava & Spring · ServerGitHub
- Flutter / DartMobile, web & desktop · ClientGitHub
- RubyRuby & Rails · ServerGitHub
More ways to build
Start with a prompt for your coding assistant, or follow the SDK guide for your language. Both paths cover installation, publishing, subscriptions and channel authorization.
New to the terminology? Explore the realtime glossary for WebSockets, pub/sub, channel authorization and delivery concepts, with practical Pubb examples.