• Stars
    star
    298
  • Rank 139,635 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight Action Cable implementation (Rails-free)

Gem Version Build

Lite Cable

Lightweight ActionCable implementation.

Contains application logic (channels, streams, broadcasting) and also (optional) Rack hijack based server (suitable only for development and test due to its simplicity).

Compatible with AnyCable (for production usage).

Sponsored by Evil Martians

Examples

Installation

Add this line to your application's Gemfile:

gem "litecable"

And run bundle install.

Usage

Please, checkout Action Cable guides for general information. Lite Cable aims to be compatible with Action Cable as much as possible without the loss of simplicity and lightness.

You can use Action Cable javascript client without any change (precompiled version can be found here).

Here are the differences:

  • Use LiteCable::Connection::Base as a base class for your connection (instead of ActionCable::Connection::Base)

  • Use LiteCable::Channel::Base as a base class for your channels (instead of ActionCable::Channel::Base)

  • Use LiteCable.broadcast to broadcast messages (instead of ActionCable.server.broadcast)

  • Explicitly specify channels names:

class MyChannel < LiteCable::Channel::Base
  # Use this id in your client to create subscriptions
  identifier :chat
end
App.cable.subscriptions.create('chat', ...)

Using a custom channel registry

Alternatively to eager loading all channel classes and providing identifiers, you can build a custom channel registry object, which can perform channel class lookups:

# DummyRegistry which always returns a predefined channel class
class DummyRegistry
  def lookup(channel_id)
    DummyChannel
  end
end

LiteCable.channel_registry = DummyRegistry.new

Using built-in server (middleware)

Lite Cable comes with a simple Rack middleware for development/testing usage. To use Lite Cable server:

  • Add gem "websocket" to your Gemfile

  • Add require "lite_cable/server"

  • Add LiteCable::Server::Middleware to your Rack stack, for example:

Rack::Builder.new do
  map "/cable" do
    # You have to specify your app's connection class
    use LiteCable::Server::Middleware, connection_class: App::Connection
    run proc { |_| [200, {"Content-Type" => "text/plain"}, ["OK"]] }
  end
end

Using with AnyCable

Lite Cable is AnyCable-compatible out-of-the-box.

If AnyCable gem is loaded, you don't need to configure Lite Cable at all.

Otherwise, you must configure broadcast adapter manually:

LiteCable.broadcast_adapter = :any_cable

You can also do this via configuration, e.g., env var (LITECABLE_BROADCAST_ADAPTER=any_cable) or broadcast_adapter: any_cable in a YAML config.

At the AnyCable side, you must configure a connection factory:

AnyCable.connection_factory = MyApp::Connection

Then run AnyCable along with the app:

bundle exec anycable

# add -r option to load the app if it's not ./config/anycable.rb or ./config/environment.rb
bundle exec anycable -r ./my_app.rb

See Sinatra example for more.

Configuration

Lite Cable uses anyway_config for configuration.

See config for available options.

Unsupported features

  • Channel callbacks (after_subscribe, etc)

  • Stream callbacks (stream_from "xyz" { |msg| ... })

  • Periodical timers

  • Remote connections.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/litecable.

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

logidze

Database changes log for Rails
Ruby
1,596
star
2

action_policy

Authorization framework for Ruby/Rails applications
Ruby
1,404
star
3

isolator

Detect non-atomic interactions within DB transactions
Ruby
850
star
4

anyway_config

Configuration library for Ruby gems and applications
Ruby
735
star
5

active_delivery

Ruby framework for keeping all types of notifications (mailers, push notifications, whatever) in one place
Ruby
595
star
6

n_plus_one_control

RSpec and Minitest matchers to prevent N+1 queries problem
Ruby
556
star
7

store_attribute

ActiveRecord extension which adds typecasting to store accessors
Ruby
376
star
8

view_component-contrib

A collection of extension and developer tools for ViewComponent
Ruby
345
star
9

acli

Action Cable command-line client
Ruby
230
star
10

action-cable-testing

Action Cable testing utils
Ruby
212
star
11

rubanok

Parameters-based transformation DSL
Ruby
205
star
12

active_event_store

Rails Event Store in a more Rails way
Ruby
180
star
13

action_policy-graphql

Action Policy integration for GraphQL
Ruby
151
star
14

engems

Rails component-based architecture on top of engines and gems (showroom)
Ruby
136
star
15

influxer

InfluxDB ActiveRecord-style
Ruby
118
star
16

abstract_notifier

ActionMailer-like interface for any type of notifications
Ruby
116
star
17

turbo-music-drive

Exploring Turbo future features while building a music library app
Ruby
102
star
18

wsdirector

All the world's a server, and all the men and women merely clients
Ruby
102
star
19

gem-check

GemCheck: Writing Better Ruby Gems Checklist
CSS
95
star
20

pgrel

ActiveRecord extension for querying hstore and jsonb
Ruby
93
star
21

rbytes

Ruby Bytes helps you build, deploy and install Ruby and Rails application templates
Ruby
68
star
22

faqueue

Researching background jobs fairness
Ruby
66
star
23

downstream

Straightforward way to implement communication between Rails Engines using the Publish-Subscribe pattern.
Ruby
51
star
24

newgem

Custom script to generate new gems
Ruby
35
star
25

turbo-view-transitions

View Transitions API for Turbo
TypeScript
33
star
26

influx_udp

Erlang InfluxDB UDP writer
Erlang
31
star
27

ruby-dip

Docker-based development environment for hacking Ruby MRI
Dockerfile
30
star
28

erlgrpc

GRPC client for Erlang
Erlang
25
star
29

as3_p2plocal

as3 lib for local p2p connections (serverless rtmfp)
ActionScript
25
star
30

rails-intest-views

Generate view templates dynamically in Rails tests
Ruby
21
star
31

docsify-namespaced

Docsify plugin to work with namespaces
JavaScript
12
star
32

sharelatex-vagrant-ansible

Vagrant + Ansible configuration for ShareLatex
Shell
12
star
33

slog-spy

Slog handler to temporary deliver formatted verbose logs to an arbitrary target
Go
12
star
34

docs-example

Playground for dealing with documentation engines
7
star
35

ruby-russia-2020

RubyRussia 2020 "Frontendless Rails" workshop demo app
Ruby
6
star
36

engine-cable-app

Experimenting with Action Cable and engines
Ruby
6
star
37

rails-on-wasm-playground

A minimal Rails app to showcase Rails on Wasm features
Ruby
5
star
38

palkan

It's me
4
star
39

ruby-compatibility-examples

Collections of reproduction cases for TruffleRuby vs. MRI (in)compatibility
Ruby
3
star
40

erffmpeg

Erlang wrapper for some ffmpeg
C
3
star
41

th-dummy

TH Dummy
Ruby
2
star
42

ulitos

Erlang utils modules
Erlang
2
star
43

meetings

Good old Teachbase Meetings client
ActionScript
2
star
44

rebar_templates

Custom rebar templates
Erlang
1
star
45

macos-setup

Shell
1
star
46

bitrix-orm

Bitrix kinda ORM for IBlockElements and CUser.
PHP
1
star
47

anycable-elements

Web Components for AnyCable console
JavaScript
1
star
48

adventofcode2018

https://adventofcode.com
Rust
1
star
49

tb_utils

ActionScript 3 library
ActionScript
1
star