« Back to Cisco JTAPI Questions

How do I answer a call with a CTI route point?

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hi,
 
I'd like to write a program that registers a CTI route point, accepts incoming calls and plays a message.
I could register the CTI Route point, but I think the little bit that accepts the call is missing.
If I call the RP, I receive a CallActiveEv and a ConnConnectedEv (that seems to indicate that the phone the call is started from is now connected), but there is no event I can get a RTPHandle or so from. After about a second, the call is disconnected and I get a busy tone on my phone.
 
Any Idea what's wrong or missing in the code below? Or does anyone has some example code for me?
 
Thanks in advance
 
Jörg
 
 
public class ConditionalForwarder implements ProviderObserver, CiscoTerminalObserver, CiscoAddressObserver, CallObserver,MediaCallObserver, CallControlTerminalObserver, PhoneTerminalObserver {

    static private Log log = LogFactory.getLog(ConditionalForwarder.class);

    Condition providerInService = new Condition();
    Condition terminalInService = new Condition();
    Condition addressInService = new Condition();

    CiscoProvider provider;
    CiscoRouteTerminal terminal;
    CiscoAddress address;

    public ConditionalForwarder(String host, String userid, String password, String deviceName) {

        String providerString= host + ";login=" + userid + ";passwd=" + password;
        try {
            JtapiPeer peer = JtapiPeerFactory.getJtapiPeer ( null );
            provider = (CiscoProvider)peer.getProvider(providerString);
            provider.addObserver(this);
            providerInService.waitTrue();
            terminal = (CiscoRouteTerminal)provider.getTerminal(deviceName);
            CiscoMediaCapability[] cap = {new CiscoG711MediaCapability()};
            terminal.register(cap,CiscoRouteTerminal.DYNAMIC_MEDIA_REGISTRATION);
            terminal.addObserver(this);
            terminal.addCallObserver(this);
            address = (CiscoAddress)terminal.getAddresses()[0];
            address.addObserver(this);
            address.addCallObserver(this);
            terminalInService.waitTrue();
            addressInService.waitTrue();
            log.info("Initialization done.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void providerChangedEvent(ProvEv[] eventList) {
        if ( eventList != null ) {
            for ( int i = 0; i < eventList.length; i++ )
            {
                log.debug(eventList.getClass().getCanonicalName());
                if ( eventList instanceof ProvInServiceEv ) {
                    providerInService.set();
                    return;
                }
            }
        }
    }

    public void callChangedEvent(CallEv[] eventList) {
        if ( eventList != null ) {
            for ( int i = 0; i < eventList.length; i++ )
            {
                CallEv event = eventList;
                log.debug("CALL: " + event.getClass().getCanonicalName());   
                CiscoCall call = (CiscoCall)event.getCall();
                Connection[] connections = call.getConnections();
                for(int j=0; i<connections.length;j++) {
                    log.info(connections.getAddress().getName() + " State: " + getStateName(connections.getState()));
                }
            }
        }
    }

    public void addressChangedEvent(AddrEv[] eventList) {
        if ( eventList != null ) {
            for ( int i = 0; i < eventList.length; i++ )
            {
                log.debug("ADDRESS: " + eventList.getClass().getCanonicalName());
                if ( eventList instanceof CiscoAddrInServiceEv ) {
                    addressInService.set();
                    return;
                }
            }
        }
    }

    public void terminalChangedEvent(TermEv[] eventList) {
        if ( eventList != null ) {
            for ( int i = 0; i < eventList.length; i++ )
            {
                log.debug("TERMINAL: " + eventList.getClass().getCanonicalName());
                if ( eventList instanceof CiscoTermInServiceEv ) {
                    terminalInService.set();
                    return;
                }
            }
        }
    }

    public static String getStateName(int state) {
        switch(state) {
        case (Connection.ALERTING) : return "ALERTING";
        case (Connection.CONNECTED) : return "CONNECTED";
        case (Connection.DISCONNECTED) : return "DISCONNECTED";
        case (Connection.FAILED) : return "FAILED";
        case (Connection.IDLE) : return "IDLE";
        case (Connection.INPROGRESS) : return "INPROGRESS";
        case (Connection.UNKNOWN) : return "UNKNOWN";
        default : return "OTHER";
        }
    }

    public static void main(String[] args) {

        new ConditionalForwarder("10.129.32.20", "condFwd", "XXXX","CONFWD01");
    }

}

Applications controlling CTIPort and Route points should accept the call or setup auto accept. Use CiscoAddress.<strong style="line-height: normal; white-space: pre;">setAutoAcceptStatus(int autoAcceptStatus, javax.telephony.Terminal terminal) to enable auto accept. Once the call is accepted, application will see Terminal
Connection events ie <strong style="line-height: normal; font-family: Times; font-size: medium;">TermConnRingingEv and <strong style="line-height: normal; font-family: Times; font-size: medium;">CallCtlTermConnRingingEv.
 
After receiving these events application should answer the call. After the call is answered application will see a 
<h2 style="font-family: Times;">CiscoMediaOpenLogicalChannelEv. Application should get the RTP handle from this event and set the IP address and port number. </h2>
Application will also recieve CiscoRTP events indicating the IP address and port number of the calling party that can be used to stream media to the caller. 
 
CiscoJTAPI implementation doesn't provide any drivers to play media but Cisco RTP events provide enough information for application to stream media.