Asterisk AMI Classes

As you should be aware the Asterisk AMI Proxy suite does a few more things than just proxy AMI messages from Asterisk to clients. The Asterisk AMI Proxy suite also produces extra messages to so you can build your own Extension monitors, line monitors and call stats.

None of the extra features would be possible without two key classes and they are the Phone class and the Channel class. The other classes listed are merely helper classes but we will explain their roles here too.

Phone Class

The Phone class holds basic information about an extension on the Asterisk PBX and also stores which channels are currently linked to it. The phone class also stores lists of sockets which get added when a client sends the correct command. For example

string message = "Command:Listen\r\nExtension: 2000\r\n\r\n"

Pubic properties

Property TypeProperty NameDescription
StringExtensionThe terminals Extension
StringProtocolWhich protocol the terminal is using, e.g. SIP
StringIPThe IP address of the terminal
Int32PortThe port the terminal is connected to
StringCurrentStatusThe current state of the terminal, e.g. the current state of the last changed channel
List<ManagedSocket>ListenersA list of ManagedSockets that will receive detailed messages about the terminals status
List<ManagedSocket>MonitorListenersA list of ManagedSockets that will receive basic details about the terminals status
Dictionary<Double, Channel>ClonedChannelsThis is used to track transfers of channels
ChannelsCollectionChannelsA list of channels currently linked to the terminal
StatePhoneStateA basic overview of the terminals state, e.g. Free, Busy, Receiving

Pubic methods

Method TypeMethod NameDescription
StringgetCurrentChannelsReturns a shapshot of all the current channels on the terminal

ChannelsCollection Class

Instead of using a standard Collection to store the phoes channels (such as a List<Channels>) we have made our own simpe collection. The ChannelsCollection simply wires up each new Channel added so that the phone handles the channels events, and we do this in the Add Method.

public void Add(Channel item)
{
     this.List.Add(item);
     item.LinkPhone(_owner);
     _owner.ChannelAdded(item);
     item.ChannelUpdated += new Channel.ChannelUpdatedDelegate(_owner.OnChannelUpdated);
     item.UniqueidChanged += new Channel.UniqueidChangedDelegate(_owner.OnChannelUniqueidChanged);
     item.ChannelStateUpdated += new Channel.ChannelStateUpdatedDelegate(_owner.OnChannelStateUpdated);
}

Callstat Class

The CallStat class simply represents a unit of information about a channels time on the terminal. Callstat items are generated inside the Phone class because it’s the time a channel is linked to a terminal that is important in any accurate call stats. Lots of more basic call stat systems for Asterisk do this purely with the channel which leads to inaccurate stats. For example when you transfer a channel, Asterisk will clone a channel and move it to the new terminal. When you only generate stats based on the channel this will result in only the last person to use that channel getting all its call time.

Channel Class

This Channel class has more properties than any other class in the Asterisk AMI Proxy suite and this is due to the amount of stages a Channel can pass through during any typical call.

Pubic properties

Property TypeProperty NameDescription
StringNameThe channels name
StringStateDescriptionA basic description of the current state of the Channel, e.g. Ringing
BooleanAliveIs the Channel alive
DoubleUniqueidThe Channels Uniqueid ID
ChannelOutgoingCallA link to the Channels outgoing Channel
ChannelIncomingCallA link to the Channels incoming Channel
StringCallerIDNumThe Channels Caller ID Number
StringCallerIDNameThe Channels Caller ID Name
StringExtenThe Extension the Channel is trying to reach
BooleanOnHoldThis Channel has placed the other Channel OnHold
BooleanPlacedOnHoldThis Channel has been placed OnHold - Works for internal calls only
PhoneCurrentPhoneA link to the phone this Channel is currently on
ChannelTransferTransferedA link to the Channel that transfered this Channel
ChannelBridgeBridgedToA link to the Channel this Channel is currently Bridged to
BooleanInternalCallIs internal Call
BooleanClonedChannel has been cloned
BooleanSplitDialSplit this Channel when it received a new Dial command - Used to track accurate call stats
BooleanLeftQueueChannel has left a queue
BooleanJoinedQueueChannel as joined a queue
StringQueueExtensionThe extension of the queue the Channel was in
StateStateA basic state of the Channel, e.g. Free, Busy or Recieving