CallManager.java
Upload User: liulanlin
Upload Date: 2017-12-08
Package Size: 1274k
Code Size: 4k
Category:

VOIP program

Development Platform:

Java

  1. /*
  2.  * CallManager.java
  3.  * 
  4.  * Created on Mar 15, 2004
  5.  *
  6.  */
  7. package gov.nist.applet.phone.ua.call;
  8. import java.util.Iterator;
  9. import java.util.Vector;
  10. /**
  11.  * This class manage all the calls of the application
  12.  * 
  13.  * @author Jean Deruelle <jean.deruelle@nist.gov>
  14.  *
  15.  * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
  16.  */
  17. public class CallManager {
  18. private Vector imCalls=null;
  19. private Vector audioCalls=null;
  20. /**
  21.  * Creates a new instance of the call manager  
  22.  */
  23. public CallManager() {
  24. imCalls=new Vector();
  25. audioCalls=new Vector();
  26. }
  27. /**
  28.  * Find the Audio call for a specified callee
  29.  * @param callee - the callee
  30.  * @return the Audio call currently bound to the callee 
  31.  */
  32. public AudioCall findAudioCall(String callee){
  33. //System.out.println("Test against "+ callee);
  34. Iterator it=audioCalls.iterator();
  35. while(it.hasNext()){
  36. AudioCall call=(AudioCall)it.next();
  37. //System.out.println("callee "+ call.getCallee());
  38. if(call.getCallee().equalsIgnoreCase(callee))
  39. return call;
  40. }
  41. return null;
  42. }
  43. /**
  44.  * Find the Instant Messaging call for a specified callee
  45.  * @param callee - the callee
  46.  * @return the IM call currently bound to the callee 
  47.  */
  48. public IMCall findIMCall(String callee){
  49. //System.out.println("Test against "+ callee);
  50. Iterator it=imCalls.iterator();
  51. while(it.hasNext()){
  52. IMCall call=(IMCall)it.next();
  53. //System.out.println("callee "+ call.getCallee());
  54. if(call.getCallee().equalsIgnoreCase(callee))
  55. return call;
  56. }
  57. return null;
  58. }
  59. /**
  60.  * Find an existing call with the matching dialogId in parameter 
  61.  * @param dialogId - the dialog Id of the searched call 
  62.  * @return call matching the dialogId in parameter
  63.  */
  64. public Call findCall(String dialogId){
  65. Iterator it=imCalls.iterator();
  66. while(it.hasNext()){
  67. Call call=(Call)it.next();
  68. //System.out.println("callee "+ call.getCallee());
  69. if(call.getDialog().getDialogId().equalsIgnoreCase(dialogId))
  70. return call;
  71. }
  72. it=audioCalls.iterator();
  73. while(it.hasNext()){
  74. Call call=(Call)it.next();
  75. //System.out.println("callee "+ call.getCallee());
  76. if(call.getDialog().getDialogId().equalsIgnoreCase(dialogId))
  77. return call;
  78. }
  79. return null;
  80. }
  81. /**
  82.  * Add a new Media call to the call manager
  83.  * @param audioCall - the Media call to add
  84.  */
  85. public void addAudioCall(AudioCall audioCall){
  86. audioCalls.add(audioCall);
  87. }
  88. /**
  89.  * Add a new Instant Messaging call to the call manager
  90.  * @param imCall - the Instant Messaging call to add
  91.  */
  92. public void addIMCall(IMCall imCall){
  93. imCalls.add(imCall);
  94. }
  95. /**
  96.  * Remove an Audio call from the call manager
  97.  * @param audioCall - the audio call to remove
  98.  */
  99. public void removeAudioCall(AudioCall audioCall){
  100. audioCalls.remove(audioCall);
  101. }
  102. /**
  103.  * Remove an Instant Messaging call from the call manager
  104.  * @param imCall - the Instant Messaging call to remove
  105.  */
  106. public void removeIMCall(IMCall imCall){
  107.                 if (imCall.getDialog() != null) {
  108.                         imCall.getDialog().delete();
  109.                 }
  110. imCalls.remove(imCall);
  111. }
  112. /** Remove an im call given its id.
  113. *@param imcallId -- id for removing the IM call.
  114. */
  115. public void  removeIMCall(String callId) {
  116. Iterator it = audioCalls.iterator();
  117. while (it.hasNext() ) {
  118. Call c = (Call) it.next();
  119. IMCall call;
  120. if (c  instanceof IMCall) {
  121. call = (IMCall) c;
  122. } else {
  123.  continue;
  124. }
  125. if (call.getCallee().equals(callId) ) it.remove();
  126.                         if (call.getDialog() != null) {
  127.                                 call.getDialog().delete();
  128.                         }
  129. }
  130. }
  131. /**
  132.  * Tells if a media session is already active
  133.  * @return true if there is already an audio call active
  134.  */
  135. public boolean isAlreadyInAudioCall(){
  136. Iterator it=audioCalls.iterator();
  137. while(it.hasNext()){
  138. Call call=(Call)it.next();
  139. if(call.getStatus().equalsIgnoreCase(Call.IN_A_CALL))
  140. return true;
  141. }
  142. return false;
  143. }
  144. }