action_cable 0.1.0
action_cable: ^0.1.0 copied to clipboard
ActionCable client port in dart, available in web, dartVM and flutter.
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: (){
// do something here
},
);
subscribe to channel #
cable.subscribeToChannel(
'Chat', // either 'Chat' and 'ChatChannel' is fine
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', { 'message': 'Hello' });
ActionCable protocol #
Anycable has a great doc on that topic.