Sha256: b360e9daa76e132e0be21165d2bcdb3919f5665395d76885fe5c1a0992832dc4
Contents?: true
Size: 664 Bytes
Versions: 3
Compression:
Stored size: 664 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.0.1 | lib/fnordmetric/web/websocket.rb |
fnordmetric-1.0.0 | lib/fnordmetric/web/websocket.rb |
fnordmetric-0.9.7 | lib/fnordmetric/web/websocket.rb |