eko 0.0.1
eko: ^0.0.1 copied to clipboard
Eko for connecting your flutter to laravel reverb.
π‘ Eko a Flutter Laravel Reverb Client #
π Features #
βοΈ Easy WebSocket Connection to Laravel Reverb
βοΈ Authentication Support (JWT, API Keys)
βοΈ Public & Private Channel Subscriptions
βοΈ Real-time Event Handling
βοΈ Lightweight & Easy to Use
π¦ Installation #
Add eko to your pubspec.yaml:
dependencies:
eko: ^0.0.1
and run:
flutter pub get
or install it from the command line:
flutter pub add eko
π― Usage #
1οΈβ£ Initialize the WebSocket Client #
import 'package:eko/eko.dart';
final options = EkoOptions(
scheme: "ws",
host: "localhost",
port: "8080",
appKey: "your-app-key", // Reverb app key
authUrl: "https://your-backend.com/api/broadcasting/auth", // optional, needed for private channels
authToken: "your-auth-token", // optional
privatePrefix: "private-", // default: "private-"
);
final eko = Eko(options: options);
2οΈβ£ Listen for Messages #
// Public channel
eko.listen((message) {
print("Received: ${message.event}, Data: ${message.data}");
}, "public-channel", isPrivate: false);
// Private channel
eko.listen((message) {
print("Received: ${message.event}, Data: ${message.data}");
}, "public-channel", isPrivate: true);
3οΈβ£ Close Connection #
eko.close();
π§ͺ Testing #
Unit tests are included and use mockito to simulate WebSocket interactions: TODO
flutter test
π Configuration #
| Parameter | Type | Description |
|---|---|---|
scheme |
String | WebSocket scheme (ws or wss) |
host |
String | Server hostname |
port |
String | Server port |
appKey |
String | Laravel Echo app key |
authUrl |
String? | URL for authentication (private channels) |
authToken |
String? | Token for authentication requests (sanctum or similar) |
privatePrefix |
String | Prefix for private channels (default: private-) |
EkoOptions example #
class EkoOptions {
final String scheme;
final String host;
final String port;
final String appKey;
final dynamic authToken;
final String? authUrl;
final String privatePrefix;
final bool usePrefix;
EkoOptions({
required this.scheme,
required this.host,
required this.port,
required this.appKey,
this.authToken,
this.authUrl,
this.privatePrefix = 'private-',
this.usePrefix = true,
});
}