Overview
History and presence answer two different questions:
- History: what persisted events happened in this channel?
- Presence: who is connected right now?
Presence is realtime state and may change immediately as clients connect, disconnect or reconnect. History follows the channel's persistence and retention settings.
Setup
Server-side history/presence:
- JavaScript: history(), events(), presence(), onlineCount(), isOnline(identifierId)
- Python: history(), events(), presence(), online_count(), is_online(identifier_id)
WebSocket presence actions:
- requestPresenceSnapshot / request_presence_snapshot
- checkPresence / check_presence
Listen for presence_snapshot, presence_joined, presence_left, presence_count and presence_check_result messages to update live UI state.
Code example
const channel = pg.channel("operations");
const events = await channel.events({ limit: 50 });
const presence = await channel.presence();
const count = await channel.onlineCount();
const driver = await channel.isOnline("driver_88");
console.log({ events, presence, count, driver });
connection.requestPresenceSnapshot();
connection.checkPresence("driver_88");
channel = pg.channel("operations")
events = channel.events(limit=50)
presence = channel.presence()
count = channel.online_count()
driver = channel.is_online("driver_88")
print(events, presence, count, driver)
connection.request_presence_snapshot()
connection.check_presence("driver_88")
Notes
Use a stable identifier_id chosen by your application, such as user_123, driver_88 or support_agent_7. identifier_label is display text and may change.
Presence should not be treated as permanent account status. It represents active channel connections.