📄 callprocessing.java
字号:
console.logExit();
}
}
// ----------------- Responses --------------------------
//NOT FOUND
public void processNotFound(ClientTransaction clientTransaction, Response response)
{
try
{
console.logEntry();
if (!clientTransaction.getDialog().getFirstTransaction().getRequest().
getMethod().equals(Request.INVITE)) {
//Not for us
console.debug("ignoring not found response");
return;
}
//find the call
Call call = callDispatcher.findCall(clientTransaction.
getDialog());
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Server returned a NOT FOUND Response",
response
);
}
finally
{
console.logExit();
}
}
public void processNotImplemented(ClientTransaction clientTransaction,
Response response)
{
try
{
console.logEntry();
if (!clientTransaction.getDialog().getFirstTransaction().getRequest().
getMethod().equals(Request.INVITE)) {
//Not for us
console.debug("ignoring not implemented response");
return;
}
//find the call
Call call = callDispatcher.findCall(clientTransaction.
getDialog());
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Server returned a NOT IMPLEMENTED Response",
response
);
}
finally
{
console.logExit();
}
}
//-------------------------------- User Initiated processing ---------------------------------
public Call invite(String callee, String sdpContent) throws
CommunicationsException
{
try
{
console.logEntry();
callee = callee.trim();
//Handle default domain name (i.e. transform 1234 -> 1234@sip.com
String defaultDomainName =
Utils.getProperty("net.java.sip.communicator.sip.DEFAULT_DOMAIN_NAME");
if (defaultDomainName != null //no sip scheme
&& callee.indexOf('@') == -1 //most probably a sip uri
) {
callee = callee + "@" + defaultDomainName;
}
//Let's be uri fault tolerant
if (callee.toLowerCase().indexOf("sip:") == -1 //no sip scheme
&& callee.indexOf('@') != -1 //most probably a sip uri
) {
callee = "sip:" + callee;
}
//Request URI
URI requestURI;
try {
requestURI = sipManCallback.addressFactory.createURI(callee);
}
catch (ParseException ex) {
console.error(callee + " is not a legal SIP uri!", ex);
throw new CommunicationsException(callee +
" is not a legal SIP uri!", ex);
}
//Call ID
CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
//CSeq
CSeqHeader cSeqHeader;
try {
cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1,
Request.INVITE);
}
catch (ParseException ex) {
//Shouldn't happen
console.error(ex, ex);
throw new CommunicationsException(
"An unexpected erro occurred while"
+ "constructing the CSeqHeadder", ex);
}
catch (InvalidArgumentException ex) {
//Shouldn't happen
console.error(
"An unexpected erro occurred while"
+ "constructing the CSeqHeadder", ex);
throw new CommunicationsException(
"An unexpected erro occurred while"
+ "constructing the CSeqHeadder", ex);
}
//FromHeader
FromHeader fromHeader = sipManCallback.getFromHeader();
//ToHeader
Address toAddress = sipManCallback.addressFactory.createAddress(
requestURI);
ToHeader toHeader;
try {
toHeader = sipManCallback.headerFactory.createToHeader(
toAddress, null);
}
catch (ParseException ex) {
//Shouldn't happen
console.error(
"Null is not an allowed tag for the to header!", ex);
throw new CommunicationsException(
"Null is not an allowed tag for the to header!", ex);
}
//ViaHeaders
ArrayList viaHeaders = sipManCallback.getLocalViaHeaders();
//MaxForwards
MaxForwardsHeader maxForwards = sipManCallback.getMaxForwardsHeader();
//Contact
ContactHeader contactHeader = sipManCallback.getContactHeader();
Request invite = null;
try {
invite = sipManCallback.messageFactory.createRequest(requestURI,
Request.INVITE,
callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders,
maxForwards);
}
catch (ParseException ex) {
console.error(
"Failed to create invite Request!", ex);
throw new CommunicationsException(
"Failed to create invite Request!", ex);
}
//
invite.addHeader(contactHeader);
//Content
ContentTypeHeader contentTypeHeader = null;
try {
//content type should be application/sdp (not applications)
//reported by Oleg Shevchenko (Miratech)
contentTypeHeader =
sipManCallback.headerFactory.createContentTypeHeader(
"application", "sdp");
}
catch (ParseException ex) {
//Shouldn't happen
console.error(
"Failed to create a content type header for the INVITE request",
ex);
throw new CommunicationsException(
"Failed to create a content type header for the INVITE request",
ex);
}
try {
invite.setContent(sdpContent, contentTypeHeader);
}
catch (ParseException ex) {
console.error(
"Failed to parse sdp data while creating invite request!", ex);
throw new CommunicationsException(
"Failed to parse sdp data while creating invite request!", ex);
}
//Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.
getNewClientTransaction(invite);
}
catch (TransactionUnavailableException ex) {
console.error(
"Failed to create inviteTransaction.\n" +
"This is most probably a network connection error.", ex);
throw new CommunicationsException(
"Failed to create inviteTransaction.\n" +
"This is most probably a network connection error.", ex);
}
try {
inviteTransaction.sendRequest();
if( console.isDebugEnabled() )
console.debug("sent request: " + invite);
}
catch (SipException ex) {
console.error(
"An error occurred while sending invite request", ex);
throw new CommunicationsException(
"An error occurred while sending invite request", ex);
}
Call call = callDispatcher.createCall(inviteTransaction.
getDialog(), invite);
call.setState(Call.DIALING);
return call;
}
finally
{
console.logExit();
}
}
//end call
public void endCall(int callID) throws CommunicationsException
{
try
{
console.logEntry();
Call call = callDispatcher.getCall(callID);
if (call == null) {
console.error(
"Could not find call with id=" +
callID);
throw new CommunicationsException(
"Could not find call with id=" +
callID);
}
Dialog dialog = call.getDialog();
if (call.getState().equals(Call.CONNECTED)
|| call.getState().equals(Call.RECONNECTED)) {
call.setState(Call.DISCONNECTED);
sayBye(dialog);
}
else if (call.getState().equals(Call.DIALING)
|| call.getState().equals(Call.RINGING)) {
if (dialog.getFirstTransaction() != null) {
try {
//Someone knows about us. Let's be polite and say we are leaving
sayCancel(dialog);
}
catch (CommunicationsException ex) {
//something went wrong let's just tell the others
console.error(
"Could not send the CANCEL request! "
+ "Remote party won't know we're leaving!",
ex);
sipManCallback.fireCommunicationsError(
new CommunicationsException(
"Could not send the CANCEL request! "
+ "Remote party won't know we're leaving!",
ex));
}
}
call.setState(Call.DISCONNECTED);
}
else if (call.getState().equals(Call.ALERTING)) {
call.setState(Call.DISCONNECTED);
sayBusyHere(dialog);
}
//For FAILE and BUSY we only need to update CALL_STATUS
else if (call.getState().equals(Call.BUSY)) {
call.setState(Call.DISCONNECTED);
}
else if (call.getState().equals(Call.FAILED)) {
call.setState(Call.DISCONNECTED);
}
else {
call.setState(Call.DISCONNECTED);
console.error(
"Could not determine call state!");
throw new CommunicationsException
("Could not determine call state!");
}
}
finally
{
console.logExit();
}
} //end call
//Bye
private void sayBye(Dialog dialog) throws CommunicationsException
{
try
{
console.logEntry();
Request request = dialog.getFirstTransaction().getRequest();
Request bye = null;
try {
bye = dialog.createRequest(Request.BYE);
}
catch (SipException ex) {
console.error(
"Failed to create bye request!",
ex);
throw new CommunicationsException(
"Failed to create bye request!",
ex);
}
ClientTransaction clientTransaction = null;
try {
clientTransaction =
sipManCallback.sipProvider.getNewClientTransaction(bye);
}
catch (TransactionUnavailableException ex) {
console.error(
"Failed to construct a client transaction from the BYE request",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -