useDataChannel
The useDataChannel
hook returns the ability to send and receive messages.
Import
import { useDataChannel } from "@livekit/components-react";
Remarks
There is only one data channel. Passing a topic
does not open a new data channel. It is only used to filter out messages with no or a different topic
.
Usage
// Send messages to all participantsconst { message: latestMessage, send } = useDataChannel("chat", (msg) =>console.log("message received", msg));
Properties
onMessage?
(msg: ReceivedDataMessage) => void
Returns
UseDataChannelReturnType;