async_cable

Last updated:

0 purchases

async_cable Image
async_cable Images
Add to Cart

Description:

async cable

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 #
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"});
}
copied to clipboard
Additional information #
Copyright (c) Delivereasy Ltd., 2023.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.