https://github.com/delivereasynz/async_cable
Async/stream-oriented implementation of the Rails ActionCable protocol for Dart & Flutter.
https://github.com/delivereasynz/async_cable
actioncable async dart flutter
Last synced: 4 months ago
JSON representation
Async/stream-oriented implementation of the Rails ActionCable protocol for Dart & Flutter.
- Host: GitHub
- URL: https://github.com/delivereasynz/async_cable
- Owner: DelivereasyNZ
- License: bsd-3-clause
- Created: 2023-04-03T01:54:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-15T09:26:11.000Z (over 2 years ago)
- Last Synced: 2023-10-16T18:52:55.494Z (over 2 years ago)
- Topics: actioncable, async, dart, flutter
- Language: Dart
- Homepage: http://pub.dev/packages/async_cable
- Size: 40 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# AsyncCable
Async/stream-oriented implementation of the Rails ActionCable protocol for Dart & Flutter.
## Features
Supports ActionCable over `dart:io` WebSocket connections.
Web (`dart:html`) is not supported, and support is not planned at this time.
## Getting started
To use this library with unauthenticated ActionCable servers, you just need to know the URL.
Most ActionCable servers use authentication. To use these, you first need to figure out how your Dart application will authenticate to the Rails server. For example, if you will use `Authorization` headers, you may implement your own APIs to get an authentication token, then pass it in the [AsyncCable.connect] `headers` option, and make sure the `ApplicationCable::Connection` code in the server will accept these authorization headers.
Then you just need to agree on the channel naming and parameter conventions with the server code, and you're ready to start sending & receiving messages.
## Usage
```dart
void main() async {
final accessToken = yourAuthToken();
final connection = await AsyncCable.connect(
"ws://localhost:3000/cable",
headers: {
"Origin": "http://localhost:3000",
"Authorization": "Bearer $accessToken",
},
);
final channel = await connection.subscribe(
"HelloChannel",
{"foo": "bar"},
(message) => print("Received ${message.message["greeting"]}"),
);
channel.perform("hello", {"greeting": "hi"});
}
```
## Additional information
Copyright (c) Delivereasy Ltd., 2023.