Example of using Pusher's presence functionality for a simple chat demo
Pull request Compare This branch is even with pusher-community:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
db
lib/tasks
public
script
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru

README.md

Pusher presence demo

Short and sweet example of how authentication and presence events hook together.

There are two branches which demonstrate some different approaches:

  • demonstrate_use_of_socket_id: Uses the sender's socket_id when triggering events to avoid sending the chat message via pusher to the sender's browser. See http://pusher.com/docs/duplicates for a fuller description of this issue.

  • send_messages_with_client_events: Uses client events to send chat messages rather than an ajax call to the rails app. This reduces latency but means that persistence isn't possible on the server. It also uses client events to send typing notifications to other browsers which is a nice use case for client events. Note: This will only work for you if client events have been enabled for your app.

Before running locally, add some Pusher credentials to config/initializers/pusher_init.rb. Then run with

script/rails server

Deploying to Heroku with the Pusher Heroku add-on

git clone git@github.com:pusher/pusher-presence-demo.git
heroku create
heroku addons:add pusher
git push heroku master
heroku open