Overview
This example demonstrates the main PulseGrid flow without creating separate documentation pages for every helper.
Both applications use the same project. The first one ensures a channel exists, each backend creates its own client token, and both connect to the same room. An event published by either side can be received by all connected clients.
Setup
1. Configure the same PulseGrid project keys in both applications.
2. Ensure the desired channel exists from one trusted backend.
3. Create one client token per realtime identity.
4. Connect Node and Python.
5. Send a message or custom event.
6. Check history and presence.
7. Observe heartbeat pongs as connection maintenance, not repeated user actions.
Code example
import { createPulseGrid } from "pulsegrid";
const pg = createPulseGrid();
const existing = await pg.channels.all();
let room = existing.find(c => c.slug === "live-operations");
if (!room) {
const created = await pg.channels.create({ name: "Live Operations" });
room = created.data.channel;
}
const token = await pg.tokens.create({
identifierId: "node_dispatch",
identifierLabel: "Node Dispatch",
allowedChannels: [room.slug],
});
const socket = await pg.channel(room.slug).connect({
clientToken: token,
onMessage: console.log,
});
socket.sendEvent("dispatch.ready", { data: { ready: true } });
from pulsegrid import PulseGrid
pg = PulseGrid()
room_slug = "live-operations"
token = pg.tokens.create(
identifier_id="python_field",
identifier_label="Python Field Service",
allowed_channels=[room_slug],
)
socket = pg.channel(room_slug).connect(
client_token=token,
on_message=lambda payload: print(payload),
)
socket.send_event("field.ready", data={"ready": True})
print(pg.channel(room_slug).events(limit=20))
print(pg.channel(room_slug).online_count())
Notes
Use separate identifier IDs for separate logical clients. A browser connection should use its own short-lived token rather than reusing a server identity.