Join & Leave
When a client connects to or disconnects from a channel,
all other clients receive a join or leave event with the current user count.
Basic Events
By default, join and leave events include the total number of connected users:
channel.on('join', ({ users }) => {
console.log(`Someone joined! ${users} online`)
})
channel.on('leave', ({ users }) => {
console.log(`Someone left. ${users} online`)
})Announcing Identity
Set announce: true and an alias to broadcast your identity when you join or leave.
Other clients will see your uid and alias in the event:
const channel = connect('my-chat', {
as: 'Alice', // set a display name
announce: true, // broadcast identity on join/leave
})
channel.on('join', ({ uid, alias, users }) => {
console.log(`${alias} (${uid}) joined — ${users} online`)
})
channel.on('leave', ({ uid, alias, users }) => {
console.log(`${alias} left — ${users} online`)
})Without announce, other clients only see the updated user count — not who joined or left.
Event Payloads
| Field | Type | Description |
|---|---|---|
type | 'join' | 'leave' | The event type |
users | number | Total users now on the channel |
uid | string? | User ID (only with announce: true) |
alias | string? | Display name (only with announce: true) |
date | number | Server timestamp |
User Identifiers
Each connection gets a short, unique uid (6 characters). This identifier is:
- Generated server-side on connection
- Unique within the channel
- Included in all messages from that user
- Used for direct messages
You can set a human-readable display name using the as option (or alias).
Next: TypeScript — type your listeners, sends, and connections.