Sha256: 0cb903e1e3a95733fdeafbc82096d0889c1907fc28c4642d622f01b875812e67
Contents?: true
Size: 665 Bytes
Versions: 3
Compression:
Stored size: 665 Bytes
Contents
require "eventmachine" require 'rack/websocket' require "em-hiredis" require "json" class FnordMetric::WebSocket < Rack::WebSocket::Application def initialize super @reactor = FnordMetric::Reactor.new @uuid = "websocket-#{get_uuid}" end def on_open(env) # socket openened :) end def on_message(env, message) begin message = JSON.parse(message) rescue puts "websocket: invalid json" else message["_eid"] ||= get_uuid message["_sender"] = @uuid @reactor.execute(self, message).each do |m| send_data m.to_json end end end def get_uuid rand(8**64).to_s(36) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fnordmetric-1.2.4 | lib/fnordmetric/web/websocket.rb |
fnordmetric-1.2.1 | lib/fnordmetric/web/websocket.rb |
fnordmetric-1.2.0 | lib/fnordmetric/web/websocket.rb |