搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

所在榜單