Tuesday, 29 December 2015

Hello Guys,

I've just create Faye Installation for local or heroku app, So please checkout the below steps for using private pub with faye server-
For current application-
1. Add gems into gemfile
gem
"private_pub"
gem "thin"

2.
Run the generator to create the initial files.
rails g private_pub:install

3.
Next, start up Faye using the rackup file that was generated.
rackup private_pub.ru -s thin -E production


4. add the JavaScript file to your application.js file.
//= require private_pub

5. Add subscription below of rendered messages in html file
<%=
subscribe_to "/messages/new" %>

6. Add into create.js.erb file

<%
publish_to "/messages/new" do %> $("#chat").append("<%= j render(@messages) %>"); <% end %>

For Heroku:

1. Create new folder heroku_private_pub
mkdir heroku_private_pub
2. cd heroku_private_pub
3. create Gemfile and add
source 'https://rubygems.org'
gem 'private_pub'
gem 'thin'
gem 'foreman'

4. create Procfile and add
web: bundle exec rackup private_pub.ru -s thin -p $PORT -E production
5. create private_pub.ru and add
# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

Faye::WebSocket.load_adapter('thin')

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "production")
run PrivatePub.faye_app

5. cd config
6. create private_pub.yml and add
production:
  server: "http://tgs-privatpub.herokuapp.com/faye"
  secret_token: "1c8d5ec9aa425b5758a7390f724f69bb40ee53053aedfca8da4ffefa8b4b9c62"
  signature_expiration: 86400

7. Add above server and secret_token into your app config/private_pub.yml 
Enjoy....

Thanks,
Hemant Gupta

No comments:

Post a Comment