Thunderer is gem for publishing messages through Faye. It allows you to easily provide real-time updates through an open socket without tying
Add this line to your application's Gemfile:
gem 'thunderer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install thunderer
Now thunderer supports ActiveJob scheduling of notifications and can be configured by global setup of ActiveJob or in thunderer.rb
Thunderer.configure do |config|
config.queue_adapter = :sucker_punch
config.environment = Rails.env
config.config_file_path = 'config/thunderer.yml'
end
Run generator:
rails g thunderer:install
It will generate thunderer.ru and thunderer.yml files. Check it and setup domain for production
Next add the JavaScript file to your application.js file manifest.
//= require thunderer
Use the subscribe_to
helper method on any page to subscribe to a channel.
<%= subscribe_to "/comments" %>
Then setup active record models:
class Comment < ActiveRecord::Base
include Thunderer::PublishChanges
notify_client_to_channels '/comments/new'
end
Before start using with Angular add response interceptor (ThundererInterceptor) and service ($thunderer):
//= require thunderer_angular
Inject 'Thunderer'
module to your app, and setup $http
service
...
provider.interceptors.push('ThundererInterceptor');
...
The main deference of usage is adding special headers to json responses:
class CommentsController < ApplicationController
include Thunderer::ControllerAdditions
thunderer_channels '/comments'
end
After that you can subscribe in your angular controllers and directives to Faye callbacks
commentAddOrChangedCallback = function(data) {
alert(data);
}
$thunderer.addListener("/comments", commentAddOrChangedCallback);
- Fork it ( http://github.com//thunderer/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request