lib/slanger/handler.rb
# Dispatches message handling to method with same name as
# the event name
Dispatches message handling to method with same name as
the event name
Dispatches message handling to method with same name as the event name
def onmessage(msg)
      Slanger::Statsd.increment("messages")
      Slanger::Statsd.gauge("message_size", msg.bytesize)
      msg = Oj.load(msg)
      msg["data"] = Oj.load(msg["data"]) if msg["data"].is_a? String
      case msg["event"]
      when /\Aclient-/
        msg["socket_id"] = socket_id
        Channel.send_client_message(msg)
      when "pusher:ping"
        pusher_ping(msg)
      when "pusher:pong"
        pusher_pong(msg)
      when "pusher:subscribe"
        pusher_subscribe(msg)
      when "pusher:unsubscribe"
        pusher_unsubscribe(msg)
      end
    rescue JSON::ParserError, Oj::ParseError
      send_error({ code: 5001, message: "Invalid JSON" })
    rescue Exception => e
      puts "Error: #{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
      send_error({ code: 500, message: "Internal Error" })
    end
def onmessage ( msg ) Slanger :: Statsd . increment ( "messages" ) Slanger :: Statsd . gauge ( "message_size" , msg . bytesize ) msg = Oj . load ( msg ) msg [ "data" ] = Oj . load ( msg [ "data" ] ) if msg [ "data" ] . is_a? String case msg [ "event" ] when / \A client- / msg [ "socket_id" ] = socket_id Channel . send_client_message ( msg ) when "pusher:ping" pusher_ping ( msg ) when "pusher:pong" pusher_pong ( msg ) when "pusher:subscribe" pusher_subscribe ( msg ) when "pusher:unsubscribe" pusher_unsubscribe ( msg ) end rescue JSON :: ParserError , Oj :: ParseError send_error ( { code : 5001 , message : "Invalid JSON" } ) rescue Exception => e puts "Error: #{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}" send_error ( { code : 500 , message : "Internal Error" } ) end
Dispatches message handling to method with same name as
the event name
Dispatches message handling to method with same name as the event name
msg
<not_specific>