Git Product home page Git Product logo

litecable's Introduction

Gem Version Build Status Circle CI Dependency Status

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 then execute:

$ bundle

Or install it yourself as:

$ gem install litecable

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 ligthness.

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 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. You should write a simple server script:

#!/usr/bin/env ruby

require "my_app"
require "rack"
require "anycable"

# Turn AnyCable compatibility mode
LiteCable.anycable!

Anycable.connection_factory = MyApp::Connection

Anycable::Server.start

And then run this script along with your application. 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/anycable/litecable.

License

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

litecable's People

Contributors

palkan avatar depfu-bot avatar depfu[bot] avatar

Watchers

Mark Frost avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.