Thư viện client
Flutter thời gian thực với WebSocket Ứng dụng Flutter và Dart trên iOS, Android và web.
Đăng nhập để xem các đoạn mã này với host cụm của riêng bạn. Đăng nhập
Đang dùng một AI agent lập trình? Sao chép prompt cho agent ↓
Cài đặt flutter pub add dart_pusher_channelsĐăng ký một kênh final options = PusherChannelsOptions .fromHost (
scheme: 'wss' ,
host: 'ws.hibira.io' ,
port: 443 ,
key: 'YOUR_APP_KEY' ,
);
final client = PusherChannelsClient .websocket (
options: options,
connectionErrorHandler: (error, trace, refresh) => refresh (),
);
final channel = client.publicChannel ('orders' );
channel.bind ('order-shipped' ).listen ((event) => print (event.data));
client.onConnectionEstablished.listen ((_) => channel.subscribeIfNotUnsubscribed ());
await client.connect ();Prompt cho agent Dán nội dung này vào Claude Code, Cursor, GitHub Copilot hoặc một AI agent lập trình khác, và nó sẽ tích hợp Hibira vào dự án Flutter của bạn với các cài đặt ở trên.
Integrate Hibira realtime messaging into this Flutter project. Hibira is a hosted WebSocket service that speaks the Pusher Channels protocol, so it works with the standard Pusher libraries (here: dart_pusher_channels, https://pub.dev/packages/dart_pusher_channels) pointed at Hibira instead of pusher.com.
Connection details:
- Host: ws.hibira.io
- Port: 443
- TLS: yes (https)
- App key: YOUR_APP_KEY
- No app secret: it belongs on the server, never in this app
What to do:
1. Look at the project first (framework version, package manager, config and env conventions, where similar integrations live) and follow what it already does.
2. Add dart_pusher_channels (the official Flutter SDK can't change its host, so don't use pusher_channels_flutter).
3. Keep one client in a service or provider and pass the key and host with --dart-define or the project's existing config approach.
4. Cancel stream subscriptions and disconnect when the owning widget or service is disposed.
5. If the app needs private or presence channels, use the package's endpoint authorization delegate pointed at the backend's auth endpoint; the app secret must never be in the app.
6. Read the credentials and host from environment variables or the project's config, and add placeholder entries to .env.example (or its equivalent). Never commit real values.
7. Always pass the host, port and TLS setting above. The library defaults to pusher.com; where it requires a cluster, use "ap" (the host decides where it connects).
8. If YOUR_APP_KEY above is still a placeholder, keep it as an env placeholder and tell me where to fill it in rather than inventing a value.
9. When you are done, list the files you changed and tell me how to check it works, for example by publishing a test event and watching it arrive.
Reference setup from the Hibira Flutter guide (adapt it to the project's structure):
Install:
```shell
flutter pub add dart_pusher_channels
```
Subscribe to a channel:
```dart
final options = PusherChannelsOptions.fromHost(
scheme: 'wss',
host: 'ws.hibira.io',
port: 443,
key: 'YOUR_APP_KEY',
);
final client = PusherChannelsClient.websocket(
options: options,
connectionErrorHandler: (error, trace, refresh) => refresh(),
);
final channel = client.publicChannel('orders');
channel.bind('order-shipped').listen((event) => print(event.data));
client.onConnectionEstablished.listen((_) => channel.subscribeIfNotUnsubscribed());
await client.connect();
```
Thay YOUR_APP_KEY và các giá trị giữ chỗ khác bằng giá trị từ bảng điều khiển, hoặc để agent giữ chúng dưới dạng biến môi trường để bạn tự điền.
Hoặc kết nối máy chủ MCP của Hibira, và agent của bạn có thể tự tạo ứng dụng và điền thông tin xác thực. Kết nối AI agent lập trình của bạn →
Dùng app key và secret từ bảng điều khiển. Kênh, sự kiện và endpoint xác thực hoạt động y như với Pusher. Tài liệu thư viện ↗