我在我的 Android 项目中使用 Smack 4.1.1 作为 Gradle 依赖项。
我已经成功地与我的本地 OpenFire 服务器建立了连接。
但是我在从 Android 客户端创建临时房间时遇到了问题。
final MultiUserChat multiUserChat = userChatManager.getMultiUserChat(roomId);
try {
multiUserChat.create(connection.getUser());
LOG.debug("room created");
} catch (XMPPException.XMPPErrorException | SmackException e) {
LOG.error("create room error:{}", e);
}
try{
multiUserChat.sendConfigurationForm(new Form(DataForm.Type.submit));
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
LOG.error("sending room configurations error:{}", e);
}
最棒的是我可以看到这个房间是在 OpenFire 管理面板中创建的,并从另一个客户端获取房间信息。
try {
MultiUserChatManager userChatManager = MultiUserChatManager.getInstanceFor(connection);
RoomInfo info = userChatManager.getRoomInfo(roomId);
LOG.debug("room has {} occupants", info.getOccupantsCount());
joinToExistingRoom(roomId);
} catch (XMPPException.XMPPErrorException e) {
LOG.error("join room error:{}", e);
final XMPPError.Condition condition = e.getXMPPError().getCondition();
if (condition == XMPPError.Condition.item_not_found) {
LOG.error("room does not exist error:{}", e);
createRoom(roomId);
}
}
但是在尝试从第二个客户端加入房间时,我收到XMPPError: recipient-unavailable - wait。
我的joinRoom方法的片段:
final MultiUserChat multiUserChat = userChatManager.getMultiUserChat(roomId);
try {
multiUserChat.join(connection.getUser());
LOG.debug("joined to room:{}", roomId);
} catch (SmackException.NoResponseException
| XMPPException.XMPPErrorException
| SmackException.NotConnectedException e) {
LOG.error("error joining room {}", e);
}
所以我在加入房间 org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError:recipient-unavailable - wait
所以问题是什么可能是错的?我还尝试从createAnswerForm()方法创建submitForm 。但结果是一样的。
我发现使其工作的一种解决方案是在配置表单的答案中将persistantroom发送为true 。但是这种方法会创建持久的房间,尽管我需要在所有与会者离开房间后销毁这个房间。
也许这是一个简单的问题,但现在我不知道如何解决这个问题。
帮助将不胜感激。
提前致谢。