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 Type Property Name Description
String Extension The terminals Extension
String Protocol Which protocol the terminal is using, e.g. SIP
String IP The IP address of the terminal
Int32 Port The port the terminal is connected to
String CurrentStatus The current state of the terminal, e.g. the current state of the last changed channel
List<ManagedSocket> Listeners A list of ManagedSockets that will receive detailed messages about the terminals status
List<ManagedSocket> MonitorListeners A list of ManagedSockets that will receive basic details about the terminals status
Dictionary<Double, Channel> ClonedChannels This is used to track transfers of channels
ChannelsCollection Channels A list of channels currently linked to the terminal
State PhoneState A basic overview of the terminals state, e.g. Free, Busy, Receiving

Pubic methods

Method Type Method Name Description
String getCurrentChannels Returns 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 Type Property Name Description
String Name The channels name
String StateDescription A basic description of the current state of the Channel, e.g. Ringing
Boolean Alive Is the Channel alive
Double Uniqueid The Channels Uniqueid ID
Channel OutgoingCall A link to the Channels outgoing Channel
Channel IncomingCall A link to the Channels incoming Channel
String CallerIDNum The Channels Caller ID Number
String CallerIDName The Channels Caller ID Name
String Exten The Extension the Channel is trying to reach
Boolean OnHold This Channel has placed the other Channel OnHold
Boolean PlacedOnHold This Channel has been placed OnHold - Works for internal calls only
Phone CurrentPhone A link to the phone this Channel is currently on
ChannelTransfer Transfered A link to the Channel that transfered this Channel
ChannelBridge BridgedTo A link to the Channel this Channel is currently Bridged to
Boolean InternalCall Is internal Call
Boolean Cloned Channel has been cloned
Boolean SplitDial Split this Channel when it received a new Dial command - Used to track accurate call stats
Boolean LeftQueue Channel has left a queue
Boolean JoinedQueue Channel as joined a queue
String QueueExtension The extension of the queue the Channel was in
State State A basic state of the Channel, e.g. Free, Busy or Recieving

Last edited Jun 16, 2011 at 9:19 AM by Cadey, version 5

Comments

No comments yet.