Module: Socker::Helper

Included in:
App
Defined in:
lib/socker/helper.rb

Instance Method Summary collapse

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(message)
  connections.each do |c|
    begin
      c.send(message)
    rescue => error
      log("ERROR: Connection #{c} seems invalid, ignoring. (#{error.message})")
    end
  end
end

#paramsObject

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(message, callback)
  connections.each { |c| c.ping(message, &callback) }
end