action_cable 0.1.5

  • Readme
  • Changelog
  • Installing
  • new73

Pub

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 #

connect #

cable = ActionCable.Connect(
  'ws://10.0.2.2:3000/cable',
  headers: {
    'Authorization': 'Some Token',
  },

  onConnected: (){
    print('connected');
  },
);

subscribe to channel #

cable.subscribeToChannel(
  'Chat', // either 'Chat' and 'ChatChannel' is fine
  channelParams: { 'id': 1 },
  onSubscribed: (){}, // `confirm_subscription` received
  onMessage: (Map message) {} // any other message received
);

unsubscribe to channel #

cable.unsubscribeToChannel(
  'Chat', // either 'Chat' and 'ChatChannel' is fine
);

perform action #

cable.performAction(
  'Chat', 'send',
  channelParams: { 'roomId': 1 },
  actionParams: { 'message': 'Hello' }
);

disconnect #

cable.disconnect();

ActionCable protocol #

Anycable has a great doc on that topic.

# 2019-11-21 0.1.0

First version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  action_cable: ^0.1.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:action_cable/action_cable.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health issues and suggestions

Document public APIs. (-1 points)

12 out of 12 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/action_cable.dart. (-0.50 points)

Analysis of lib/action_cable.dart reported 1 hint:

line 23 col 32: Use = to separate a named parameter from its default value.

Format lib/channel_id.dart.

Run dartfmt to format lib/channel_id.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and action_cable.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
web_socket_channel ^1.1.0 1.1.0
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
stream_channel 2.0.0
typed_data 1.1.6