class Guh::EM::Connection
Public Instance Methods
onmessage(&block)
click to toggle source
# File lib/guh/em/connection.rb, line 11 def onmessage(&block) @onmessage = block end
post_init()
click to toggle source
# File lib/guh/em/connection.rb, line 15 def post_init request_string = Guh::Base.hash_to_json({id: Guh::Base.generate_request_id, method: "JSONRPC.SetNotificationStatus", params: { enabled: true } }) send_data(request_string) @message = "" end
receive_data(data)
click to toggle source
# File lib/guh/em/connection.rb, line 22 def receive_data(data) data.each_line do |line| @message << line if line.match(/^\}\n/) trigger_on_message(@message) @message = "" end end end
unbind()
click to toggle source
# File lib/guh/em/connection.rb, line 35 def unbind # TODO implement a callback to enable the notification of all clients about lost connection end
Private Instance Methods
trigger_on_message(message)
click to toggle source
# File lib/guh/em/connection.rb, line 41 def trigger_on_message(message) begin @onmessage.call(JSON::parse(message)) rescue Exception => e puts "--> rescue in guh.rb: #{e.inspect}" return {} end end