我在Mobicents中尝试了jainsip示例restcomm-android-sdk.Its对我有用但是我无法正确地从客户端创建再见消息。
我创建了一个像这样的Bye Message类
public class Bye {
public Request MakeRequest(SipManager sipManager) throws ParseException,
InvalidArgumentException {
AddressFactory addressFactory = sipManager.addressFactory;
SipProvider sipProvider = sipManager.sipProvider;
MessageFactory messageFactory = sipManager.messageFactory;
HeaderFactory headerFactory = sipManager.headerFactory;
// Create addresses and via header for the request
Address fromAddress = addressFactory.createAddress("sip:"
+ sipManager.getSipProfile().getSipUserName() + "@"
+ sipManager.getSipProfile().getRemoteIp());
fromAddress.setDisplayName(sipManager.getSipProfile().getSipUserName());
Address toAddress = addressFactory.createAddress("sip:"
+ sipManager.getSipProfile().getSipUserName() + "@"
+ sipManager.getSipProfile().getRemoteIp());
toAddress.setDisplayName(sipManager.getSipProfile().getSipUserName());
Address contactAddress = sipManager.createContactAddress();
ArrayList<ViaHeader> viaHeaders = sipManager.createViaHeader();
URI requestURI = addressFactory.createAddress(
"sip:" + sipManager.getSipProfile().getRemoteEndpoint())
.getURI();
// Build the request
CallIdHeader callIdHeader = sipManager.sipProvider.;
final Request request = messageFactory.createRequest(requestURI,
Request.BYE, sipProvider.getNewCallId(),
headerFactory.createCSeqHeader(1l, Request.BYE),
headerFactory.createFromHeader(fromAddress, "c3ff411e"),
headerFactory.createToHeader(toAddress, null), viaHeaders,
headerFactory.createMaxForwardsHeader(70));
// Add the contact header
request.addHeader(headerFactory.createContactHeader(contactAddress));
ExpiresHeader eh = headerFactory.createExpiresHeader(300);
request.addHeader(eh);
// Print the request
System.out.println(request.toString());
return request;
// Send the request --- triggers an IOException
// sipProvider.sendRequest(request);
// ClientTransaction transaction = sipProvider
// .getNewClientTransaction(request);
// Send the request statefully, through the client transaction.
// transaction.sendRequest();
}
}
将其从SipManager类调用为
public void disconnectCall() throws NotInitializedException {
// TODO Auto-generated method stub
if (!initialized)
throw new NotInitializedException("Sip Stack not initialized");
this.sipManagerState = SipManagerState.BYE;
Bye byeRequest = new Bye();
Request r=null ;
try{
r = byeRequest.MakeRequest(this);//byeRequest.MakeRequest(SipManager.this);
final ClientTransaction transaction = this.sipProvider
.getNewClientTransaction(r);
Thread thread = new Thread() {
public void run() {
try {
transaction.sendRequest();
} catch (SipException e) {
e.printStackTrace();
}
}
};
thread.start();
} catch (TransactionUnavailableException e) {
e.printStackTrace();
}catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
我有481个错误代码作为响应。我想我已经错过了再见消息中的当前callid字段。我已经搜索过它,但是没有找到sipmanager class.pls帮助。
答案 0 :(得分:3)
Nidhin,
BYE消息始终位于SIP对话框中,因此您无需从头开始创建新消息。相反,您只需要获取要终止的对话框,从中创建BYE类型的请求并发送它。 JAIN将负责其余的工作。
例如,您可以在Mobicents restcomm-android-sdk repo上检查代码,方法sendByeClient():
还请记住,使用Restcomm Android Client SDK的Messenger示例已经废弃了JAIN SIP示例,该客户端SDK提供了更简单的API。以下是供您参考的代码:
https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/restcomm-messenger