Client for integrating a ruby application with a remote ActionCable-based backend provided by Rails 5 or compatible framework.
Switch branches/tags
Nothing to show
Clone or download
preston Merge pull request #3 from frostmark/master
Minor refactoring to move client into its own file.
Latest commit 6bf6a31 Mar 10, 2017

space_elevator - The ActionCable Client for Ruby

space_elevator is a client for integrating a ruby application with a remote ActionCable-based backend provided by a Rails 5 application or compatible framework. It allows for subscription and publication to multiple channels simultaneously, features automatic message routing to subscription-specific handlers, and supports eavesdropping on wire-level messages, allowing you to harness the power of WebSockets and receive push notifications in your own Ruby applications!


Add this line to your application's Gemfile:

gem 'space_elevator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install space_elevator


require 'space_elevator'
require 'eventmachine'
require 'em-websocket-client' do

    url = 'ws://'

    # Create a SpaceElevator::Client with a disconnect handler.
    client = do
        puts 'Disconnected. Exiting...'

    # Connect the client using the provided callback block.
    client.connect do |msg|
        case msg['type'] # The server will always set a 'type'.
        when 'welcome' # Sent after a successful connection.
            puts 'The server says "welcome".'

            # Subscribe to something..
            client.subscribe(channel: 'ChatChannel') do |chat|
                puts "Received Chat Event: #{chat}"
                if chat['type'] == 'confirm_subscription'
                    puts "Subscription to #{chat['identifier']['channel']} confirmed!"
                    # Broadcast to the channel! The actual channel identifier and message payload is specific to your backend's WebSocket API.
                    client.publish({channel: 'ChatChannel'}, {subject: 'Hi', text: "What's up, y'all!?!?"})

            # Subscribe to something else simultaneously. Note the additional parameters!
            client.subscribe(channel: 'PlatformChannel', platform_id: platform_id) do |m|
                puts "Received Platform #{platform_id} Event: #{m}"
                # Do whatever, here.
        when 'ping'
            puts 'The server just pinged us.'
            puts msg


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


This work is published under the Apache 2.0 license. Copyright (c) 2017 Preston Lee.