Sha256: 8ab0f8d3bfdc9fec57cc5265756c514f707d186cdc4662ba0d919cde40f67716

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'pry'

module Adhearsion
  module Console
    include Adhearsion

    class << self
      ##
      # Start the Adhearsion console
      #
      def run
        Pry.prompt = [
                        proc do |*args|
                          obj, nest_level, pry_instance = args
                          "AHN#{'  ' * nest_level}> "
                        end,
                        proc do |*args|
                          obj, nest_level, pry_instance = args
                          "AHN#{'  ' * nest_level}? "
                        end
                      ]
        Pry.config.command_prefix = "%"
        pry
      end

      def logger
        Adhearsion::Logging
      end

      def calls
        Adhearsion.active_calls
      end

      def use(call)
        unless call.is_a? Adhearsion::Call
          raise ArgumentError unless Adhearsion.active_calls[call]
          call = Adhearsion.active_calls[call]
        end
        Pry.prompt = [ proc { "AHN<#{call.channel}> "},
                       proc { "AHN<#{call.channel}? "}  ]

        # Pause execution of the thread currently controlling the call
        call.with_command_lock do
          CallWrapper.new(call).pry
        end
      end
    end

    class CallWrapper
      attr_accessor :call

      def initialize(call)
        @call = call
        extend Adhearsion::VoIP::Commands.for('asterisk')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-1.2.6 lib/adhearsion/console.rb
adhearsion-1.2.5 lib/adhearsion/console.rb
adhearsion-1.2.4 lib/adhearsion/console.rb