When working with websocket, I really like working with pusher . They have dinner easy to set up. they are free for 200 thousand messages per day
This is the heroku documentation for the pusher
1) set the gem
gem install pusher
2) install addons
heroku addons:create pusher:sandbox
3) set your initializers
#config/initializers/pusher.rb require 'pusher' Pusher.app_id = '000000' Pusher.key = '000000000000000000' Pusher.secret = '00000000000000000000' Pusher.cluster = 'xxx' Pusher.logger = Rails.logger Pusher.encrypted = true
Once you have the keys, all you need to do is create a client (js) and a server
the code on the client is similar to this
<!DOCTYPE html> <head> <title>Pusher Test</title> <script src="https://js.pusher.com/4.1/pusher.min.js"></script> <script> </script> </head>
Now the server is really simple
require 'pusher' pusher_client = Pusher::Client.new( app_id: ENV[:app_id], key: ENV[:key], secret: ENV[:secret], cluster: ENV[:cluster], encrypted: true ) pusher_client.trigger('my-channel', 'my-event', { message: 'hello world' })
I hope this helps
source share