Sha256: 414e39f56b122a50c78ccb9d9c60e28764b899928b1810aecd39894796e998f1

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

# This is a file which shows you how to use the Asterisk Manager Interface library in a standalone Ruby script.

PATH_TO_ADHEARSION = File.join(File.dirname(__FILE__), "/../..")

MANAGER_CONNECTION_INFORMATION = {
  :host     => "10.0.1.97",
  :username => "jicksta",
  :password => "roflcopter",
  :events   => true
}

require 'rubygems'
begin
  require 'adhearsion'
rescue LoadError
  begin
    require File.join(PATH_TO_ADHEARSION, "/lib/adhearsion")
  rescue LoadError
    abort "Could not find Adhearsion! Please update the PATH_TO_ADHEARSION constant in this file"
  end
end

require 'adhearsion/voip/asterisk/manager_interface'

# If you'd like to see the AMI protocol data, change this to :debug
Adhearsion::Logging.logging_level = :warn

# This makes addressing the ManagerInterface class a little cleaner
include Adhearsion::VoIP::Asterisk::Manager

# Let's instantiate a new ManagerInterface object and have it automatically connect using the Hash we defined above.
interface = ManagerInterface.connect MANAGER_CONNECTION_INFORMATION

# Send an AMI action with our new ManagerInterface object. This will return an Array of SIPPeer events.
sip_peers = interface.send_action "SIPPeers"

# Pretty-print the SIP peers on the server

if sip_peers.any?
  sip_peers.each do |peer|
    # Uncomment the following line to view all the headers for each peer.
    # p peer.headers
    
    peer_name   = peer.headers["ObjectName"]
    peer_status = peer.headers["Status"]
    
    puts "#{peer_name}: #{peer_status}"
  end
else
  puts "This Asterisk server has no SIP peers!"
end

Version data entries

12 entries across 12 versions & 6 rubygems

Version Path
eric-adhearsion-0.8.0 examples/asterisk_manager_interface/standalone.rb
jicksta-adhearsion-0.7.999 examples/asterisk_manager_interface/standalone.rb
jicksta-adhearsion-0.8.0 examples/asterisk_manager_interface/standalone.rb
jicksta-adhearsion-0.8.2 examples/asterisk_manager_interface/standalone.rb
jicksta-adhearsion-0.8.3 examples/asterisk_manager_interface/standalone.rb
kenwiesner-adhearsioncw-0.8.3 examples/asterisk_manager_interface/standalone.rb
mtrudel-adhearsion-0.8.3 examples/asterisk_manager_interface/standalone.rb
sevenscale-adhearsion-0.8.0 examples/asterisk_manager_interface/standalone.rb
adhearsion-0.8.3 examples/asterisk_manager_interface/standalone.rb
adhearsion-0.8.0 examples/asterisk_manager_interface/standalone.rb
adhearsion-0.8.2 examples/asterisk_manager_interface/standalone.rb
adhearsion-0.8.1 examples/asterisk_manager_interface/standalone.rb