Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namiwang/actioncable_dart
actioncable client in dart, for pure dart or flutter project
https://github.com/namiwang/actioncable_dart
actioncable dart flutter websocket
Last synced: 15 days ago
JSON representation
actioncable client in dart, for pure dart or flutter project
- Host: GitHub
- URL: https://github.com/namiwang/actioncable_dart
- Owner: namiwang
- License: mit
- Created: 2018-12-21T06:53:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T14:47:41.000Z (4 months ago)
- Last Synced: 2025-01-18T07:41:23.376Z (21 days ago)
- Topics: actioncable, dart, flutter, websocket
- Language: Dart
- Size: 5.18 MB
- Stars: 25
- Watchers: 2
- Forks: 25
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
![Pub](https://img.shields.io/pub/v/action_cable)
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#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 🙌
```dart
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 🎉
```dart
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 🎃
```dart
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.
```dart
cable.performAction(
"Chat",
action: "send_message",
channelParams: { "room": "private" },
actionParams: { "message": "Hello private peeps! 😜" }
);
```### Disconnect from the ActionCable server
```dart
cable.disconnect();
```## ActionCable protocol
Anycable has [a great doc](https://docs.anycable.io/#/misc/action_cable_protocol) on that topic.
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Clinton
💻 ⚠️
Hamad AlGhanim
💻
Fareesh Vijayarangam
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!