Skip to content

Listen for events

Once a user has joined a room, you keep the conversation live by following the updates cursor. Each poll returns the events since the cursor you passed and a fresh cursor for the next poll — new messages, reactions, replies, and moderation actions all arrive on the same stream.

listen.js — sportstalk-sdk
import { ChatClient } from 'sportstalk-sdk';
// Public app id only. userToken comes from whichever auth model you chose.
const client = ChatClient.init({ appId: APP_ID });
client.setUserToken(userToken);
client.setUser({ userid: 'u-8842' }); // same user you joined as
// Handle the events you care about — the SDK tracks the cursor for you.
client.setEventHandlers({
onChatEvent: (e) => render(e),
onReaction: (e) => bump(e),
onAnnouncement: (e) => banner(e),
});
// Join, then start the long-poll loop.
await client.joinRoomByCustomId('live-event-chat');
client.startListeningToEventUpdates();