Connecting to a Broadcast Channel
This tutorial will guide you step by step on how to connect and listen to notifications via the broadcast channel using NativeEventEmitter
in React Native with the module provided by react-native-rook-sdk
.
Importing the Rook Module
To interact with the Rook notifications, you first need to obtain the module using the getRookModule
function provided by the SDK:
import { getRookModule } from "react-native-rook-sdk";
import { NativeEventEmitter } from "react-native";
Creating the Event Emitter
Next, create a NativeEventEmitter
to subscribe to the events emitted by the Rook module:
const rookModule = getRookModule();
const eventEmitter = new NativeEventEmitter(rookModule);
Listening to Rook Notifications
The Rook SDK emits notifications under the event 'ROOK_NOTIFICATION'
. These messages follow this structure:
{
type: string,
value: boolean,
message?: string
}