Skip to main content
Version: 0.1.x

Notify Attendees in Realtime - React Native

This guide explains how PubSub can be used to implement the functionality of broadcasting a message to all the viewers at once. If you are not familiar with the PubSub mechanism and usePubSub hook, you can follow this guide.

Notifying Attendees​

  1. To implement this functionality, begin by creating a "Notify Attendees" button along with a text input to capture the message. When a message is entered into the input and the button is clicked, publish a message with the topic NOTIFY_ATTENDEES.
// importing usePubSub hook from react-native-sdk
import { usePubSub } from "@videosdk.live/react-native-sdk";

function MeetingView() {
// destructure publish method from usePubSub hook
const { publish } = usePubSub("NOTIFY_ATTENDEES");
const [message, setMessage] = useState("");

return (
<SafeAreaView>
<TextInput
style={{
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
}}
onChangeText={setMessage}
value={message}
/>

<TouchableOpacity
onPress={() => {
publish(message);
}}
>
<Text>Notfiy Attendees</Text>
</TouchableOpacity>
</SafeAreaView>
);
}
  1. Next, alert all the speakers, displaying the message posted by the speaker.
function MeetingView() {
const { localParticipant } = useMeeting();

// destructure publish method from usePubSub hook
const { publish } = usePubSub("NOTIFY_ATTENDEES", {
onMessageReceived: (message) => {
if (localParticipant.mode == "VIEWER") alert(`${message.message}`);
},
});

return <>...</>;
}

API Reference​

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord