Connection flow
- Obtain a valid Chat Live session with an HttpOnly cookie.
- Connect from the same origin to /ws?roster=2.
- Send a join event with an accessible room slug.
- Listen for ready, joined, message, presence, presence-delta and room-counts events.
- Leave before changing rooms, or let the server enforce one room per socket.
Same-origin browser sample
This example runs inside an authenticated first-party Chat Live page. Browsers attach same-origin cookies automatically.
// For a logged-in user on the SAME Chat Live origin only.
// Browser cookies are automatically attached to same-origin WebSockets.
const scheme = location.protocol === 'https:' ? 'wss:' : 'ws:';
const socket = new WebSocket(`${scheme}//${location.host}/ws?roster=2`);
socket.addEventListener('open', () => {
socket.send(JSON.stringify({ type: 'join', room: 'general' }));
});
socket.addEventListener('message', ({ data }) => {
const event = JSON.parse(data);
if (event.type === 'joined') console.log('Joined', event.room);
if (event.type === 'message') console.log('Message', event.message);
if (event.type === 'presence') console.log('Roster', event.users);
if (event.type === 'presence-delta') console.log('Changes', event.upserts, event.removed);
});
socket.addEventListener('close', () => console.log('Disconnected'));Local development guest session
Use this only on your separately deployed development instance, not as an external production messaging API. Do not commit cookie.txt.
# Only on YOUR independently hosted Chat Live instance, with matching Origin.
# This creates a guest session and writes an HttpOnly cookie to the jar.
curl -i -c cookie.txt \
-H 'Content-Type: application/json' \
-H 'Origin: http://127.0.0.1:9330' \
-d '{"nickname":"Example Tester"}' \
'http://127.0.0.1:9330/api/session'
# Never upload cookie.txt, commit it, or print session tokens in logs.Presence details
A presence snapshot can be followed by presence-delta messages with upserts and removed siteKey entries. Some supporter presences have no private-message peerId; a roster entry is not automatically a DM target. Online counts change in real time.
Not a public contract
There is currently no general WebSocket SDK, no third-party-origin socket access, and no permission to copy user sessions. Internal protocol events may evolve, so supported external integrations require a separate contract.