搜索插件、代码仓与 APP 分类

插件详情v0.21.0

centrifuge

Dart 客户端,通过 WebSocket 与 Flutter 和 VM 上的 Centrifuge 和 Centrifugo 进行通信

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7.7万
喜欢数
49
Pub 分数
140

安装插件

flutter pub add centrifuge

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Centrifuge 是一个 Dart 客户端,可通过 WebSocket 与 Centrifuge 和 Centrifugo 服务器进行实时通信。它使 Flutter 和 VM 应用能够订阅频道、接收实时更新并发布消息。专为低延迟交互设计,支持连接管理、重连逻辑以及跨多个平台的消息广播。非常适合构建聊天应用、实时仪表板和需要即时数据同步的协作工具。

适合场景

  • 实时聊天应用
  • 实时仪表板更新
  • 协作编辑工具
  • 推送通知
  • 多人游戏同步

主要特点

  • 基于WebSocket的实时通信
  • 自动重连
  • 频道订阅和发布
  • 跨平台支持
  • 轻便高效
  • 安全令牌认证

适合对象

  • Flutter 移动和网页应用
  • 服务器端 Dart 服务
  • 实时数据流
  • 高频事件处理

使用建议

  • 需要运行中的 Centrifuge 或 Centrifugo 服务器
  • 需要正确的身份验证设置
  • 在移动设备上可能需要配置网络权限
  • 依赖稳定的WebSocket连接

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Websocket client for Centrifugo server and Centrifuge library.

Since there is no v1 release yet, patch version updates only contain backwards compatible changes, minor version updates can have backwards incompatible API changes.

Check out client SDK API specification to learn how this SDK behaves. It's recommended to read that before starting to work with this SDK as the spec covers common SDK behavior - describes client and subscription state transitions, main options and methods. Also check out examples folder.

The features implemented by this SDK can be found in SDK feature matrix.

Note that custom WebSocket connection Upgrade headers are sent natively on platforms that support dart:io and in web context headers are sent using Centrifugo v6 Headers Emulation feature.

The latest centrifuge-dart is compatible with Centrifugo server v6, v5 and v4 and Centrifuge >= 0.25.0. For Centrifugo v2, Centrifugo v3 and Centrifuge < 0.25.0 you should use centrifuge-dart v0.8.0.

Examples

  • example\flutter_app simple chat application
  • example\chat_app one more chat example
  • example\console simple console application

Usage in background

When a mobile application goes to the background there are OS-specific limitations for established persistent connections - which can be silently closed shortly. Thus in most cases you need to disconnect from a server when app moves to the background and connect again when app goes to the foreground.

Alternative SDK

See also PlugFox/spinify for an alternative Dart (Flutter) real-time client SDK implementation.

Run tests locally

Start test Centrifugo server:

docker compose up

Then run tests:

dart run test --reporter expanded

Instructions for maintainers/contributors

How to update protobuf definitions
  1. Install protoc compiler
  2. Install protoc_plugin https://pub.dev/packages/protoc_plugin (dart pub global activate protoc_plugin)
  3. cd lib/src/proto and run protoc --dart_out=. -I . client.proto
  4. cd to root and run dartfmt -w lib/ test/ (install dartfmt with dart pub global activate dart_style)
How to release
  1. Update CHANGELOG.md, bump version in pubspec.yaml, push, create new tag
  2. [ONLY IF THERE ARE ISSUES WITH CI PUBLISH] dart pub publish

Author

German Saprykin, saprykin.h@gmail.com

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

所在榜单