Skip to content

Commit

Permalink
add dial options to blind transfer activity
Browse files Browse the repository at this point in the history
  • Loading branch information
rlsutton1 committed Apr 6, 2020
1 parent acb034b commit 41e85c8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,31 @@ public class BlindTransfer

static public void main(String[] args) throws IOException, AuthenticationFailedException, TimeoutException
{
/**
* Initialise the PBX Factory. You need to implement your own AsteriskSettings class.
*/
/**
* Initialise the PBX Factory. You need to implement your own
* AsteriskSettings class.
*/
PBXFactory.init(new ExamplesAsteriskSettings());

/**
* Activities utilise an agi entry point in your dial plan.
* You can create your own entry point in dialplan or have
* asterisk-java add it automatically
* Activities utilise an agi entry point in your dial plan. You can
* create your own entry point in dialplan or have asterisk-java add it
* automatically
*/
AsteriskPBX asteriskPbx = (AsteriskPBX) PBXFactory.getActivePBX();
asteriskPbx.createAgiEntryPoint();

// We are all configured lets try and do a blind transfer.
blindTransfer();
}

static private void blindTransfer()
{
PBX pbx = PBXFactory.getActivePBX();

// The trunk MUST match the section header (e.g. [default]) that appears
// in your /etc/asterisk/sip.d file (assuming you are using a SIP trunk).
// in your /etc/asterisk/sip.d file (assuming you are using a SIP
// trunk).
// The trunk is used to select which SIP trunk to dial through.
Trunk trunk = pbx.buildTrunk("default");

Expand Down Expand Up @@ -85,11 +87,12 @@ public void progress(DialActivity activity, ActivityStatusEnum status, String me
{

@Override
public void progress(BlindTransferActivity activity, ActivityStatusEnum status, String message)
public void progress(BlindTransferActivity activity, ActivityStatusEnum status,
String message)
{
// if success the blind transfer completed.
}
});
}, "");
}
if (status == ActivityStatusEnum.FAILURE)
System.out.println("Oops something bad happened when we dialed.");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/asteriskjava/pbx/PBX.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface PBX
* @param ActivityCallback
*/
BlindTransferActivity blindTransfer(final Call call, OperandChannel channelToTransfer, final EndPoint transferTarget,
final CallerID toCallerID, boolean autoAnswer, long timeout);
final CallerID toCallerID, boolean autoAnswer, long timeout, String dialOptions);

/**
* The BlindTransferActivity is used by the AsteriksPBX to transfer a live
Expand All @@ -73,7 +73,7 @@ BlindTransferActivity blindTransfer(final Call call, OperandChannel channelToTra
* is reached the Blind Transfer will be cancelled.
*/
void blindTransfer(Call call, OperandChannel channelToTransfer, final EndPoint transferTarget, final CallerID toCallerID,
boolean autoAnswer, long timeout, ActivityCallback<BlindTransferActivity> callback);
boolean autoAnswer, long timeout, ActivityCallback<BlindTransferActivity> callback, String dialOptions);

/**
* Sends a DTMF tone to given channel. Not returning until the tone has been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class AgiChannelActivityBlindTransfer implements AgiChannelActivityAction
private String sipHeader;
int timeout = 30;
private String callerId;
private String dialOptions;

public AgiChannelActivityBlindTransfer(String fullyQualifiedName, String sipHeader, String callerId)
public AgiChannelActivityBlindTransfer(String fullyQualifiedName, String sipHeader, String callerId, String dialOptions)
{
this.target = fullyQualifiedName;
this.sipHeader = sipHeader;
this.callerId = callerId;
this.dialOptions = dialOptions;
if (sipHeader == null)
{
this.sipHeader = "";
Expand All @@ -34,7 +36,7 @@ public void execute(AgiChannel channel, Channel ichannel) throws AgiException, I
channel.setVariable("__SIPADDHEADER", sipHeader);
channel.setCallerId(callerId);
ichannel.setCurrentActivityAction(new AgiChannelActivityHold());
channel.dial(target, timeout, "");
channel.dial(target, timeout, dialOptions);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class BlindTransferActivityImpl extends ActivityHelper<BlindTransferActiv

final Channel actualChannelToTransfer;

private String dialOptions;

/**
* Blind transfers a live channel to a given endpoint which may need to be
* dialed. When we dial the endpoint we display the 'toCallerID'.
Expand All @@ -78,7 +80,7 @@ public class BlindTransferActivityImpl extends ActivityHelper<BlindTransferActiv
*/
public BlindTransferActivityImpl(Call call, final Call.OperandChannel channelToTransfer, final EndPoint transferTarget,
final CallerID toCallerID, boolean autoAnswer, long timeout,
final ActivityCallback<BlindTransferActivity> listener)
final ActivityCallback<BlindTransferActivity> listener, String dialOptions)
{
super("BlindTransferActivity", listener);

Expand All @@ -88,14 +90,15 @@ public BlindTransferActivityImpl(Call call, final Call.OperandChannel channelToT
this._toCallerID = toCallerID;
this._autoAnswer = autoAnswer;
this._timeout = timeout;
this.dialOptions = dialOptions;

actualChannelToTransfer = _call.getOperandChannel(this._channelToTransfer);

this.startActivity(true);
}

public BlindTransferActivityImpl(Channel agentChannel, EndPoint transferTarget, CallerID toCallerID, boolean autoAnswer,
int timeout, ActivityCallback<BlindTransferActivity> iCallback) throws PBXException
int timeout, ActivityCallback<BlindTransferActivity> iCallback, String dialOptions) throws PBXException
{
super("BlindTransferActivity", iCallback);

Expand All @@ -104,6 +107,7 @@ public BlindTransferActivityImpl(Channel agentChannel, EndPoint transferTarget,
this._autoAnswer = autoAnswer;
this._timeout = timeout;
actualChannelToTransfer = agentChannel;
this.dialOptions = dialOptions;
_channelToTransfer = OperandChannel.ORIGINATING_PARTY;
this._call = new CallImpl(agentChannel, CallDirection.OUTBOUND);
this.startActivity(true);
Expand Down Expand Up @@ -150,7 +154,7 @@ public boolean doActivity() throws PBXException
sipHeader = PBXFactory.getActiveProfile().getAutoAnswer();
}
actualChannelToTransfer.setCurrentActivityAction(new AgiChannelActivityBlindTransfer(
this._transferTarget.getFullyQualifiedName(), sipHeader, _toCallerID.getNumber()));
this._transferTarget.getFullyQualifiedName(), sipHeader, _toCallerID.getNumber(), dialOptions));

// TODO: At one point we were adding the /n option to the end of the
// channel to get around
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public boolean isBridgeSupported()

@Override
public BlindTransferActivity blindTransfer(Call call, Call.OperandChannel channelToTransfer, EndPoint transferTarget,
CallerID toCallerID, boolean autoAnswer, long timeout)
CallerID toCallerID, boolean autoAnswer, long timeout, String dialOptions)
{
final CompletionAdaptor<BlindTransferActivity> completion = new CompletionAdaptor<>();

final BlindTransferActivityImpl transfer = new BlindTransferActivityImpl(call, channelToTransfer, transferTarget,
toCallerID, autoAnswer, timeout, completion);
toCallerID, autoAnswer, timeout, completion, dialOptions);

completion.waitForCompletion(timeout + 2, TimeUnit.SECONDS);

Expand All @@ -145,16 +145,19 @@ public BlindTransferActivity blindTransfer(Call call, Call.OperandChannel channe

@Override
public void blindTransfer(Call call, Call.OperandChannel channelToTransfer, EndPoint transferTarget, CallerID toCallerID,
boolean autoAnswer, long timeout, ActivityCallback<BlindTransferActivity> listener)
boolean autoAnswer, long timeout, ActivityCallback<BlindTransferActivity> listener, String dialOptions)
{
new BlindTransferActivityImpl(call, channelToTransfer, transferTarget, toCallerID, autoAnswer, timeout, listener);
new BlindTransferActivityImpl(call, channelToTransfer, transferTarget, toCallerID, autoAnswer, timeout, listener,
dialOptions);

}

public BlindTransferActivity blindTransfer(Channel agentChannel, EndPoint transferTarget, CallerID toCallerID,
boolean autoAnswer, int timeout, ActivityCallback<BlindTransferActivity> iCallback) throws PBXException
boolean autoAnswer, int timeout, ActivityCallback<BlindTransferActivity> iCallback, String dialOptions)
throws PBXException
{
return new BlindTransferActivityImpl(agentChannel, transferTarget, toCallerID, autoAnswer, timeout, iCallback);
return new BlindTransferActivityImpl(agentChannel, transferTarget, toCallerID, autoAnswer, timeout, iCallback,
dialOptions);

}

Expand Down

0 comments on commit 41e85c8

Please sign in to comment.