gpt4 book ai didi

android - 如何在 jainsip android 中创建并从客户端向服务器发送 Bye 消息?

转载 作者:行者123 更新时间:2023-11-29 17:30:48 24 4
gpt4 key购买 nike

我在 Mobicents restcomm-android-sdk 中尝试了 jainsip 示例。它对我有用,但我无法从客户端正确创建再见消息。

I created a Bye Message class like this

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 类中找到。请帮助。

最佳答案

尼丁,

BYE 消息始终在 SIP 对话中,因此您不必从头开始创建新消息。相反,您只需要获取要终止的对话,从中创建 BYE 类型的请求并发送它。 JAIN 会处理剩下的事情。

例如,您可以查看 Mobicents restcomm-android-sdk 存储库中的代码,方法 sendByeClient():

https://github.com/Mobicents/restcomm-android-sdk/blob/master/sipua/src/main/java/org/mobicents/restcomm/android/sipua/impl/SipManager.java#L931

另请记住,JAIN SIP 示例已被使用 Restcomm Android 客户端 SDK 的 Messenger 示例废弃,后者提供了更简单的 API。这是它的代码供您引用:

https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/restcomm-messenger

关于android - 如何在 jainsip android 中创建并从客户端向服务器发送 Bye 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33081890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com