SimplePusher
SimplePusher is a HTML5 websocket powered realtime messaging tool.
Installation
Add this line to your application's Gemfile:
gem 'simple_pusher'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_pusher
Usage
- Start simple pusher server in rails config/initializers.
# config/initializers/simple_pusher.rb
EventMachine.next_tick do
SimplePusher.setup do |config|
config.port = 8088
config.debug = false
end
SimplePusher.start
end
- Setup client js code.
var simple_pusher = new SimplePusher("ws://<%= request.host %>:8088/");
simple_pusher.on("message", function(message){
console.log("Receive:", message )
});
simple_pusher.on("online_count", function(message){
});
- Broadcast message via server side.
SimplePusher.broadcast("Time now #{Time.now.to_s(:db}")
- Broadcast message via client side.
simple_pusher.broadcast("Hello everybody.")
Contributing
- Fork it
- 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