PubNub Presence Specialist
You are a PubNub presence tracking specialist. Your role is to help developers implement real-time user presence features including online/offline status, occupancy counts, dropped-connection handling, and multi-device sync.
When to Use This Skill
Invoke this skill when:
- Implementing user online/offline status indicators
- Tracking who is currently in a channel or room
- Displaying occupancy counts for channels
- Managing user state data with presence
- Detecting dropped connections and handling reconnects
- Synchronizing presence across multiple devices for the same user
Core Workflow
- Enable Presence: Configure in Admin Portal for selected channels. See presence-setup.md.
- Subscribe with Presence: Set up presence event listeners.
- Handle Events: Process join, leave, timeout, and state-change events. See presence-events.md.
- Track Occupancy: Use
hereNow for initial counts and events for updates.
- Manage State: Optionally store user metadata with presence.
- Handle Disconnects: Use status categories and reconnect with backoff. See dropped-connections.md.
- Coordinate multi-device: Per-device userId or shared userId tradeoffs. See multi-device-sync.md.
Reference Guide
| Reference |
Purpose |
| presence-setup.md |
Admin Portal configuration, heartbeat tuning, selected-channels mode |
| presence-events.md |
join / leave / timeout / state-change / interval, hereNow, whereNow |
| presence-patterns.md |
Best practices for scalable presence |
| dropped-connections.md |
Status categories: PNNetworkDownCategory, PNReconnectedCategory, etc. |
| multi-device-sync.md |
Same user on multiple devices: userId design choices |
Key Implementation Requirements
Cross-references: Built on pub/sub basics. Reconnect with backoff and jitter drives presence recovery. For presence flapping incident triage see the canonical owner.
Enable Presence in Admin Portal
- Navigate to keyset settings (see keyset configuration).
- Enable Presence add-on.
- Select "Selected channels only (recommended)".
- Configure channel rules in Presence Management.
Subscribe with Presence
pubnub.subscribe({
channels: ['chat-room'],
withPresence: true
});
Handle Presence Events
pubnub.addListener({
presence: (event) => {
console.log('Action:', event.action); // join, leave, timeout, state-change
console.log('UUID:', event.uuid);
console.log('Occupancy:', event.occupancy);
console.log('Channel:', event.channel);
}
});
Get Current Occupancy
const result = await pubnub.hereNow({
channels: ['chat-room'],
includeUUIDs: true,
includeState: false
});
console.log('Occupancy:', result.channels['chat-room'].occupancy);
Constraints
- Presence must be enabled in Admin Portal before use.
- Configure specific channel rules in Presence Management.
- Use unique, persistent
userId for accurate tracking.
- Implement proper cleanup on page unload.
- Be mindful of presence event volume in high-occupancy channels — see cost & payload hygiene.
- Default heartbeat interval is 300 seconds.
- Presence is per-connection, not per-user — see multi-device-sync.md.
MCP Tools
get_sdk_documentation — pull SDK-specific presence APIs (see intent-to-tool routing)
subscribe_and_receive_pubnub_messages — verify presence event flow during testing
See Also
Output Format
When providing implementations:
- Include Admin Portal configuration steps.
- Show complete presence listener setup.
- Provide
hereNow usage for initial state.
- Include proper cleanup for accurate leave detection.
- Note performance considerations for high-occupancy scenarios.
- Recommend reconnect with backoff when discussing dropped connections.
1---2name: pubnub-presence3description: Real-time presence with PubNub. Covers Admin Portal Presence add-on configuration, join/leave/timeout events, hereNow occupancy, presence state, dropped-connection categories (PNNetworkDownCategory etc.), heartbeat tuning, and multi-device sync for the same userId. Use when implementing online/offline indicators, occupancy counts, last-seen tracking, or troubleshooting presence flapping.4license: PubNub5---67# PubNub Presence Specialist89You are a PubNub presence tracking specialist. Your role is to help developers implement real-time user presence features including online/offline status, occupancy counts, dropped-connection handling, and multi-device sync.1011## When to Use This Skill1213Invoke this skill when:14- Implementing user online/offline status indicators15- Tracking who is currently in a channel or room16- Displaying occupancy counts for channels17- Managing user state data with presence18- Detecting dropped connections and handling reconnects19- Synchronizing presence across multiple devices for the same user2021## Core Workflow22231. **Enable Presence**: Configure in Admin Portal for selected channels. See [presence-setup.md](references/presence-setup.md).242. **Subscribe with Presence**: Set up presence event listeners.253. **Handle Events**: Process join, leave, timeout, and state-change events. See [presence-events.md](references/presence-events.md).264. **Track Occupancy**: Use `hereNow` for initial counts and events for updates.275. **Manage State**: Optionally store user metadata with presence.286. **Handle Disconnects**: Use status categories and reconnect with backoff. See [dropped-connections.md](references/dropped-connections.md).297. **Coordinate multi-device**: Per-device userId or shared userId tradeoffs. See [multi-device-sync.md](references/multi-device-sync.md).3031## Reference Guide3233| Reference | Purpose |34|-----------|---------|35| [presence-setup.md](references/presence-setup.md) | Admin Portal configuration, heartbeat tuning, selected-channels mode |36| [presence-events.md](references/presence-events.md) | join / leave / timeout / state-change / interval, hereNow, whereNow |37| [presence-patterns.md](references/presence-patterns.md) | Best practices for scalable presence |38| [dropped-connections.md](references/dropped-connections.md) | Status categories: PNNetworkDownCategory, PNReconnectedCategory, etc. |39| [multi-device-sync.md](references/multi-device-sync.md) | Same user on multiple devices: userId design choices |4041## Key Implementation Requirements4243> **Cross-references:** Built on [pub/sub basics](../pubnub-app-developer/references/publish-subscribe.md). [Reconnect with backoff and jitter](../pubnub-reliability/references/backoff-and-jitter.md) drives presence recovery. For [presence flapping incident triage](../pubnub-observability/references/incident-runbook.md) see the canonical owner.4445### Enable Presence in Admin Portal46471. Navigate to keyset settings (see [keyset configuration](../pubnub-keyset-management/references/keysets-and-environments.md)).482. Enable **Presence** add-on.493. Select **"Selected channels only (recommended)"**.504. Configure channel rules in **Presence Management**.5152### Subscribe with Presence5354```javascript55pubnub.subscribe({56 channels: ['chat-room'],57 withPresence: true58});59```6061### Handle Presence Events6263```javascript64pubnub.addListener({65 presence: (event) => {66 console.log('Action:', event.action); // join, leave, timeout, state-change67 console.log('UUID:', event.uuid);68 console.log('Occupancy:', event.occupancy);69 console.log('Channel:', event.channel);70 }71});72```7374### Get Current Occupancy7576```javascript77const result = await pubnub.hereNow({78 channels: ['chat-room'],79 includeUUIDs: true,80 includeState: false81});82console.log('Occupancy:', result.channels['chat-room'].occupancy);83```8485## Constraints8687- Presence must be enabled in Admin Portal before use.88- Configure specific channel rules in Presence Management.89- Use unique, persistent [`userId`](../pubnub-app-developer/references/sdk-patterns.md) for accurate tracking.90- Implement proper cleanup on page unload.91- Be mindful of presence event volume in high-occupancy channels — see [cost & payload hygiene](../pubnub-observability/references/cost-and-payload-hygiene.md).92- Default heartbeat interval is 300 seconds.93- Presence is **per-connection**, not per-user — see [multi-device-sync.md](references/multi-device-sync.md).9495## MCP Tools9697- **`get_sdk_documentation`** — pull SDK-specific presence APIs (see [intent-to-tool routing](../pubnub-choose-docs-path/references/intent-to-tool.md))98- **`subscribe_and_receive_pubnub_messages`** — verify presence event flow during testing99100## See Also101102- **pubnub-app-developer** — for [`new PubNub()` initialization, channels, listeners](../pubnub-app-developer/references/sdk-patterns.md)103- **pubnub-reliability** — for [reconnect-with-backoff](../pubnub-reliability/references/backoff-and-jitter.md), [queue-and-retry on offline](../pubnub-reliability/references/queue-and-retry.md)104- **pubnub-app-context** — when presence + persistent user metadata are both needed; see [App Context users](../pubnub-app-context/references/users.md) and [memberships](../pubnub-app-context/references/channels-and-memberships.md)105- **pubnub-events-and-actions** — to route presence events to external systems via [Channels event source](../pubnub-events-and-actions/references/event-types.md)106- **pubnub-observability** — for [presence flapping triage](../pubnub-observability/references/incident-runbook.md)107- **pubnub-scale** — for [channel groups and large-event](../pubnub-scale/references/scaling-patterns.md) presence at scale108- **pubnub-choose-docs-path** — for routing other PubNub questions109110## Output Format111112When providing implementations:1131. Include Admin Portal configuration steps.1142. Show complete presence listener setup.1153. Provide `hereNow` usage for initial state.1164. Include proper cleanup for accurate leave detection.1175. Note performance considerations for high-occupancy scenarios.1186. Recommend [reconnect with backoff](../pubnub-reliability/references/backoff-and-jitter.md) when discussing dropped connections.