📄 javaphoneframe.java
字号:
{
m_iPortA = 42028;
m_iPortB = 42028;
m_iHeartBeat = -1;
m_sHostA = "localhost";
m_sHostB = "localhost";
m_iPeripheralID = 0;
m_bAutoAnswer = false;
// initialize edit boxes
m_edtConnection.setText("Offline");
m_edtHostA.setText("localhost");
m_edtPortA.setText("42028");
m_edtHostB.setText("localhost");
m_edtPortB.setText("42028");
m_edtAgentID.setText("5000");
m_edtPassword.setText("5000");
m_edtInstrument.setText("5000");
m_edtPeripheralID.setText("5000");
m_edtCallID.setText("no call");
SetSessionConnected(false);
SetAgentStateText(eUnknown);
Log("Welcome to the Java CIL Softphone Sample\r\n");
Log("To start please connect\r\n");
// disable buttons
m_btnLogin.setEnabled(false);
m_btnLogout.setEnabled(false);
m_btnReady.setEnabled(false);
m_btnNotReady.setEnabled(false);
m_btnMakeCall.setEnabled(false);
m_btnAnswer.setEnabled(false);
m_btnRelease.setEnabled(false);
m_btnHold.setEnabled(false);
m_btnRetrieve.setEnabled(false);
m_btnCCConference.setEnabled(false);
m_btnConference.setEnabled(false);
m_btnSSConference.setEnabled(false);
m_btnCCTransfer.setEnabled(false);
m_btnTransfer.setEnabled(false);
m_btnSSTransfer.setEnabled(false);
} // Initialize
///////////////////////////////////////////////////////////////////////////
/**
* Check to see if the session is connected to the server
*/
///////////////////////////////////////////////////////////////////////////
boolean IsSessionConnected()
{
synchronized(m_cs)
{
return m_bSessionConnected;
}
} // IsSessionConnected
///////////////////////////////////////////////////////////////////////////
/**
* Set the Session connected flag
*/
///////////////////////////////////////////////////////////////////////////
void SetSessionConnected(boolean bConnected)
{
synchronized(m_cs)
{
m_bSessionConnected = bConnected;
}
} // SetSessionConnected
///////////////////////////////////////////////////////////////////////////
/**
* Get the Agent's peripheral ID
*/
///////////////////////////////////////////////////////////////////////////
int GetPeripheralID()
{
synchronized(m_cs)
{
return m_iPeripheralID;
}
} // GetPeripheralID
///////////////////////////////////////////////////////////////////////////
/**
* Set the Agent's peripheral ID
*/
///////////////////////////////////////////////////////////////////////////
void SetPeripheralID(int PeripheralID)
{
synchronized(m_cs)
{
m_iPeripheralID = PeripheralID;
}
} // SetPeripheralID
///////////////////////////////////////////////////////////////////////////
/**
* Get the Agent ID
*/
///////////////////////////////////////////////////////////////////////////
String GetAgentID()
{
synchronized(m_cs)
{
return m_sAgentID;
}
} // GetAgentID
///////////////////////////////////////////////////////////////////////////
/**
* Set the Agent ID
*/
///////////////////////////////////////////////////////////////////////////
void SetAgentID( String AgentID)
{
synchronized(m_cs)
{
m_sAgentID = AgentID;
}
} // SetAgentID
///////////////////////////////////////////////////////////////////////////
/**
* Get the Agent's Instrument
*/
///////////////////////////////////////////////////////////////////////////
String GetAgentInstrument()
{
synchronized(m_cs)
{
return m_sAgentInstrument;
}
} // GetAgentInstrument
///////////////////////////////////////////////////////////////////////////
/**
* Set the Agent's Instrument
*/
///////////////////////////////////////////////////////////////////////////
void SetAgentInstrument( String AgentInstrument)
{
synchronized(m_cs)
{
m_sAgentInstrument = AgentInstrument;
}
} // SetAgentInstrument
///////////////////////////////////////////////////////////////////////////
/**
* Get the Agent's Extension
*/
///////////////////////////////////////////////////////////////////////////
String GetAgentExtension()
{
synchronized(m_cs)
{
return m_sAgentExtension;
}
} // GetAgentExtension
///////////////////////////////////////////////////////////////////////////
/**
* Set the Agent's Extension
*/
///////////////////////////////////////////////////////////////////////////
void SetAgentExtension( String AgentExtension )
{
synchronized(m_cs)
{
m_sAgentExtension = AgentExtension;
}
} // SetAgentExtension
///////////////////////////////////////////////////////////////////////////
/**
* Get the Agent's Password
*/
///////////////////////////////////////////////////////////////////////////
String GetAgentPassword()
{
synchronized(m_cs)
{
return m_sAgentPassword;
}
} // GetAgentPassword
///////////////////////////////////////////////////////////////////////////
/**
* Set the Agent's Password
*/
///////////////////////////////////////////////////////////////////////////
void SetAgentPassword( String AgentPassword )
{
synchronized(m_cs)
{
m_sAgentPassword = AgentPassword;
}
} // SetAgentPassword
///////////////////////////////////////////////////////////////////////////
/**
* Set the AutoAnswer flag
*/
///////////////////////////////////////////////////////////////////////////
void SetAutoAnswer(boolean bAutoAnswer)
{
synchronized(m_cs)
{
m_bAutoAnswer = bAutoAnswer;
}
} // SetAutoAnswer
///////////////////////////////////////////////////////////////////////////
/**
* Get the AutoAnswer flag
*/
///////////////////////////////////////////////////////////////////////////
boolean GetAutoAnswer()
{
synchronized(m_cs)
{
return m_bAutoAnswer;
}
} // GetAutoAnswer
///////////////////////////////////////////////////////////////////////////
/**
* Set the Session object reference
*/
///////////////////////////////////////////////////////////////////////////
void SetCtiosSession(CtiOsSession Session)
{
synchronized(m_cs)
{
m_ctiSession = Session;
}
} // SetCtiosSession
///////////////////////////////////////////////////////////////////////////
/**
* Get the Session object reference
*/
///////////////////////////////////////////////////////////////////////////
CtiOsSession GetCtiosSession()
{
synchronized(m_cs)
{
return m_ctiSession;
}
} // GetCtiosSession
///////////////////////////////////////////////////////////////////////////
/**
* Get a reference to the Agent object
*/
///////////////////////////////////////////////////////////////////////////
Agent GetAgent()
{
synchronized(m_cs)
{
return m_ctiAgent;
}
} // GetAgent
///////////////////////////////////////////////////////////////////////////
/**
* Change the Agent's state text
*/
///////////////////////////////////////////////////////////////////////////
void SetAgentStateText(int iNewState)
{
final int iState = iNewState;
// Run this code on the EventDispatch thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
m_edtAgentState.setText( AgentStateToString(iState) );
}
});
} // SetAgentState
///////////////////////////////////////////////////////////////////////////
/**
* Check to see if we have a Login in progress
*/
///////////////////////////////////////////////////////////////////////////
boolean IsLoginInProgress()
{
synchronized(m_cs)
{
return m_bLoginInProgress;
}
} // IsLoginInProgress
///////////////////////////////////////////////////////////////////////////
/**
* Set the Login in progress flag
*/
///////////////////////////////////////////////////////////////////////////
void SetLoginInProgress(boolean bVal)
{
synchronized(m_cs)
{
m_bLoginInProgress = bVal;
}
} // SetLoginInProgress
///////////////////////////////////////////////////////////////////////////
/**
* Get the current state of the Agent
*/
///////////////////////////////////////////////////////////////////////////
int GetAgentState()
{
synchronized(m_cs)
{
if (m_ctiAgent != null)
return m_ctiAgent.GetAgentState();
else
return CtiOs_Enums.AgentState.eUnknown;
}
} // GetAgentState
///////////////////////////////////////////////////////////////////////////
/**
* Convert agent state enum to string
*/
///////////////////////////////////////////////////////////////////////////
public String AgentStateToString(int iState)
{
// Use the enum utility method to get the string name of the
// state and chop the "e" off of the beginning
String s = CtiOs_EnumStrings.AgentStateToString(iState);
if (null != s && s.length() > 0)
{
return s.substring(1);
}
return "Unknown";
} // AgentStateToString
///////////////////////////////////////////////////////////////////////////
/**
* Log event contents to the log window
*/
///////////////////////////////////////////////////////////////////////////
public void LogEvent(String msg, Arguments rArguments)
{
// Display event name
String s = msg + " Event received";
Log(s);
s = "\t";
// Create and display event contents
String sTemp = rArguments.toString();
int beginIndex = 0;
// Print each element on new line plus tab offset for
// pretty output :)
for (int i=0; i<sTemp.length(); i++)
{
if (sTemp.charAt(i) == ' ')
{
s += (sTemp.substring(beginIndex, i)) + "\r\n\t";
beginIndex = i+1;
}
}
s += (sTemp.substring(beginIndex, sTemp.length())) + "\r\n";
Log(s);
} // LogEvent
///////////////////////////////////////////////////////////////////////////
/**
* Write a message to the log window
*/
///////////////////////////////////////////////////////////////////////////
public void Log(final String sNewMsg)
{
final String sWinText = m_edtLogWindow.getText();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
String sNewText = sWinText + "\r\n" + sNewMsg;
m_edtLogWindow.setText(sNewText);
m_edtLogWindow.select(sNewText.length(), (sNewText.length() + 1));
}
});
} // Log
///////////////////////////////////////////////////////////////////////////
/**
* Write a message to the log window and the trace output
*/
///////////////////////////////////////////////////////////////////////////
public void AddLogMessage(String sMessage)
{
Log(sMessage);
Trace(0x01, sMessage);
} // AddLogMessage
///////////////////////////////////////////////////////////////////////////
/**
* Disconnect from the CTI OS server
*/
///////////////////////////////////////////////////////////////////////////
public void Disconnect()
{
// Can't disconnect if we're not connected
if ( IsSessionConnected() )
{
// Setup to wait for the OnConnectionClosed event following
// Disconnect(). Need to do this so we can wait for that event
// before unsubscribing for events.
Arguments rWaitArgs = new Arguments();
rWaitArgs.SetValue("Event1", eOnConnectionClosed);
WaitObject rWaitObj = m_ctiSession.CreateWaitObject(rWaitArgs);
// Perform disconnect
m_ctiSession.Disconnect( new Arguments() );
// Wait for OnConnectionClosed for 5 seconds
rWaitObj.WaitOnMultipleEvents(5);
// Allow the Session to clean up the wait object
m_ctiSession.DestroyWaitObject(rWaitObj);
}
// Unsubscribe for CTI events
if (m_ctiSession != null)
m_ctiSession.RemoveEventListener(m_eventSink, eAllInOneList);
} // Disconnect
} // class JavaPhoneFrame
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -