lib/adhearsion/call.rb in adhearsion-2.1.3 vs lib/adhearsion/call.rb in adhearsion-2.2.0

- old
+ new

@@ -21,33 +21,28 @@ def proxy.method_missing(*args) super rescue Celluloid::DeadActorError raise ExpiredError, "This call is expired and is no longer accessible" end - - def proxy.join(*args) - Actor.call @mailbox, :join, *args - end end end - # @private - attr_accessor :offer, :client, :end_reason, :commands, :controllers + attr_reader :end_reason, :commands, :controllers, :variables - attr_accessor :variables - delegate :[], :[]=, :to => :variables delegate :to, :from, :to => :offer, :allow_nil => true def initialize(offer = nil) register_initial_handlers + @offer = nil @tags = [] @commands = CommandRegistry.new @variables = {} @controllers = [] @end_reason = nil + @peers = {} self << offer if offer end # @@ -90,10 +85,18 @@ # def tagged_with?(label) @tags.include? label end + # + # Hash of joined peers + # @return [Hash<String => Adhearsion::Call>] + # + def peers + @peers.clone + end + def register_event_handler(*guards, &block) register_handler :event, *guards, &block end def deliver_message(message) @@ -115,31 +118,32 @@ throw :pass end on_joined do |event| target = event.call_id || event.mixer_name + @peers[target] = Adhearsion.active_calls[target] signal :joined, target end on_unjoined do |event| target = event.call_id || event.mixer_name + @peers.delete target signal :unjoined, target end on_end do |event| logger.info "Call ended" clear_from_active_calls @end_reason = event.reason commands.terminate - after(after_end_hold_time) { current_actor.terminate! } + after(Adhearsion.config.platform.after_hangup_lifetime) { current_actor.terminate! } throw :pass end end - # @private - def after_end_hold_time - 30 + def finalize + ::Logging::Repository.reset end ## # Registers a callback for when this call is joined to another call or a mixer # @@ -195,10 +199,11 @@ write_and_await_response Punchblock::Command::Answer.new(:headers => headers) end def reject(reason = :busy, headers = nil) write_and_await_response Punchblock::Command::Reject.new(:reason => reason, :headers => headers) + Adhearsion::Events.trigger_immediately :call_rejected, call: current_actor, reason: reason end def hangup(headers = nil) return false unless active? logger.info "Hanging up" @@ -338,9 +343,19 @@ end # @private def resume_controllers controllers.each(&:resume!) + end + + private + + def offer + @offer + end + + def client + @client end # @private class CommandRegistry < ThreadSafeArray def terminate