Module: Adhearsion::Events

Defined in:
lib/adhearsion/events_support.rb

Constant Summary collapse

DEFAULT_FRAMEWORK_EVENT_NAMESPACES =
%w[
  /after_initialized
  /shutdown
  /asterisk/manager_interface
  /asterisk/before_call
  /asterisk/after_call
  /asterisk/hungup_call
  /asterisk/failed_call
]

Class Method Summary collapse

Class Method Details

.framework_theatreObject



38
39
40
# File 'lib/adhearsion/events_support.rb', line 38

def framework_theatre
  defined?(@@framework_theatre) ? @@framework_theatre : reinitialize_theatre!
end

.register_callback(namespace, block_arg = nil, &method_block) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
77
78
79
# File 'lib/adhearsion/events_support.rb', line 73

def register_callback(namespace, block_arg=nil, &method_block)
  raise ArgumentError, "Cannot supply two blocks!" if block_arg && block_given?
  block = method_block || block_arg
  raise ArgumentError, "Must supply a callback!" unless block

  framework_theatre.register_callback_at_namespace(namespace, block)
end

.register_namespace_name(name) ⇒ Object



63
64
65
# File 'lib/adhearsion/events_support.rb', line 63

def register_namespace_name(name)
  framework_theatre.register_namespace_name name
end

.reinitialize_theatre!Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/adhearsion/events_support.rb', line 50

def reinitialize_theatre!
  @@framework_theatre.gracefully_stop! if defined? @@framework_theatre
rescue
  # Recover and reinitalize
ensure
  # TODO: Extract number of threads to use from AHN_CONFIG
  @@framework_theatre = Theatre::Theatre.new
  DEFAULT_FRAMEWORK_EVENT_NAMESPACES.each do |namespace|
    register_namespace_name namespace
  end
  return @@framework_theatre
end

.stop!Object



67
68
69
70
71
# File 'lib/adhearsion/events_support.rb', line 67

def stop!
  Events.trigger :shutdown
  framework_theatre.graceful_stop!
  framework_theatre.join
end

.trigger(*args) ⇒ Object



42
43
44
# File 'lib/adhearsion/events_support.rb', line 42

def trigger(*args)
  framework_theatre.trigger(*args)
end

.trigger_immediately(*args) ⇒ Object



46
47
48
# File 'lib/adhearsion/events_support.rb', line 46

def trigger_immediately(*args)
  framework_theatre.trigger_immediately(*args)
end