Sha256: 22eceff4b064f80107d555bf45ab17ea01a59fcc12a191346598812d3ace0a1b

Contents?: true

Size: 862 Bytes

Versions: 2

Compression:

Stored size: 862 Bytes

Contents

# encoding: utf-8

require 'ruby_ami'

module Punchblock
  module Connection
    class Asterisk < GenericConnection
      attr_reader :ami_client, :translator
      attr_accessor :event_handler

      def initialize(options = {})
        @ami_client = RubyAMI::Client.new options.merge(:event_handler => lambda { |event| translator.async.handle_ami_event event }, :logger => pb_logger)
        @translator = Translator::Asterisk.new @ami_client, self, options[:media_engine]
        super()
      end

      def run
        ami_client.start
        raise DisconnectedError
      end

      def stop
        translator.async.shutdown
        ami_client.stop
      end

      def write(command, options)
        translator.async.execute_command command, options
      end

      def handle_event(event)
        event_handler.call event
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
punchblock-1.8.2 lib/punchblock/connection/asterisk.rb
punchblock-1.8.1 lib/punchblock/connection/asterisk.rb