🚀 nito_reverb

A professional, robust, and lightweight Flutter package for seamless communication with Laravel Reverb.

Built for performance and reliability, nito_reverb provides a clean, Stream-based API to handle real-time events, private channels, and presence tracking. It is designed with an open-source mindset, offering a clear project structure and extensible architecture.

✨ Features

  • ✅ Direct Reverb Integration: Optimized for the Reverb/Pusher protocol (V7).
  • ✅ Clean Categorization: Logic is organized into core, channels, auth, and models.
  • ✅ Stream-based API: Listen for events using standard Dart Streams.
  • ✅ Secure Authentication: Built-in support for Private and Presence channels with custom HTTP authorizers.
  • ✅ Presence Tracking: Track who's online with NitoReverbPresenceChannel.
  • ✅ Connection Resilience: Automatic reconnection with exponential backoff.
  • ✅ State Awareness: Reactive connection states (connecting, connected, retrying, etc.).

📁 Project Structure

The source code is organized into logical domains for maximum maintainability:

lib/
 ├── src/
 │    ├── core/      # Connection logic, Config, and States
 │    ├── channels/  # Public, Private, and Presence channel implementations
 │    ├── auth/      # Authentication interfaces and HTTP handlers
 │    ├── models/    # Event and Member data models
 │    └── utils/     # Internal utilities
 └── nito_reverb.dart # Main public API exports

🛡️ Type-Safe Event Streaming

Easily map incoming JSON to your models using a factory:

channel.on<User>('UserJoined', User.fromJson).listen((user) {
  print(user.name); // Type-safe!
});

🤫 Client-Side Sending (Whispering)

Send events directly from the client (useful for typing indicators):

final channel = client.private('chat');
channel.whisper('typing', {'user': 'Ammanuel'});

👥 Presence Tracking

Keep track of online users effortlessly:

final presence = client.presence('lobby');

presence.membersStream.listen((members) {
  print("Who's online: ${members.keys}");
});

🚀 Getting Started

1. Configure the Client

final config = NitoReverbConfig(
  host: 'reverb.yourdomain.com',
  key: 'your-key',
  port: 443,
  encrypted: true,
);

final client = NitoReverbClient(config: config);

2. Add Authentication (for Private/Presence)

final auth = HttpNitoReverbAuth(
  url: 'https://api.yourdomain.com/broadcasting/auth',
  headers: {
    'Authorization': 'Bearer <TOKEN>',
  },
);

final client = NitoReverbClient(config: config, auth: auth);

3. Connect and Listen

await client.connect();

client.public('orders').on('NewOrder').listen((event) {
  print('New order received: ${event.data}');
});

Private Channel (Requires Auth)

final profileChannel = client.private('users.1');
profileChannel.on('ProfileUpdated').listen((event) {
  print('User updated: ${event.data}');
});

Presence Channel (User Tracking)

final room = client.presence('chat.lobby');

// Listen for messages
room.on('MessageSent').listen((event) => print(event.data));

// Track online members
room.membersStream.listen((members) {
  print('Members online: ${members.length}');
});

🛠 Advanced Usage

Monitoring Connection Status

client.stateStream.listen((state) {
  if (state == NitoReverbConnectionState.retrying) {
    print('Lost connection... attempting to reconnect');
  }
});

Unsubscribing

client.unsubscribe('private-orders.123');

📚 Full Examples

Check out the example project for ready-to-use boilerplate for:

  • Connection Lifecycle Monitoring
  • Presence Channel Member Tracking
  • Whisper Event Dispatching
  • Type-Safe JSON-to-Model mapping

🤝 Open Source & Contributing

nito_reverb is built to be the gold standard for Laravel Reverb in Flutter. Contributions are welcome!

  1. Fork the repository.
  2. Create your feature branch.
  3. Commit your changes.
  4. Push to the branch.
  5. Create a new Pull Request.

📄 License

This project is licensed under the MIT License.

Libraries

nito_reverb