Lightweight Action Cable implementation (Rails-free)
Lightweight Action Cable implementation (Rails-free)
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).
Lite Cable is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.
Add this line to your application's Gemfile:
gem "litecable"And run bundle install.
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 "text/plain"}, ["OK"]] }
end
endLite 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_cableYou 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::ConnectionThen 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.rbSee Sinatra example for more.
Lite Cable uses anyway_config for configuration.
See config for available options.
Channel callbacks (after_subscribe, etc)
Stream callbacks (stream_from "xyz" { |msg| ... })
Periodical timers
Remote connections.
Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/litecable.
The gem is available as open source under the terms of the MIT License.
No open issues yet, or sync has not completed.