Dart Faye
A Dart implementation of the Faye real-time messaging protocol. Provides WebSocket-based messaging with support for subscriptions, authentication, and scalable real-time communication. Perfect for building collaborative applications, live chat systems, and real-time dashboards.
Links
Features
WebSocket Support
Full WebSocket implementation for low-latency, bidirectional real-time communication.
Pub/Sub Messaging
Publish-subscribe pattern for scalable messaging across multiple clients and channels.
Authentication
Built-in support for client authentication and authorization mechanisms.
Auto Reconnection
Intelligent reconnection logic with exponential backoff for network resilience.
Cross-Platform
Works seamlessly across Flutter mobile, web, and desktop applications.
Easy Integration
Simple API design that makes real-time messaging easy to implement in any Flutter app.
Getting Started
Installation
Add Dart Faye to your Flutter project:
dependencies:
dart_faye: ^1.0.0
Basic Usage
1import 'package:dart_faye/dart_faye.dart';
2
3class ChatApp extends StatefulWidget {
4
5 _ChatAppState createState() => _ChatAppState();
6}
7
8class _ChatAppState extends State<ChatApp> {
9 late FayeClient client;
10
11
12 void initState() {
13 super.initState();
14
15 client = FayeClient('ws://localhost:9292/faye');
16
17 client.onConnected = () {
18 print('Connected to Faye server');
19 };
20
21 client.onDisconnected = () {
22 print('Disconnected from Faye server');
23 };
24
25 // Subscribe to chat messages
26 client.subscribe('/chat/room1', (message) {
27 print('Received: ${message.data}');
28 });
29
30 client.connect();
31 }
32
33 void _sendMessage(String text) {
34 client.publish('/chat/room1', {
35 'user': 'Current User',
36 'message': text,
37 'timestamp': DateTime.now().toIso8601String(),
38 });
39 }
40}
Protocol Compliance
Dart Faye implements the complete Bayeux protocol specification, ensuring compatibility with existing Faye servers and clients. The protocol defines several message types:
Handshake
Initial connection establishment and capability negotiation.
Subscribe/Unsubscribe
Channel subscription management for receiving messages.
Publish
Sending messages to specific channels for distribution.
Connect/Disconnect
Connection lifecycle management and heartbeat monitoring.
Use Cases
Real-time Chat
Build instant messaging applications with reliable message delivery and presence indicators.
Collaborative Tools
Create collaborative editors, whiteboards, and shared workspaces with real-time synchronization.
Live Dashboards
Build real-time monitoring dashboards that update automatically as data changes.
Gaming
Implement multiplayer game features with low-latency real-time communication.