GitHub

Source

useDataChannel

The useDataChannel hook returns the ability to send and receive messages. By optionally passing a topic, you can narrow down which messages are returned in the messages array.

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 participants via the 'chat' topic.
const { message: latestMessage, send } = useDataChannel("chat", (msg) =>
console.log("message received", msg)
);

Properties

topicT
onMessage?(msg: ReceivedDataMessage<T>) => void

Returns

UseDataChannelReturnType<T>;