我正在使用Asterisk和星号java构建简单的传出IVR我在同一网络中的两台不同的计算机(A和B)中安装了Xlite软电话,并将它们设置在星号上,我可以成功呼叫它们这是我的星号java代码
public class PhoneUtility {
private static ManagerConnection instanceManagerConnection;
private static ManagerConnection getManagerConnectionInstance() {
if (instanceManagerConnection == null) {
ManagerConnectionFactory factory = new
ManagerConnectionFactory("192.132.0.01", "admin", "amp111");
instanceManagerConnection = factory.createManagerConnection();
}
return instanceManagerConnection;
}
public static boolean phoneCall() {
try {
ManagerConnection managerConnection = getManagerConnectionInstance();
OriginateAction originateAction;
ManagerResponse originateResponse;
originateAction = new OriginateAction();
originateAction.setChannel("SIP/ivan");
originateAction.setCallerId("1234");
originateAction.setContext("ivr-ext");
originateAction.setExten("1235");
originateAction.setPriority(new Integer(1));
originateAction.setActionId("2");
originateAction.setTimeout(300000l);
originateAction.setAsync(new Boolean(false));
// connect to Asterisk and log in
managerConnection.login();
AsteriskServerImpl asteriskServer = new AsteriskServerImpl(managerConnection);
AsteriskChannel asteriskChannel = asteriskServer.originate(originateAction);
// Play a prompt by text to speach
Character dtmf = asteriskChannel.getDtmfSent();
if (dtmf.equals("1")) {
managerConnection.logoff();
return true;
} else {
managerConnection.logoff();
return false;
}
} catch (Exception e) {
System.out.println(e);
return false;
}
}
}
我在计算机A中执行代码(调用phoneCall())来调用计算机B当代码在计算机A中执行时,我的软电话首先在计算机A响起,如何通过编码自动为计算机a打开通道(我根本不想在计算机a中有软电话)
您可以先让电话B响,如果有人接听,然后电话A响(IVR分机将被自动接听的IVR APP取代),方法是:
用扩展交换来电显示,如下所示:
originateAction = new OriginateAction();
originateAction.setChannel("SIP/1235");
originateAction.setCallerId("1235");//put the target extension here
originateAction.setContext("ivr-ext");
originateAction.setExten("1234"); //put IVR-extension here
originateAction.setPriority(new Integer(1));
originateAction.setActionId("2");
originateAction.setTimeout(300000l);
originateAction.setAsync(new Boolean(false));