Class: FnordMetric::WebSocket
- Inherits:
-
Rack::WebSocket::Application
- Object
- Rack::WebSocket::Application
- FnordMetric::WebSocket
- Defined in:
- lib/fnordmetric/web/websocket.rb
Instance Method Summary collapse
- #get_uuid ⇒ Object
-
#initialize ⇒ WebSocket
constructor
A new instance of WebSocket.
- #on_message(env, message) ⇒ Object
- #on_open(env) ⇒ Object
Constructor Details
#initialize ⇒ WebSocket
Returns a new instance of WebSocket.
8 9 10 11 12 13 |
# File 'lib/fnordmetric/web/websocket.rb', line 8 def initialize super @reactor = FnordMetric::Reactor.new @uuid = "websocket-#{get_uuid}" end |
Instance Method Details
#get_uuid ⇒ Object
37 38 39 |
# File 'lib/fnordmetric/web/websocket.rb', line 37 def get_uuid rand(8**64).to_s(36) end |
#on_message(env, message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fnordmetric/web/websocket.rb', line 19 def (env, ) begin = JSON.parse() rescue puts "websocket: invalid json" else ["_eid"] ||= get_uuid ["_sender"] = @uuid @reactor.execute(self, ).each do |m| send_data m.to_json end end rescue Exception => e FnordMetric.error("[WebSocket] #{e.to_s}") puts e.backtrace.join("\n") end |
#on_open(env) ⇒ Object
15 16 17 |
# File 'lib/fnordmetric/web/websocket.rb', line 15 def on_open(env) @reactor.ready! end |