📄 sipmanager.java.svn-base
字号:
/**
* Queries the RegisterProcessing object whether the application is
* registered with a registrar.
*
* @return true if the application is registered with a registrar.
*/
public boolean isRegistered() {
return (registerProcessing != null && registerProcessing.isRegistered());
}
/**
* Determines whether the SipManager was started.
*
* @return true if the SipManager was started.
*/
public boolean isStarted() {
return isStarted;
}
// ============================ COMMUNICATION FUNCTIONALITIES =========================
/**
* Causes the CallProcessing object to send an INVITE request to the URI
* specified by <code>callee</code> setting sdpContent as message body.
* The method generates a Call object that will represent the resulting call
* and will be used for later references to the same call.
*
* @param callee the URI to send the INVITE to.
* @param sdpContent the sdp session offer.
* @return the Call object that will represent the call resulting from
* invoking this method.
* @throws CommunicationsException if an exception occurs while sending and parsing.
*/
public Call establishCall(String callee, String sdpContent)
throws CommunicationsException {
checkIfStarted();
if (isBusy()) return null;
return callProcessing.invite(callee, sdpContent);
} // CALL
// ------------------ hang up on
/**
* Causes the CallProcessing object to send a terminating request (CANCEL,
* BUSY_HERE or BYE) and thus terminate that call with id
* <code>callID</code>.
*
* @param callID the id of the call to terminate.
* @throws CommunicationsException if an exception occurs while invoking this method.
*/
public void endCall(int callID) throws CommunicationsException {
fireCallEnded(callProcessing.callDispatcher.getCall(callID));
checkIfStarted();
callProcessing.endCall(callID);
}
public void sendDTMF(int callID, String digit)
throws CommunicationsException {
callProcessing.sendDTMF(callID, digit);
}
public void hold(int callID, SessionDescription sdp, boolean mic, boolean cam)
throws CommunicationsException {
callProcessing.hold(callID, sdp.toString());
callProcessing.callDispatcher.getCall(callID).onHoldMic(mic);
callProcessing.callDispatcher.getCall(callID).onHoldCam(cam);
}
public void transfer(int callID, String callee) {
try {
transferProcessing.transfer(callID, callee);
}
catch (CommunicationsException e) {
e.printStackTrace();
}
}
/**
* Calls endCall for all currently active calls.
*
* @throws CommunicationsException if an exception occurs while
*/
public void endAllCalls() throws CommunicationsException {
try {
checkIfStarted();
if (!isRegistered()) {
return;
}
if (callProcessing == null) {
return;
}
Object[] keys = callProcessing.getCallDispatcher().getAllCalls();
for (int i = 0; i < keys.length; i++) {
endCall(((Integer) keys[i]).intValue());
}
}
finally {
setBusy(false);
}
}
/**
* Causes CallProcessing to send a 200 OK response, with the specified sdp
* description, to the specified call's remote party.
*
* @param callID the id of the call that is to be answered.
* @param sdpContent this party's media description (as defined by SDP).
* @throws CommunicationsException if an axeption occurs while invoking this method.
*/
public void answerCall(int callID, String sdpContent)
throws CommunicationsException {
checkIfStarted();
callProcessing.sayOK(callID, sdpContent);
} // answer to
/**
* Sends a NOT_IMPLEMENTED response through the specified transaction.
*
* @param serverTransaction the transaction to send the response through.
* @param request the request that is being answered.
*/
void sendNotImplemented(ServerTransaction serverTransaction, Request request) {
Response notImplemented = null;
try {
notImplemented = messageFactory.createResponse(
Response.NOT_IMPLEMENTED, request);
attachToTag(notImplemented, serverTransaction.getDialog());
}
catch (ParseException ex) {
fireCommunicationsError(new CommunicationsException(
"Failed to create a NOT_IMPLEMENTED response to a "
+ request.getMethod() + " request!", ex));
return;
}
try {
serverTransaction.sendResponse(notImplemented);
}
catch (SipException ex) {
fireCommunicationsError(new CommunicationsException(
"Failed to create a NOT_IMPLEMENTED response to a "
+ request.getMethod() + " request!", ex));
}
catch (InvalidArgumentException e) {
fireCommunicationsError(new CommunicationsException(
"Failed to create a NOT_IMPLEMENTED response to a "
+ request.getMethod() + " request!", e));
}
}
public void processIOException(IOExceptionEvent ioExceptionEvent) {
}
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
}
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
}
// ============================= Utility Methods ==================================
/**
* Initialises SipManager's fromHeader field in accordance with
* net.java.mais.sip.PUBLIC_ADDRESS net.java.mais.sip.DISPLAY_NAME
* net.java.mais.sip.TRANSPORT net.java.mais.sip.PREFERRED_LOCAL_PORT and
* returns a reference to it.
*
* @return a reference to SipManager's fromHeader field.
* @throws CommunicationsException if a ParseException occurs while initially composing the
* FromHeader.
*/
public FromHeader getFromHeader() throws CommunicationsException {
return this.getFromHeader(false);
}
public FromHeader getFromHeader(boolean isNew)
throws CommunicationsException {
if (fromHeader != null && !isNew) {
return fromHeader;
}
try {
SipURI fromURI = (SipURI) addressFactory
.createURI(currentlyUsedURI);
fromURI.setTransportParam(listeningPoint.getTransport());
fromURI.setPort(listeningPoint.getPort());
Address fromAddress = addressFactory.createAddress(fromURI);
if (displayName != null && displayName.trim().length() > 0) {
fromAddress.setDisplayName(displayName);
} else {
fromAddress
.setDisplayName(Credentials.getUserDisplay());
}
fromHeader = headerFactory.createFromHeader(fromAddress,
Integer.toString(hashCode()));
}
catch (ParseException ex) {
throw new CommunicationsException(
"A ParseException occurred while creating From Header!",
ex);
}
return fromHeader;
}
/**
* Same as calling getContactHeader(true)
*
* @return the result of getContactHeader(true)
* @throws CommunicationsException if an exception is thrown while calling
* getContactHeader(false)
* @uml.property name="contactHeader"
*/
public ContactHeader getContactHeader() throws CommunicationsException {
return getContactHeader(true);
}
/**
* Same as calling getContactHeader(true).
*
* @return the result of calling getContactHeader(true).
* @throws CommunicationsException if an exception occurs while executing
* getContactHeader(true).
*/
ContactHeader getRegistrationContactHeader() throws CommunicationsException {
return getContactHeader(true);
}
/**
* Initialises SipManager's contactHeader field in accordance with
* javax.sip.IP_ADDRESS net.java.mais.sip.DISPLAY_NAME
* net.java.mais.sip.TRANSPORT net.java.mais.sip.PREFERRED_LOCAL_PORT and
* returns a reference to it.
*
* @param useLocalHostAddress specifies whether the SipURI in the contact header should
* contain the value of javax.sip.IP_ADDRESS (true) or that of
* net.java.mais.sip.PUBLIC_ADDRESS (false).
* @return a reference to SipManager's contactHeader field.
* @throws CommunicationsException if a ParseException occurs while initially composing the
* FromHeader.
*/
public ContactHeader getContactHeader(boolean useLocalHostAddress)
throws CommunicationsException {
if (contactHeader != null) {
return contactHeader;
}
try {
SipURI contactURI;
if (useLocalHostAddress) {
contactURI = (SipURI) addressFactory.createSipURI(null,
Credentials.getUserDisplay()
+ "@"
+ publicIpAddress.getAddress()
.getHostAddress());
} else {
contactURI = (SipURI) addressFactory
.createURI(currentlyUsedURI);
}
// Forces NAT Traversal
// contactURI = (SipURI)
// addressFactory.createSipURI(null,Credentials.getUser()+
// "@" + publicIpAddress.getAddress().getHostAddress());
// contactURI.setTransportParam(listeningPoint.getTransport());
contactURI.setPort(publicIpAddress.getPort());
Address contactAddress = addressFactory
.createAddress(contactURI);
if (displayName != null && displayName.trim().length() > 0) {
contactAddress.setDisplayName(displayName);
}
contactHeader = headerFactory
.createContactHeader(contactAddress);
}
catch (ParseException ex) {
throw new CommunicationsException(
"A ParseException occurred while creating From Header!",
ex);
}
return contactHeader;
}
/**
* Initializes (if null) and returns an ArrayList with a single ViaHeader
* containing localhost's address. This ArrayList may be used when sending
* requests.
*
* @return ViaHeader-s list to be used when sending requests.
* @throws CommunicationsException if a ParseException is to occur while initializing the array
* list.
*/
public ArrayList<ViaHeader> getLocalViaHeaders() throws CommunicationsException {
ListeningPoint lp = sipProvider.getListeningPoint();
viaHeaders = new ArrayList();
try {
ViaHeader viaHeader = headerFactory.createViaHeader(SIPConfig
.getIPAddress(), lp.getPort(), lp.getTransport(), null);
viaHeader.setParameter("rport", null);
viaHeaders.add(viaHeader);
return viaHeaders;
}
catch (ParseException ex) {
throw new CommunicationsException(
"A ParseException occurred while creating Via Headers!");
}
catch (InvalidArgumentException ex) {
throw new CommunicationsException(
"Unable to create a via header for port "
+ lp.getPort(), ex);
}
}
/**
* Initializes and returns SipManager's maxForwardsHeader field using the
* value specified by MAX_FORWARDS.
*
* @return an instance of a MaxForwardsHeader that can be used when sending
* requests
* @throws CommunicationsException if MAX_FORWARDS has an invalid value.
*/
public MaxForwardsHeader getMaxForwardsHeader()
throws CommunicationsException {
if (maxForwardsHeader != null) {
return maxForwardsHeader;
}
try {
maxForwardsHeader = headerFactory
.createMaxForwardsHeader(MAX_FORWARDS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -