cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
Walkthrough Wednesdays

Does it exist any event which can show us that a call is connected?

352
Views
0
Helpful
0
Comments
This document was generated from CDN thread

Created by: Pavel Shirshov on 10-09-2013 12:36:37 PM
Hi guys,

Is it possible to catch the event which shows us that connection to other phone is set up? Why I'm asking that because when I catch "ConnConnectedEv" event in CallObserver object in my application the particular call haven't connected yet.For test I call by my application from my hardware cisco phone to my cell phone.My application considers that calls is set up (because the application get the "ConnConnectedEv" event), but my cell phone haven't begined ringing yet!. So I can decline the call on my cell phone, but the application doesn't get any signal about that.
You can find full sources of my test application below:
  1
  2import javax.telephony.*;
  3import javax.telephony.callcontrol.CallControlTerminalConnection;
  4import javax.telephony.events.*;
  5import com.cisco.cti.util.Condition;
  6import com.cisco.jtapi.extensions.*;
  7
  8public class CallTest
  9{
 10    CiscoTerminalConnection ctc = null;
 11
 12    public CallTest() throws Exception
 13    {
 14        String hostname = "10.5.5.5";
 15        String login = "jtapi.test";
 16        String passwd = "1q2w3e";
 17        String src = "61711";
 18
 19         /* start up JTAPI */
 20        CiscoJtapiPeer peer = (CiscoJtapiPeer)JtapiPeerFactory.getJtapiPeer(null);
 21
 22         /* connect to the provider */
 23        String providerString = hostname;
 24        providerString += ";login=" + login;
 25        providerString += ";passwd=" + passwd;
 26        CiscoProvider provider = (CiscoProvider) peer.getProvider(providerString);
 27
 28        /* wait for it to come into service */
 29        final Condition    provderInService = new Condition();
 30        provider.addObserver(new ProviderObserver() {
 31            public void providerChangedEvent (ProvEv [] eventList) {
 32                if (eventList == null) return;
 33                for (int i = 0; i < eventList.length; i++) {
 34                    if (eventList[i] instanceof ProvInServiceEv) {
 35                        provderInService.set();
 36                    }
 37                }
 38            }
 39        });
 40        provderInService.waitTrue();
 41
 42        final Condition addrInService = new Condition();
 43        CiscoAddress srcAddr = (CiscoAddress) provider.getAddress(src);
 44        srcAddr.addObserver(new AddressObserver() {
 45            public void addressChangedEvent(AddrEv[] eventList){
 46                if (eventList == null) {
 47                    System.out.println("addressChangedEvent is null");
 48                } else {
 49                    for(int i = 0; i < eventList.length; i++) {
 50                        AddrEv ev = eventList[i];
 51                        if (ev instanceof CiscoAddrInServiceEv) {
 52                            addrInService.set();
 53                        }
 54                    }
 55                }
 56            }
 57        });
 58        addrInService.waitTrue();
 59
 60        final Condition inCallActive = new Condition();
 61        srcAddr.addCallObserver(new CallObserver() {
 62            public void callChangedEvent (CallEv [] eventList) {
 63                if (eventList == null) {
 64                    System.out.println("Call Event - Null");
 65                } else {
 66                    System.out.println("Call Event:");
 67                    for (int i = 0; i < eventList.length; ++i) {
 68                        CiscoCall call = (CiscoCall)eventList[i].getCall();
 69                        if(call.getState() == CiscoCall.ACTIVE) {
 70                            Connection[] conns = call.getConnections();
 71
 72                            for(int j = 0; j < conns.length; j++) {
 73                                System.out.println("connection = " + j + " getState() = " + conns[j].getState());
 74                            }
 75                        }
 76                        System.out.println("Event current = " + call + " event = " + eventList[i].getClass().getName());
 77                    }
 78                }
 79                if (eventList == null) return;
 80                for (int i = 0; i < eventList.length; ++i) {
 81                    if (eventList[i] instanceof ConnConnectedEv) {
 82                        System.out.println("ConnConnectedEv");
 83                        ConnConnectedEv ev = (ConnConnectedEv) eventList[i];
 84                        CiscoCall call = (CiscoCall)eventList[i].getCall();
 85                        if(call.getState() == CiscoCall.ACTIVE) {
 86                            System.out.println("call.getState() == CiscoCall.ACTIVE");
 87                            Connection[] conns = call.getConnections();
 88                            for(int k = 0; k < conns.length; k++) {
 89                                System.out.println("connection = " + k + " getState() = " + conns[k].getState());
 90                                if(conns[i].getState() == Connection.CONNECTED) {
 91                                    inCallActive.set();
 92                                }
 93                            }
 94                        }
 95//                        }
 96                    }
 97                }
 98            }
 99        });
100
101
102        String num = "915555555555";
103        System.out.println("Call to number:" + num);
104        CiscoTerminal callingTerminal = (CiscoTerminal) srcAddr.getTerminals()[0];
105        CiscoCall call = (CiscoCall) provider.createCall();
106        call.connect(callingTerminal, srcAddr, num);
107        inCallActive.waitTrue();
108
109        System.out.println("Ok");
110    }
111
112    public static void main(String[] args) {
113        try {
114            new CallTest();
115        } catch (Exception e) {
116            e.printStackTrace();
117        } finally {
118            System.exit(0);
119        }
120    }
121}


You also can find the logs of my test call (I printed all events out on the screen for debug):

 1
 2Call to number:915555555555
 3Call Event:
 4connection = 0 getState() = 51
 5Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.CallActiveEvImpl
 6connection = 0 getState() = 51
 7Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.ConnCreatedEvImpl
 8connection = 0 getState() = 51
 9Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.ConnConnectedEvImpl
10connection = 0 getState() = 51
11Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.TermConnCreatedEvImpl
12connection = 0 getState() = 51
13Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.TermConnActiveEvImpl
14ConnConnectedEv
15call.getState() == CiscoCall.ACTIVE
16connection = 0 getState() = 51
17Call Event:
18connection = 0 getState() = 51
19connection = 1 getState() = 51
20Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.ConnCreatedEvImpl
21Call Event:
22connection = 0 getState() = 51
23connection = 1 getState() = 51
24Event current = (P1-jtapi.test) GCID=(1,1582453)->ACTIVE event = com.cisco.jtapi.ConnConnectedEvImpl
25ConnConnectedEv
26call.getState() == CiscoCall.ACTIVE
27connection = 0 getState() = 51
28connection = 1 getState() = 51
29Ok


Subject: RE: Does it exist any event which can show us that a call is connected?
Replied by: Alexander Anikin on 11-09-2013 01:39:44 AM
Pavel, your program will receive ConnConnectedEv for far side if you allow it to wait a bit longer.

Subject: RE: Does it exist any event which can show us that a call is connected?
Replied by: Pavel Shirshov on 11-09-2013 06:35:34 PM
Alexander Anikin:
Pavel, your program will receive ConnConnectedEv for far side if you allow it to wait a bit longer.
Alexander,

Thank you for your answer. 
The program stops working, so I waited as long as I can.
If you check the output of the program you can see that my program got ConnConnectedEv a couple times. The second time I see, that connection states for both calls are Connection.CONNECTED (51).

Maybe I'm wrong in my CallObserver? Can you please help me?

Subject: RE: Does it exist any event which can show us that a call is connected?
Replied by: Abhishek Malhotra on 12-09-2013 04:36:33 AM
There are 3 problems with your code, so let me explain what is happening in your code.

When you get first set of events to your call observer, only 1 connection(for near end) exists for the call which is already in connected state.
So, if you look at your logs, at line 16, your log prints only 1 connection, which is in connected state, so you code goes ahead and  does inCallActive.set() because at that point there is no second connection in the call which it could iterate and find not connected and your code ends.

Problem 2 - So, question is why does it print more logs after the condition is set and your code ends. Thats second part of your problem, you are handling events on JTAPI's thread and not your own thread. 
public void callChangedEvent (CallEv [] eventList) {} - this method is invoked on JTAPI's thread. You are suppose to return from this method call as soon as possible so the JTAPI thread can deliver you more events as quickly as possible. To do this you need to take copyOf Array and pass it to a different thread of yours which you should use to process events while returning the method immediately while your other thread(s) processes those event(s).

Third problem is that your java program never ends, calling System.exit(0) is the worse way to end program because it tells us that you didnt clean up things properly. You need to remove the observers and shutdown the provider inorder to gracefully end your program.


Subject: RE: Does it exist any event which can show us that a call is connected?
Replied by: Pavel Shirshov on 19-09-2013 06:51:16 PM
Hi Abhishek,

Thank you for your commentary. It's really turn me into right direction. I create a new thread and run my code from there. I don't know why but it's magically helps me to receive all events what I should receive.

Thanks
Content for Community-Ad