📄 softphonemanager.java
字号:
}
/**
* Handle an RegisterRequest
*
* @param username username
* @param authUserName Authorization username
* @param password password
*/
public void handleRegisterRequest(String username, String authUserName, String password) {
this.authUserName = authUserName;
this.username = username;
this.password = password;
try {
sipManager.startRegisterProcess(username, authUserName, password);
}
catch (CommunicationsException exc) {
Log.error("handleRegisterRequest", exc);
}
}
/**
* Add a CommunicationsListener
*
* @param communicationsListener CommunicationsListener
*/
public void addCommunicationsListener(CommunicationsListener communicationsListener) {
sipManager.addCommunicationsListener(communicationsListener);
}
/**
* Fired when a call ends
*
* @param evt CallEvent
*/
public void callEnded(CallEvent evt) {
AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
if (audioMediaSession != null) {
audioMediaSession.close();
}
}
/**
* Fired when a call is received
*
* @param evt CallEvent
*/
public void callReceived(CallEvent evt) {
try {
Call call = evt.getSourceCall();
Interlocutor interlocutor = new Interlocutor();
interlocutor.setCall(call);
guiManager.addInterlocutor(interlocutor);
call.addStateChangeListener(this);
// handleAnswerRequest(interlocutor);
}
catch (Exception e) {
Log.error("callReceived", e);
}
}
/**
* Fired when a message is received
*
* @param evt MessageEvent
*/
public void messageReceived(MessageEvent evt) {
for (SoftPhoneListener sfl : softPhoneListeners) {
sfl.messageReceived(evt);
}
}
/**
* Fired when a call is rejected locally
*
* @param evt CallRejectedEvent
*/
public void callRejectedLocally(CallRejectedEvent evt) {
String reason = evt.getReason();
String detailedReason = evt.getDetailedReason();
}
/**
* Fired when a call is rejected remotly
*
* @param evt CallRejectedEvent
*/
public void callRejectedRemotely(CallRejectedEvent evt) {
for (SoftPhoneListener softPhoneListener : softPhoneListeners) {
softPhoneListener.callRejectedRemotely(evt);
}
}
/**
* Fired when softphone is register sucessfully
*
* @param evt RegistrationEvent
*/
public void registered(RegistrationEvent evt) {
status = SipRegisterStatus.Registered;
preferences.setPreferredAddress(NetworkAddressManager.getLocalHost().getHostAddress());
//preference.commit();
registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.Registered, evt.getReason()));
if (callTo.length() > 2) {
handleDialRequest(callTo);
}
registerMenu.setSelected(true);
}
public void registrationFailed(RegistrationEvent evt) {
status = SipRegisterStatus.RegistrationFailed;
registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.RegistrationFailed, evt.getReason()));
registerMenu.setSelected(false);
}
/**
* Fired when softphone is registering
*
* @param evt RegistrationEvent
*/
public void registering(RegistrationEvent evt) {
status = SipRegisterStatus.Registering;
registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.Registering, evt.getReason()));
}
/**
* Fired when softphone is unregistered sucessfully
*
* @param evt RegistrationEvent
*/
public void unregistered(RegistrationEvent evt) {
try {
status = SipRegisterStatus.Unregistered;
registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.Unregistered, evt.getReason()));
// we could now exit
synchronized (unregistrationLock) {
unregistrationLock.notifyAll();
}
destroySoftPhone();
registerMenu.setSelected(false);
}
catch (Exception e) {
Log.error("unregistered", e);
}
}
/**
* Fired when softphone is unregistering
*
* @param evt RegistrationEvent
*/
public void unregistering(RegistrationEvent evt) {
status = SipRegisterStatus.Unregistered;
registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.Unregistering, evt.getReason()));
int waitUnreg = SIPConfig.getWaitUnregistration();
if (waitUnreg != -1) {
try {
int delay = waitUnreg;
// we get here through a _synchronous_ call from shutdown so
// let's try
// and wait for unregistrations confirmation in case the
// registrar has requested authorization
// before conriming unregistration
if (delay > 0)
synchronized (unregistrationLock) {
unregistrationLock.wait(delay);
}
}
catch (InterruptedException ex) {
Log.error("unregistering", ex);
}
catch (NumberFormatException ex) {
Log.error("unregistering", ex);
}
}
}
private void registerStatusChanged(RegisterEvent evt) {
for (SoftPhoneListener sfl : softPhoneListeners) {
sfl.registerStatusChanged(evt);
}
}
/**
* Returns the current interlocutors
*
* @return List<InterlocutorUI>
*/
public List<InterlocutorUI> getInterlocutors() {
return guiManager.getInterlocutors();
}
/**
* Fired when softphone receive a unknown sip message
*
* @param evt RegistrationEvent
*/
public void receivedUnknownMessage(UnknownMessageEvent evt) {
// TODO Do something with the error.
}
/**
* Fired when communications Errors Occurred
*
* @param evt CommunicationsErrorEvent
*/
public void communicationsErrorOccurred(CommunicationsErrorEvent evt) {
}
/**
* Fired when call state changes
*
* @param evt CallStateEvent
*/
public void callStateChanged(CallStateEvent evt) {
try {
for (SoftPhoneListener sfl : softPhoneListeners) {
sfl.callStateChanged(evt);
}
Call call = evt.getSourceCall();
Log.debug("callStateChanged", evt.getOldState() + " -> "
+ evt.getNewState());
if (evt.getNewState() == Call.CONNECTED) {
//sipManager.setBusy(true);
if (call.getAudioReceiverChannel() != null)
call.getAudioReceiverChannel().stop();
if (evt.getOldState() == Call.MOVING_REMOTELY) {
AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
if (call.getAudioReceiverChannel() != null)
call.getAudioReceiverChannel().stop();
if (audioMediaSession != null) {
audioMediaSession.stopTrasmit();
audioMediaSession.stopReceive();
}
PhoneManager.setUsingMediaLocator(false);
}
int localPort = ((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort();
AudioMediaSession audioMediaSession = mediaManager.createAudioMediaSession(call.getRemoteSdpDescription().toString(), localPort);
call.setAudioMediaSession(audioMediaSession);
if (audioMediaSession != null) {
audioMediaSession.startTrasmit();
audioMediaSession.startReceive();
}
evt.getSourceCall().start();
Log.debug("MEDIA STREAMS OPENED");
} else if (evt.getNewState() == Call.RINGING) {
if (call.getRemoteSdpDescription() != null
&& !call.getRemoteSdpDescription().equals("")) {
Log.debug("STATE", call.getRemoteSdpDescription().toString());
int localPort = ((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort();
int destPort = ((MediaDescription) (call.getRemoteSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort();
String destIp = call.getRemoteSdpDescription().getConnection().getAddress();
AudioReceiverChannel audioReceiverChannel = mediaManager.createAudioReceiverChannel(localPort, destIp, destPort);
call.setAudioReceiverChannel(audioReceiverChannel);
if (audioReceiverChannel != null)
audioReceiverChannel.start();
}
} else if (evt.getNewState() == Call.DISCONNECTED) {
sipManager.setBusy(false);
AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
if (audioMediaSession != null) {
audioMediaSession.stopTrasmit();
audioMediaSession.stopReceive();
}
if (call.getAudioReceiverChannel() != null)
call.getAudioReceiverChannel().stop();
PhoneManager.setUsingMediaLocator(false);
} else if (evt.getNewState() == Call.FAILED) {
call.setState(Call.DISCONNECTED);
if (call.getAudioReceiverChannel() != null)
call.getAudioReceiverChannel().stop();
CallRejectedEvent rejectEvt = new CallRejectedEvent("Disconnected", call.getLastRequest(), call);
for (SoftPhoneListener softPhoneListener : softPhoneListeners) {
softPhoneListener.callRejectedRemotely(rejectEvt);
}
PhoneManager.setUsingMediaLocator(false);
}
}
catch (Exception e) {
Log.error("callStateChanged", e);
}
}
/**
* Handle a exit request
*/
public void handleExitRequest() {
if (mediaManager != null) {
}
// SIP unregister
if (sipManager != null) {
try {
sipManager.endAllCalls();
}
catch (CommunicationsException exc) {
Log.error("handleExitRequest", exc);
}
catch (Throwable exc) {
Log.error("handleExitRequest", exc);
}
try {
sipManager.unregister();
}
catch (CommunicationsException exc) {
Log.error("handleExitRequest", exc);
}
catch (Throwable exc) {
Log.error("handleExitRequest", exc);
}
try {
sipManager.stop();
}
catch (Exception exc) {
Log.error("handleExitRequest", exc);
}
}
NetworkAddressManager.shutDown();
}
/**
* Handle a Hold request
*
* @param iui the InterlocutorUI
* @param mic true to place on hold.
* @param cam true to place camera on hold.
*/
public void handleHold(InterlocutorUI iui, boolean mic, boolean cam) {
try {
sipManager.hold(iui.getID(), mediaManager.generateHoldSdpDescription(mic, mic, iui.getCall()), mic, cam);
}
catch (Exception e) {
Log.error("handleHold", e);
}
}
public void handleTransfer(int callID, String callee) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -