Method: Bixby::WebSocket::APIChannel#message

Defined in:
lib/bixby-common/websocket/api_channel.rb

#message(event) ⇒ Object

Message

Fired whenever a message is received on the channel



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/bixby-common/websocket/api_channel.rb', line 88

def message(event)
  req = Message.from_wire(event.data)
  logger.debug { "new '#{req.type}' message" }

  if req.type == "rpc" then
    # Execute the requested method and return the result
    json_req = req.json_request
    logger.debug { json_req.to_s }
    json_response = @handler.new(req).handle(json_req)

    # result = { :type => "rpc_result", :id => req.id, :data => json_response }
    # ws.send(MultiJson.dump(result))
    ws.send(Response.new(json_response, req.id).to_wire)

  elsif req.type == "rpc_result" then
    # Pass the result back to the caller
    res = req.json_response
    logger.debug { res.to_s }
    @responses[req.id].response = res

  elsif req.type == "connect" then
    @handler.new(req).connect(req.json_request, self)

  end
end