⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstest.java

📁 JTAPI Sample application for using AVAYA AES from vemsoft
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    //In order to make a call, we need to obtain an Address and a Terminal
                    //object that represent the dialing extension.  In Avaya's implementation
                    //of JTAPI, there is a one-to-one relationship between the Terminal and 
                    //Address objects that represent an extension number.
                    
                    // create Address
                    address = provider.getAddress( callingNumber );
                    System.out.println("Address " + callingNumber + " created successfully.\n\n");
                    
                    // create Terminal
        	        terminal = provider.getTerminal(callingNumber);
        	        System.out.println("Terminal " + callingNumber + " created successfully.\n\n");
                } catch (Exception e) {
    	            System.out.println( "\nPlease verify that the dialing extension number is correct.\n\n" );
    	            throw (e);
    	        }
                    
                System.out.println("Adding a callObserver to the terminal.\n\n");

                try {
                    // add callObserver to terminal
                    terminal.addCallObserver( this );
                    
                    // create Call
                    call = provider.createCall();
                } catch (Exception e) {
    	            throw (e);
    	        }
            	        
                try {
        	        // makecall by using the connect method of the Call object
                    System.out.println("Making call from " + callingNumber + " to " + calledNumber + "...\n\n");
                    connections = call.connect(terminal, address, calledNumber); 
                } catch (Exception e) {
    	            System.out.println( "\nPlease verify that the phone that you're dialing from is ready to initiate calls.\n\n" );
    	            throw (e);
    	        }
    	        
    	    } catch (Exception e) {
    	        System.out.println("makecall() caught " + e + "\n");
    	        System.out.println( "Message: " + e.getMessage() + "\n\n" );
                return;
    	    }
    	} else {
    	    System.out.println("Unable to make call - provider was not created successfully.\n\n");
    	}
    	return;
    }

   /**
    * This method disconnects the specified terminalConnection.
    */
    public void hangup( TerminalConnection terminalConnection ) 
    {
    	try {
            // drop existing connection at the terminal
    	    System.out.println("\nDropping connection...\n\n");
            if ( terminalConnection != null ) {
                terminalConnection.getConnection().disconnect();
            }
    	} catch (Exception e) {
    	    System.out.println("hangup() caught " + e + "\n");
    	    System.out.println( "Message: " + e.getMessage() + "\n\n" );
            return;
    	}
    }
    
   /**
    * This method removes the CallObserver on the Terminal and shuts down
    * the Provider.
    */
    public synchronized void logout() {   
        
        CallObserver[]      callObserver = null;
		ProviderObserver[]  providerObserver = null;
		
		if ( provider != null ) {
		    
		    if ( provider.getState() == Provider.IN_SERVICE ) {
        		
        		if ( (providerObserver = provider.getObservers()) != null ) {
        		    provider.removeObserver ( providerObserver[0] );
        		}
        		
        		if ( (callObserver = terminal.getCallObservers()) != null ) {
        		    terminal.removeCallObserver ( callObserver[0] );
        		}
                
                System.out.println("\nShutting down provider...\n\n");
        		
        		try {
        		    // shutdown the provider
        		    provider.shutdown();
        		} catch ( PlatformException e ) {
                    System.out.println ( "provider.shutdown() caught PlatformException\n" );
        	        System.out.println( "Message: " + e.getMessage() + "\n\n" );
        	    }
            
		    }
		    System.out.println( "Dial aviable!" );
            provider = null;
        }
    }
    
   /**
    * This method calls the appropriate method to handle each event.
    */
    public void handleEvent( Ev event ) {
        
        switch ( event.getID() ) {
            case TermConnActiveEv.ID:
    	        handleConnActive();
    	        break;
    	    case TermConnDroppedEv.ID:
    	        handleConnDropped();
    	        break;
    	    case CallObservationEndedEv.ID:
    	        logout();
    	        break;
    	}  
    }
    
   /**
    * When there is a connection active, change button label to "Hang up".
    */
    public void handleConnActive() 
    {
    	System.out.println ( "Connection Active ---> Can HangUp" );
    }	
    
   /**
    * When a connection has been dropped, change button label to "Dial".
    */
    public void handleConnDropped() 
    {
    	System.out.println ( "Connection Dropped ---> Can Dial" );
    }
    
   /**
	* This method is required to implement the ProviderObserver --
	* the implementation will call this routine to notify state changes
	* in the Provider.
	*/
	public synchronized void providerChangedEvent ( ProvEv[] eventList )
    {
	    for ( int i=0; i<eventList.length; i++ )
        {
	        switch(eventList[i].getID())
            {
                case ProvInServiceEv.ID:        //handle provider in service
    	            notify ();                  // login() is waiting on this event
    	            System.out.println ( "Provider In Service!" );
            		break;
            	default:
            		System.out.println ( "Provider Changed Event: "+eventList[i].getID());
            	    break;
		    }
		}
    }
    
   /**
	* This method is required to implement the CallObserver --
	* the implementation will call this routine to notify state changes
	* in the call.
	*/
	public void callChangedEvent(CallEv[] eventList) 
    {
        int i =0;

        for ( i = 0; i < eventList.length; i++ ) {
            
            System.out.println("Received ");
            switch(eventList[i].getID())
            {
                case CallActiveEv.ID:
	                System.out.println("Call Active Event\n");
	                break;
                case CallInvalidEv.ID:
	                System.out.println("Call Invalid Event\n");
	                break;
                case ConnAlertingEv.ID:
	                System.out.println("Connection Alerting Event\n");
	                break;
	            case ConnConnectedEv.ID:
	                System.out.println("Connection Connected Event\n");
	                break;
	            case ConnCreatedEv.ID:
	                System.out.println("Connection Created Event\n");
	                break;
	            case ConnDisconnectedEv.ID:
	                System.out.println("Connection Disconnected Event\n");
	                break;
	            case ConnFailedEv.ID:
        		    System.out.println("Connection Failed Event\n");
	                break;
                case ConnInProgressEv.ID:
	                System.out.println("Connection In Progress Event\n");
	                break;
	            case ConnUnknownEv.ID:
        		    System.out.println("Connection Unknown Event\n");
	                break;
	            case TermConnActiveEv.ID:
        		    //when this event is received, it means we have a call active
        		    //on our terminal.  Change label to "Hang up".
        		    System.out.println("TerminalConnection Active Event\n");
	                handleEvent (eventList[i]);
	                break;
	            case TermConnCreatedEv.ID:
        		    System.out.println("TerminalConnection Created Event\n");
	                break;
	            case TermConnDroppedEv.ID:
        		    //when this event is received, it means that our device has
        		    //disconnected from the call.  Change button label to "Dial"
	                System.out.println("TerminalConnection Dropped Event\n");
	                handleEvent (eventList[i]);
	                break;
	            case TermConnPassiveEv.ID:
        		    System.out.println("TerminalConnection Passive Event\n");
	                break;
	            case TermConnRingingEv.ID:
        		    System.out.println("TerminalConnection Ringing Event\n");
	                break;
	            case TermConnUnknownEv.ID:
        		    System.out.println("TerminalConnection Unknown Event\n");
	                break;
                case CallObservationEndedEv.ID:
	                //when call is terminated, either manually or from the
	                //app, shutdown the provider
	                System.out.println("Call Observation Ended Event\n");
	                handleEvent (eventList[i]);
	                break;
	            default:
	                System.out.println("Unknown CallEv: " + eventList[i].getID() + "\n");
	                break;
		    }
		}
   	}
   	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -