Sha256: c6b9ccd9f67bd8d206fafcad0987988d522309f666bebf5d9718a3fabf071678
Contents?: true
Size: 1.56 KB
Versions: 14
Compression:
Stored size: 1.56 KB
Contents
require 'rubygems' require 'eventmachine' require 'fsr/listener' require 'fsr/listener/header_and_content_response.rb' module FSR module Listener class Inbound < EventMachine::Protocols::HeaderAndContentProtocol HOOKS = {} def initialize(args = {}) super @auth = args[:auth] || "ClueCon" end def post_init say("auth #{@auth}") say('event plain ALL') end def receive_request(header, content) hash_header = headers_2_hash(header) hash_content = headers_2_hash(content) event = HeaderAndContentResponse.new({:headers => hash_header, :content => hash_content}) event_name = event.content[:event_name].to_s.strip unless event_name.empty? HOOKS[event_name.to_sym].call(event) unless HOOKS[event_name.to_sym].nil? end on_event(event) end def say(line) send_data("#{line}\r\n\r\n") end def on_event(event) event end # Add or replace a block to execute when the specified event occurs # # <b>Parameters</b> # - event : What event to trigger the block on. May be # :CHANNEL_CREATE, :CHANNEL_DESTROY etc # - block : Block to execute # # <b>Returns/<b> # - nil def self.add_event_hook(event, &block) HOOKS[event] = block end # Delete the block that was to be executed for the specified event. def self.del_event_hook(event) HOOKS.delete(event) end end end end
Version data entries
14 entries across 14 versions & 3 rubygems