-
Notifications
You must be signed in to change notification settings - Fork 300
Tutorial
The Tutorial is designed to take you through some common operations that you may want to do with an Asterisk PBX. The Tutorial focuses on using Activities as they are the easiest way of interacting with Asterisk.
You should read the Getting Started guide before reading this Tutorial.
The Getting Started guide showed you how to do a simple dial. Lets now do some more interesting things with a Call.
// Need to get the list of channels that make up a call?
// Remember that a call could be a conference call so it could have three or more channels.
List<Channel> channels = call.getChannels();
// Lets do a blind transfer of the call.
EndPoint mySuperviser = pbx.buildEndPoint(Tech.SIP, "101");
CallerID toCallerID = pbx.buildCallerId("100", "Show this to my supervisor");
// blind transfer the remote party (the person we originally dialed or called us) to my supervisor
// don't auto answer the call (that would be rude) and
// wait 30 seconds for the call to be answered or give up
iBlindTransferActivity blindTransfer = pbx.blindTransfer(call, OperandChannel.REMOTE_PARTY, mySupervisor, toCallerID, false, 30);
if (blindTransfer.getCompletionCause() == CompletionCause.BRIDGED)
{
// call was answered.
Call callTransferedToSupervisor = blindTransfer.getNewCall();
// be rude and now hangup or don't and our job is done
pbx.hangup(callTransferedToSupervisor);
}
This time lets put the called/calling party on hold
// First we need to split the call into its two channels
iSplitActivity split = pbx.split(call);
// now we have split the call into two separate calls, we can deal with them separately.
pbx.hangup(split.getLHSCall());
Call heldCall = split.getRHSCall();
// Now hold the call.
pbx.hold(heldCall);
The above code splits the call into two separate calls, hangs up the call to your handset and puts the remote party on hold. The methods getLHSCall and getRHSCall mean get LEFT HAND SIDE and get RIGHT HAND SIDE. This terminology is somewhat opaque and we are looking for a better way of naming these methods. For now the LHS will always be the originating party and the RHS the called party. After a split there is only one channel per Call and both are marked as the local party.
So now lets take the call off hold. We do this by blind transferring the call back to your extension using autoanswer.
// Lets do a blind transfer of the onhold call back to your own extension
EndPoint myPhone = pbx.buildEndPoint(Tech.SIP, "100");
CallerID toCallerID = pbx.buildCallerID("100", "Show this on my phone");
// blind transfer the remote party (the person we originally dialed) back to me
// don't auto answer the call and
// wait 30 seconds for the call to be answered or give up
iBlindTransferActivity blindTransfer = pbx.blindTransfer(heldCall, OperandChannel.LOCAL_PARTY, myPhone, toCallerID, true, 30);
if (blindTransfer.getCompletionCause() == CompletionCause.BRIDGED)
{
// call was answered and is no longer on hold.
Call callTransferedToSelf = blindTransfer.getNewCall();
}
So now lets Mute a call. Firstly we need to check that our version of asterisk supports the mute operation.
if (pbx.isMuteSupported())
{
// We mute the remote party so we can hear them but they can't hear us.
pbx.mute(call.getChannel(OperandChannel.REMOTE_PARTY));
}