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

插件详情v1.3.0

action_cable

Dart 中的 ActionCable 客户端,可在 Web、dartVM 和 Flutter 中使用。

AndroidiOSmacOSWindowsLinux
近 30 天下载
1490
喜欢数
22
Pub 分数
135

安装插件

flutter pub add action_cable

插件介绍

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

ActionCable 是 Rails 的 ActionCable 的 Dart 客户端实现,可在 Flutter 和 Dart 应用中通过 WebSocket 实现实时双向通信。它支持 Web、DartVM 以及 Android、iOS、macOS、Windows 和 Linux 等移动平台。该包可与 ActionCable 服务器无缝集成,实现诸如实时更新、聊天系统和通知等功能。它提供简洁的 API,用于订阅频道、接收消息,并通过内置重连逻辑管理连接。非常适合需要实时数据同步的应用。

适合场景

  • 实时聊天应用
  • 实时仪表板更新
  • 通知系统
  • 协作编辑工具
  • 流式数据馈送

主要特点

  • 基于 WebSocket 的实时通信
  • 跨平台支持(网页、移动设备、桌面)
  • 频道订阅管理
  • 自动重连
  • 简单的事件驱动 API

适合对象

  • 需要实时功能的Flutter应用
  • 使用 Rails 后端的 Dart 项目
  • 开发实时交互式 UI 的开发者
  • 需要低延迟更新的应用
  • 在服务器端使用 ActionCable 的团队

使用建议

  • 需要兼容的 ActionCable 服务器
  • 网络可靠性影响性能
  • 与成熟的替代方案相比,文档有限
  • 需要手动处理消息解析
  • 未经调优,不适用于高频、低延迟场景

原始 README

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

Pub

All Contributors

ActionCable in Dart

ActionCable is the default realtime websocket framework and protocol in Rails.

This is a dart port of the client and protocol implementation which is available in web, dartVM and flutter.

Usage

Connecting to a channel 🙌
cable = ActionCable.connect(
  "ws://10.0.2.2:3000/cable",
  headers: {
    "Authorization": "Some Token",
  },
  onConnected: (){
    print("connected");
  },
  onConnectionLost: () {
    print("connection lost");
  },
  onCannotConnect: () {
    print("cannot connect");
});
Subscribing to channel 🎉
cable.subscribe(
  "Chat", // either "Chat" and "ChatChannel" is fine
  channelParams: { "room": "private" },
  onSubscribed: (){}, // `confirm_subscription` received
  onDisconnected: (){}, // `disconnect` received
  onMessage: (Map message) {} // any other message received
);
Unsubscribing from a channel 🎃
cable.unsubscribe(
  "Chat", // either "Chat" and "ChatChannel" is fine
  {"room": "private"}
);
Perform an action on your ActionCable server 🎇

Requires that you have a method defined in your Rails Action Cable channel whose name matches the action property passed in.

cable.performAction(
  "Chat",
  action: "send_message",
  channelParams: { "room": "private" },
  actionParams: { "message": "Hello private peeps! 😜" }
);
Disconnect from the ActionCable server
cable.disconnect();

ActionCable protocol

Anycable has a great doc on that topic.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Clinton

💻 ⚠️

Hamad AlGhanim

💻

Fareesh Vijayarangam

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。