bulky-wall-61623
09/01/2025, 3:05 PMtall-airline-16756
09/01/2025, 3:05 PMtall-airline-16756
09/01/2025, 3:06 PMuseChat hook in LiveKit's @livekit/components-react package is a handy way to send messages on a specific topic using the send method. By default, it sends messages on the lk.chat topic, but you can easily switch it up by setting a channelTopic in the ChatOptions when you call useChat.
Here’s a quick example:
const { send, chatMessages } = useChat({ channelTopic: 'custom-topic' });
send('Hello on custom topic!');
Any messages you send on that topic will automatically show up and stack in the chatMessages array. One thing to keep in mind: there isn’t a built-in way to dynamically fetch or list all active topics in the room. So, everyone needs to know the topic name ahead of time to set up a handler and receive those messages.
If you’re looking to get a bit more advanced, you can pair useDataChannel with useChat to juggle multiple topics. Feel free to reach out if you want me to walk you through it or if you have any other questions—I’m here to help!
Sources: packages/core/src/observables/dataChannel.ts | Sending text | LiveKit Docs | src/components/reaction-bar.tsx