lib/adhearsion/punchblock_plugin/initializer.rb in adhearsion-2.0.0.alpha2 vs lib/adhearsion/punchblock_plugin/initializer.rb in adhearsion-2.0.0.alpha3
- old
+ new
@@ -1,14 +1,14 @@
module Adhearsion
class PunchblockPlugin
class Initializer
- cattr_accessor :config, :client, :dispatcher, :attempts
+ cattr_accessor :config, :client, :connection, :dispatcher, :attempts
self.attempts = 0
class << self
- def start
+ def init
self.config = Adhearsion.config[:punchblock]
connection_class = case (self.config.platform || :xmpp)
when :xmpp
::Punchblock::Connection::XMPP
when :asterisk
@@ -23,11 +23,11 @@
:root_domain => self.config.root_domain,
:calls_domain => self.config.calls_domain,
:mixers_domain => self.config.mixers_domain
}
- connection = connection_class.new connection_options
+ self.connection = connection_class.new connection_options
self.client = ::Punchblock::Client.new :connection => connection
# Tell the Punchblock connection that we are ready to process calls.
Events.register_callback :after_initialization do
connection.ready!
@@ -63,11 +63,13 @@
end
Events.punchblock proc { |e| e.respond_to?(:call_id) }, :call_id do |event|
dispatch_call_event event
end
+ end
+ def run
connect
end
def connect
return unless Process.state_name == :booting
@@ -117,24 +119,22 @@
call = Adhearsion.active_calls.from_offer offer
case Adhearsion::Process.state_name
when :booting, :rejecting
call.reject :decline
when :running
+ call.accept
dispatcher = Adhearsion.router.handle call
dispatcher.call call
else
call.reject :error
end
end
end
def dispatch_call_event(event, latch = nil)
if call = Adhearsion.active_calls.find(event.call_id)
- logger.debug "Event received for call #{call.id}: #{event.inspect}"
- Thread.new do
- call << event
- latch.countdown! if latch
- end
+ call.deliver_message! event
+ latch.countdown! if latch
else
logger.error "Event received for inactive call #{event.call_id}: #{event.inspect}"
end
end
end