📄 callprocessing.java.svn-base
字号:
&& callee.indexOf('@') != -1 // most probably a sip uri
) {
callee = "sip:" + callee;
}
// Request URI
URI requestURI;
try {
requestURI = sipManCallback.addressFactory.createURI(callee);
}
catch (ParseException 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
throw new CommunicationsException(
"An unexpected erro occurred while"
+ "constructing the CSeqHeadder", ex);
}
catch (InvalidArgumentException ex) {
// Shouldn't happen
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
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) {
throw new CommunicationsException(
"Failed to create invite Request!", ex);
}
//
invite.addHeader(contactHeader);
AllowHeader allow = null;
try {
allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
invite.addHeader(allow);
} catch (ParseException e) {
Log.error(e);
}
// 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
throw new CommunicationsException(
"Failed to create a content type header for the INVITE request",
ex);
}
try {
invite.setContent(sdpContent, contentTypeHeader);
}
catch (ParseException 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) {
throw new CommunicationsException(
"Failed to create inviteTransaction.\n"
+ "This is most probably a network connection error.",
ex);
}
try {
inviteTransaction.sendRequest();
}
catch (SipException 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;
}
// Hold
public void hold(int callID, String sdpContent)
throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
Request invite = null;
invite = call.getDialog().getFirstTransaction().getRequest();
try {
invite = call.getDialog().createRequest(Request.INVITE);
} catch (SipException e) {
Log.error("hold", e);
}
long cseq = ((CSeq) (invite.getHeader(CSeq.NAME)))
.getSequenceNumber() + 1;
invite.removeHeader(CSeq.NAME);
try {
invite.addHeader(sipManCallback.headerFactory.createCSeqHeader(cseq, Request.INVITE));
}
catch (Exception e) {
Log.error("hold", e);
}
invite.removeHeader(ViaHeader.NAME);
for (ViaHeader via : sipManCallback.getLocalViaHeaders())
invite.addHeader(via);
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
throw new CommunicationsException(
"Failed to create a content type header for the INVITE request",
ex);
}
try {
invite.setContent(sdpContent, contentTypeHeader);
}
catch (ParseException ex) {
throw new CommunicationsException(
"Failed to parse sdp data while creating invite request!",
ex);
}
// Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(invite);
call.getDialog().sendRequest(inviteTransaction);
call.setLastRequest(invite);
}
catch (SipException ee) {
Log.error("hold", ee);
}
return;
}
// send DTMF
void sendDTMF(int callID, String digit) {
try {
Call call = callDispatcher.getCall(callID);
Dialog dialog = call.getDialog();
sendNumDTMF(dialog, digit);
//
}
catch (CommunicationsException e) {
}
} // send DTMF
// end call
void endCall(int callID) throws CommunicationsException {
Call call = callDispatcher.getCall(callID);
if (call == null) {
throw new CommunicationsException(
"Could not find call with id=" + callID);
} else {
endCall(call);
}
} // end call
void endCall(Call call) throws CommunicationsException {
if (call == null) {
throw new CommunicationsException(
"Could not find call");
}
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
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 FAILED 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);
throw new CommunicationsException(
"Could not determine call state!");
}
} // end call
// send dtmf
private void sendNumDTMF(Dialog dialog, String digit)
throws CommunicationsException {
Request request = dialog.getFirstTransaction().getRequest();
Request info = null;
String body = "Signal=" + digit + "\nDuration=160";
String contentType = "application/dtmf-relay";
String[] contentTypeTab = contentType.split("/");
ContentTypeHeader contentTypeHeader = null;
try {
info = dialog.createRequest(Request.INFO);
try {
contentTypeHeader = sipManCallback.headerFactory
.createContentTypeHeader(contentTypeTab[0],
contentTypeTab[1]);
info.setContent(body, contentTypeHeader);
}
catch (ParseException ex) {
throw new CommunicationsException(
"ContentType Header must look like type/subtype!",
ex);
}
}
catch (SipException ex) {
throw new CommunicationsException(
"Failed to create bye request!", ex);
}
ClientTransaction clientTransaction = null;
try {
clientTransaction = sipManCallback.sipProvider
.getNewClientTransaction(info);
}
catch (TransactionUnavailableException ex) {
throw new CommunicationsException(
"Failed to construct a client transaction from the INFO request",
ex);
}
try {
dialog.sendRequest(clientTransaction);
}
catch (SipException ex1) {
throw new CommunicationsException(
"Failed to send the INFO request");
}
}
// send message
private void sendInfoMessage(Dialog dialog, String body)
throws CommunicationsException {
Request request = dialog.getFirstTransaction().getRequest();
Request info = null;
String contentType = "application/dtmd-relay";
String[] contentTypeTab = contentType.split("/");
ContentTypeHeader contentTypeHeader = null;
try {
info = dialog.createRequest(Request.INFO);
try {
contentTypeHeader = sipManCallback.headerFactory
.createContentTypeHeader(contentTypeTab[0],
contentTypeTab[1]);
info.setContent(body, contentTypeHeader);
}
catch (ParseException ex) {
throw new CommunicationsException(
"ContentType Header must look like type/subtype!",
ex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -