Module: Socker::Helper
- Included in:
- App
- Defined in:
- lib/socker/helper.rb
Instance Method Summary collapse
-
#broadcast(message) ⇒ Object
This function send an broadcast message to all active connections.
-
#params ⇒ Object
Provide access to the Rack params used for WebSocket connection, ie:.
-
#pbroadcast(message, callback) ⇒ Object
If the protocol support PING, you can send this to all clients and when they replied with PONG message, you can handle that with callback.
Instance Method Details
#broadcast(message) ⇒ Object
This function send an broadcast message to all active connections. The message must be String (but you can sent a JSON, etc..)
8 9 10 11 12 13 14 15 16 |
# File 'lib/socker/helper.rb', line 8 def broadcast() connections.each do |c| begin c.send() rescue => error log("ERROR: Connection #{c} seems invalid, ignoring. (#{error.})") end end end |
#params ⇒ Object
Provide access to the Rack params used for WebSocket connection, ie:
socket = new Socket(‘ws://’ + location.hostname + ‘:’ + ‘9292’ + ‘/?param1=value’)
29 30 31 |
# File 'lib/socker/helper.rb', line 29 def params @env.params end |
#pbroadcast(message, callback) ⇒ Object
If the protocol support PING, you can send this to all clients and when they replied with PONG message, you can handle that with callback.
21 22 23 |
# File 'lib/socker/helper.rb', line 21 def pbroadcast(, callback) connections.each { |c| c.ping(, &callback) } end |