react-native-reverb
v1.0.5
Published
React Native TurboModule wrapper for Laravel Reverb WebSocket
Maintainers
Readme
React Native Reverb
A React Native TurboModule wrapper for Laravel Reverb WebSockets.
This package lets you connect to a Reverb server, subscribe/unsubscribe to channels, and listen for broadcasted events & notifications.
🚀 Installation
From npm
npm install react-native-reverbor with yarn:
yarn add react-native-reverb📦 Setup
Autolinking (React Native 0.71+) The package supports autolinking, no extra linking step required.
iOS Install pods:
cd ios && pod installAndroid Nothing extra required, autolinking will register the TurboModule.
🛠 Usage
import { ReverbClient } from 'react-native-reverb';
const client = new ReverbClient({
appKey: '<YOUR_REVERB_APP_KEY>',
scheme: 'https',
url: '<YOUR_REVERB_HOST>',
auth: {
endpoint: '<YOUR_REVERB_AUTH_ENDPOINT>',
headers: {
Authorization: `Bearer <TOKEN>`,
},
},
});
// Connect to server
await client.connect();
// Subscribe to a channel
const channel = await client.private(`App.Models.Order.${orderId}`);
// Listen for specific event
channel.listen('OrderUpdated', (data: any) => {
console.log('Order updated:', data);
});
// Listen for Laravel notifications
channel.notifications((notification: any) => {
console.log('Notification received:', notification);
});
// Remove all Listeners and unsubscribe at once when leaving
await channel.removeAllListeners();
// Disconnect Websocket completely
await client.disconnect();📚 API Reference
ReverbClient
new ReverbClient(options: NativeReverbOptions): ReverbClient– create a client instanceconnect(): Promise<void>– connect to Reverb serverdisconnect(): Promise<void>– disconnect & cleanupchannel(name: string): Promise<ReverbChannel>– subscribe to a public channelprivate(name: string): Promise<ReverbPrivateChannel>– subscribe to a private channel
ReverbChannel | ReverbPrivateChannel
listen(event: string, callback: (data: any) => void): Promise<void>– listen for eventsnotifications(callback: (data: any) => void): Promise<void>– listen for Laravel notificationsremoveListener(event: string): Promise<void>– stop listening to an eventremoveAllListeners(): Promise<void>– stop listening from all events and unsusbcribe the channelunsubscribe(): Promise<void>– unsubscribe from this channelgetChannelName(): string- get channel name
🧑💻 Development
Clone the repo and install dependencies:
git clone https://github.com/azlanali076/react-native-reverb.git
cd react-native-reverb
npm install📄 License
MIT © Syed Azlan Ali
