Class: Adhearsion::VoIP::FreeSwitch::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/voip/freeswitch/event_handler.rb

Overview

Subclass this to register a new event handler

Constant Summary collapse

@@events =
{}
@@compound_events =
{}
@@connection =
nil

Class Method Summary collapse

Class Method Details

.dispatch_event!(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/adhearsion/voip/freeswitch/event_handler.rb', line 22

def self.dispatch_event!(data)
  #puts "\nHandling an event! #{data.inspect}"
  name = data['Event-Name']
  normal_event = name && @@events[name.underscore.to_sym]
  # puts "THIS IS WHAT I THINK IT MIGHT BE : #{normal_event.inspect} (with #{name.underscore.to_sym.inspect})"
  if normal_event then normal_event.call(data)
  else
    #debug "Trying compound events"
    @@compound_events.each do |(event, block)|
      mini_event = {}
      event.keys.each { |k| mini_event[k] = data[k] }
      block.call(data) if event == mini_event
    end
  end
rescue => e
  p e
  puts e.backtrace.map { |x| " " * 4 + x }
end

.start!(hash = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/adhearsion/voip/freeswitch/event_handler.rb', line 13

def self.start!(hash=nil)
   hash if hash
  raise "You must login to the FreeSWITCH EventSocket!" unless @@connection
  loop do
    # debug "Waiting for an event"
    dispatch_event! @@connection.get_header
  end
end