This is a Ruby gem for use with Rails to publish and subscribe to messages through Faye. All channels are automatically made private.
This project was motivated by Railscasts episode #260.
Add the gem to your Gemfile and run bundle.
Run the generator to create the initial files.
rails g private_pub:install
Next, install and start up Faye using the rackup file that was generated.
gem install faye rackup faye.ru -s thin -E production
It's not necessary to include faye.js since that will be handled automatically.
Use the subscribe_to helper method on any page to subscribe to a channel.
<%= subscribe_to "/messages/new" %>
There will be alternative ways to publish/subscribe to channels in the future.
Security is handled automatically for you. Only the Rails app is able to publish. Users are only able to receive messages on the channels you subscribe them to. This means every channel is private.
Here's how it works. The subscribe_to helper will output an element containing data information about the channel.
<span class="private_pub_subscription" data-channel="/messages/new" data-signature="2aae6c35c94fcfb415dbe95f408b9ce91ee846ed" data-timestamp="13019431281234"></span>
The data-signature is a combination of the channel, timestamp, and secret token set in the Rails app. This is checked by the Faye extension when subscribing to a channel to ensure the signature is correct. The signature is automatically expired after 1 hour but this can be configured in the generated YAML file.
signature_expiration: 600 # 10 minutes, expressed in seconds
Or use a blank value for no expiration.
Note: if Faye is on a separate server from the Rails app it's important that the system clocks be in sync.
Development & Feedback
Questions or comments? Please use the issue tracker. If you would like to contribue to this project, clone this repository and run bundle and rake to run the tests.