All Projects → NullVoxPopuli → Action_cable_client

NullVoxPopuli / Action_cable_client

Licence: mit
A ruby client for interacting with Rails' ActionCable. -- Maintainers Wanted.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Action cable client

Action policy
Authorization framework for Ruby/Rails applications
Stars: ✭ 718 (+193.06%)
Mutual labels:  hacktoberfest, rails
Ifme
Free, open source mental health communication web app to share experiences with loved ones
Stars: ✭ 1,147 (+368.16%)
Mutual labels:  hacktoberfest, rails
Logidze
Database changes log for Rails
Stars: ✭ 1,060 (+332.65%)
Mutual labels:  hacktoberfest, rails
Plots2
a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! 🎈
Stars: ✭ 666 (+171.84%)
Mutual labels:  hacktoberfest, rails
Rpush
The push notification service for Ruby.
Stars: ✭ 1,886 (+669.8%)
Mutual labels:  hacktoberfest, rails
Openfoodnetwork
Connect suppliers, distributors and consumers to trade local produce. We're recruiting paid contributors, link below.
Stars: ✭ 682 (+178.37%)
Mutual labels:  hacktoberfest, rails
Odoo Shopinvader
Odoo Modules. Sorry Magento, Shopinvader is coming
Stars: ✭ 60 (-75.51%)
Mutual labels:  hacktoberfest, rails
Anyway config
Configuration library for Ruby gems and applications
Stars: ✭ 409 (+66.94%)
Mutual labels:  hacktoberfest, rails
Boring generators
Boring generators aims to make your development faster by delegating boring setups to us.
Stars: ✭ 125 (-48.98%)
Mutual labels:  hacktoberfest, rails
Influxer
InfluxDB ActiveRecord-style
Stars: ✭ 115 (-53.06%)
Mutual labels:  hacktoberfest, rails
Osem
Open Source Event Manager. An event management tool tailored to Free and Open Source Software conferences.
Stars: ✭ 649 (+164.9%)
Mutual labels:  hacktoberfest, rails
Rubanok
Parameters-based transformation DSL
Stars: ✭ 161 (-34.29%)
Mutual labels:  hacktoberfest, rails
Webpacker
Use Webpack to manage app-like JavaScript modules in Rails
Stars: ✭ 5,282 (+2055.92%)
Mutual labels:  hacktoberfest, rails
Fae
CMS for Rails. For Reals.
Stars: ✭ 701 (+186.12%)
Mutual labels:  hacktoberfest, rails
Matestack Ui Core
Matestack enables you to create sophisticated, reactive UIs in pure Ruby, without touching JavaScript and HTML. You end up writing 50% less code while increasing productivity, maintainability and developer happiness.
Stars: ✭ 469 (+91.43%)
Mutual labels:  hacktoberfest, rails
Consul
Consul - Open Government and E-Participation Web Software
Stars: ✭ 1,088 (+344.08%)
Mutual labels:  hacktoberfest, rails
Active delivery
Ruby framework for keeping all types of notifications (mailers, push notifications, whatever) in one place
Stars: ✭ 388 (+58.37%)
Mutual labels:  hacktoberfest, rails
Refinerycms
An extendable Ruby on Rails CMS that supports Rails 6.0+
Stars: ✭ 3,825 (+1461.22%)
Mutual labels:  hacktoberfest, rails
Readyresponder
Local Incident Management System - This is used for tracking resources for Local Emergency Management
Stars: ✭ 106 (-56.73%)
Mutual labels:  hacktoberfest, rails
Yaaf
Easing the form object pattern in Rails applications
Stars: ✭ 161 (-34.29%)
Mutual labels:  hacktoberfest, rails

Action Cable Client

Gem Version Build Status Code Climate Test Coverage Dependency Status

This gem is a wrapper around websocket-eventmachine-client, and supports the Rails Action Cable protocol.

Usage

require 'action_cable_client'

EventMachine.run do

  uri = "ws://localhost:3000/cable/"
  client = ActionCableClient.new(uri, 'RoomChannel')
  # called whenever a welcome message is received from the server
  client.connected { puts 'successfully connected.' }

  # called whenever a message is received from the server
  client.received do | message |
    puts message
  end

  # Sends a message to the sever, with the 'action', 'speak'
  client.perform('speak', { message: 'hello from amc' })
end

This example is compatible with this version of a small Rails app with Action Cable

The available hooks to tie in to are:

  • disconnected {}
  • connected {}
  • subscribed {}
  • rejected {}
  • errored { |msg| }
  • received { |msg }
  • pinged { |msg| }

Connecting on initialization is also configurable.

client = ActionCableClient.new(uri, 'RoomChannel', false)
client.connect!(headers = {})
client.pinged do |_data|
  # you could track the time since you last received a ping, if you haven't
  # received one in a while, it could be that your client is disconnected.
end

To reconnect,

client.reconnect!

Sending additional params

params = { channel: 'RoomChannel', favorite_color: 'blue' }
client = ActionCableClient.new(uri, params)

then on the server end, in your Channel, params will give you:

{
       "channel" => "RoomChannel",
"favorite_color" => "blue"
}

Using Headers

params = { channel: 'RoomChannel', favorite_color: 'blue' }
client = ActionCableClient.new(uri, params, true, {
  'Authorization' => 'Bearer token'
})

Using TLS

Example given for client certificate authentication. See EventMachine::Connection#start_tls documentation for other options.

params = { channel: 'RoomChannel', favorite_color: 'blue' }
tls = {cert_chain_file: 'user.crt', private_key_file: 'user.key'}
client = ActionCableClient.new(uri, params, true, nil, tls)

Demo

Live Demo

Action Cable Client Demo on YouTube (1:41)

Here is a set of files in a gist that demonstrate how different action_cable_clients can communicate with eachother.

The Action Cable Protocol

There really isn't that much to this gem. :-)

  1. Connect to the Action Cable URL
  2. After the connection succeeds, send a subscribe message
  • The subscribe message JSON should look like this
    • {"command":"subscribe","identifier":"{\"channel\":\"MeshRelayChannel\"}"}
  • You should receive a message like this:
    • {"identifier"=>"{\"channel\":\"MeshRelayChannel\"}", "type"=>"confirm_subscription"}
  1. Once subscribed, you can send messages.
  • Make sure that the action string matches the data-handling method name on your ActionCable server.
  • Your message JSON should look like this:
    • {"command":"message","identifier":"{\"channel\":\"MeshRelayChannel\"}","data":"{\"to\":\"user1\",\"message\":\"hello from user2\",\"action\":\"chat\"}"}
    • Received messages should look about the same
  1. Notes:
  • Every message sent to the server has a command and identifier key.
  • The channel value must match the name of the channel class on the ActionCable server.
  • identifier and data are redundantly jsonified. So, for example (in ruby):
payload = {
  command: 'command text',
  identifier: { channel: 'MeshRelayChannel' }.to_json,
  data: { to: 'user', message: 'hi', action: 'chat' }.to_json
}.to_json

Contributing

  1. Fork it ( https://github.com/NullVoxPopuli/action_cable_client/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].