Low commit activity in last 3 years
No release in over a year
Enable server sent events with rack middleware implemented over Faye and Broadcaster (Redis Pub/Sub)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 5.0, < 5.11
~> 0.2
~> 0.6
~> 12.0
~> 0.12

Runtime

~> 1.0, >= 1.0.2
 Project Readme

Rasti::Web::Broadcaster

Gem Version Build Status Coverage Status Code Climate

Enable server sent events with rack middleware implemented over Faye and Broadcaster (Redis Pub/Sub)

Installation

Add this line to your application's Gemfile:

gem 'rasti-web-broadcaster'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rasti-web-broadcaster

Usage

Configuration

Rasti::Web::Broadcaster.configure do |config|
  config.id = 'AppName'
  config.redis_settings = "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}"
  config.keep_alive_interval = 30
  config.logger = Logger.new "/log/#{ENV['RACK_ENV']}.log"
end

Rack middleware

use Rasti::Web::Broadcaster

headers = {'Access-Control-Allow-Origin' => '*'}
use Rasti::Web::Broadcaster, headers

Publishing events from the web

Rasti::Web::Broadcaster.publish channel_id, data:  'hello'      # string or json
                                            event: 'eventName', # optional
                                            id:    1234         # optional

Publishing events from external processes

require 'broadcaster'

broadcaster = Broadcaster.new id: 'AppName', redis_settings: "redis://#{ENV['REDIS_HOST']}:#{ENV['REDIS_PORT']}"

broadcaster.publish channel_id, data: 'hello'

Client subscription (browser)

const events = new EventSource('/channel');

events.addEventListener('open', e => console.info('Started streaming')); 

events.addEventListener('error', e => console.warn(e)); 

events.onmessage = e => console.debug(e.data)

events.addEventListener('eventName', e => console.debug(e.data));

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/rasti-web-broadcaster.

License

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