Presence
Show who is online, away or busy across their devices, and let users set their own status.
Enable Messaging and Presence for the environment. Presence uses the same connection and messaging token as messaging.
Watch a user
import { usePresence } from '@lynkoria/react';
function Status({ userId }: { userId: string }) {
const presence = usePresence(userId); // null until the first update
if (!presence) return <span>…</span>;
return (
<span>
{presence.status}
{presence.status === 'offline' && presence.lastSeenAt && ` · last seen ${new Date(presence.lastSeenAt).toLocaleString()}`}
</span>
);
}Subscriptions are restored automatically after a reconnect. presence.status is online, away, busy, dnd or offline.
Set your own status
await client.presence.setStatus('away'); // 'available' | 'away' | 'busy' | 'dnd' | 'invisible'invisible makes the user appear offline to others while they stay connected. available returns to automatic online/offline.
How online is decided
- Each connected device sends a heartbeat about every 25 seconds and holds a 60-second lease.
- A user is online while any of their devices holds a lease, so closing one tab does not take them offline.
- After an abrupt disconnect (network loss, closed laptop), the user turns offline when the lease expires, up to about a minute later.
Who can see whom
Any user in the same environment and tenant can subscribe to any other user’s presence. Lynkoria has no contact list or block list. To restrict visibility, partition users into tenants, or leave presence off.
Presence is an approximation for display. Do not use it for authorization, or as proof that someone read a message: use read receipts for that.