lib/adhearsion/call_controller.rb in adhearsion-2.0.0.alpha1 vs lib/adhearsion/call_controller.rb in adhearsion-2.0.0.alpha2
- old
+ new
@@ -31,37 +31,40 @@
self.callbacks = self.callbacks.dup.tap { |cb| cb[:#{name}] += Array(callback) }
end
STOP
end
- def self.exec(controller, fresh_call = true)
- return unless controller
+ class << self
+ def exec(controller, fresh_call = true)
+ return unless controller
- new_controller = catch :pass_controller do
- controller.skip_accept! unless fresh_call
- controller.execute!
- nil
+ new_controller = catch :pass_controller do
+ controller.skip_accept! unless fresh_call
+ controller.execute!
+ nil
+ end
+
+ exec new_controller, false
end
- exec new_controller, false
+ ##
+ # Include another module into all CallController classes
+ def mixin(mod)
+ include mod
+ end
end
- attr_reader :call, :metadata
+ attr_reader :call, :metadata, :block
delegate :[], :[]=, :to => :@metadata
delegate :variables, :logger, :to => :call
- delegate :write_and_await_response, :accept, :answer, :reject, :to => :call
+ delegate :write_and_await_response, :accept, :answer, :reject, :mute, :unmute, :join, :to => :call
- def initialize(call, metadata = nil)
- @call, @metadata = call, metadata || {}
- setup
+ def initialize(call, metadata = nil, &block)
+ @call, @metadata, @block = call, metadata || {}, block
end
- def setup
- Plugin.add_dialplan_methods self if Plugin
- end
-
def execute!(*options)
execute_callbacks :before_call
accept if auto_accept?
run
rescue Hangup
@@ -71,10 +74,11 @@
ensure
after_call
end
def run
+ instance_exec &block if block
end
def invoke(controller_class, metadata = nil)
controller = controller_class.new call, metadata
controller.run
@@ -109,17 +113,9 @@
end
def hangup(headers = nil)
hangup_response = call.hangup! headers
after_call unless hangup_response == false
- end
-
- def mute
- write_and_await_response ::Punchblock::Command::Mute.new
- end
-
- def unmute
- write_and_await_response ::Punchblock::Command::Unmute.new
end
def execute_component_and_await_completion(component)
write_and_await_response component