您现在的位置:首页 > >

Hello Jtapi World!

发布时间:

我的第一个控制CTIPort的Jtapi程序,功能是控制一个CTI Port执行外拨,实现了电话信令的控制,但还没有涉及语音传输。实现的过程中遇到并克服了如下困难:


1 在CallManager中必须正确配置CTI Port并添加End User或者Application User并与该CTI Port关联,关键的是


必须把此用户添加到CTI Enable和CTI Control of All Devices


2 Jtapi一书中的示例代码只对Call 对象添加了Observer,并没有对Address和Terminal添加Observer,Address和


Terminal对象只有添加了Observer,才能监控Address和Terminal的状态并使用Observer处理Address和Terminal的Events


3 我使用3个Condition来判断Provider、Address和Terminal是否是InService状态,并在它们添加完Observer后waitTrue(),但运行程序后没有反应,后来Debug发现程序阻塞到AddressInService这个Condition的waitTrue(),因此想到Address没有InService,而我前一个Jtapi程序控制Cisco IP Comunicator就没问题,分析感觉是CTI Port没有注册的原因,去看别人代码,发现了别人使用了register()函数来注册,于是我改写了程序,先去注册Terminal再waitTrue() AddressInService和TerminalInService


/**************************************************************************************


*??? Outcall.java??????????????????????????????????????????????????????????????????????????????????????????????????????????????????? *


**************************************************************************************/


import javax.telephony.*;

import com.cisco.cti.util.Condition;

import org.apache.log4j.Logger;


/*

?Condition conditionInService = new Condition();

??String providerString = providerName + ";login=" + login + ";passwd="

??Address origaddr = null;

????term1 = terminals[i];


????try {

??????if (observedTerminal != null

?public static void main(String[] args) {

?public void providerChangedEvent(ProvEv[] evenList) {

?public void addressChangedEvent(AddrEv[] events) {

?}


?public void terminalChangedEvent(TermEv[] events) {


??for (int i = 0; i < events.length; i++) {

???switch (events[i].getID()) {

/**************************************************************************************


*??? MyOutCallObserver.java????????????????????????????????????????????????????????????????????????????????????????????? *


**************************************************************************************/


import javax.telephony.*;

/*
?* The MyOutCallObserver class implements the CallObserver
?* interface and receives all events associated with the Call.
?*/
public class MyOutCallObserver implements CallObserver {
?public void callChangedEvent(CallEv[] evlist) {
??for (int i = 0; i < evlist.length; i++) {
???if (evlist[i] instanceof ConnEv) {
????String name = null;
????try {
?????Connection connection = ((ConnEv) evlist[i])
???????.getConnection();
?????Address addr = connection.getAddress();
?????name = addr.getName();
????} catch (Exception excp) {
?????// Handle Exceptions
?????excp.printStackTrace();
????}
????String msg = "Connection to Address: " + name + " is ";
????if (evlist[i].getID() == ConnAlertingEv.ID) {
?????System.out.println(msg + "ALERTING");
????} else if (evlist[i].getID() == ConnInProgressEv.ID) {
?????System.out.println(msg + "INPROGRESS");
????} else if (evlist[i].getID() == ConnConnectedEv.ID) {
?????System.out.println(msg + "CONNECTED");
????} else if (evlist[i].getID() == ConnDisconnectedEv.ID) {
?????System.out.println(msg + "DISCONNECTED");
????}
???}
??}
?}
}


友情链接: 医学资料大全 农林牧渔 幼儿教育心得 小学教育 中学 高中 职业教育 成人教育 大学资料 求职职场 职场文档 总结汇报