加入XMPP(SMACK)的MUC室时出错



我正在尝试创建一个多用户聊天。加入房间时,我会遇到错误。创建聊天室的方法:

 public void createMultiUserChatRoom(String roomName, String nickName) {
            // Get the MultiUserChatManager
            MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
            // Get a MultiUserChat using MultiUserChatManager
            MultiUserChat multiUserChat = multiUserChatManager.getMultiUserChat(roomName+"@conference.localhost");
            try {
                multiUserChat.create(nickName);
               Form form = multiUserChat.getConfigurationForm();
               Form submitForm = form.createAnswerForm();
               List<FormField> formFieldList = submitForm.getFields();
               for (FormField formField : formFieldList) {
                 if(!FormField.Type.hidden.equals(formField.getType()) && formField.getVariable() != null) {
                submitForm.setDefaultAnswer(formField.getVariable());
                } 
               }
             submitForm.setAnswer("muc#roomconfig_persistentroom", true);
             submitForm.setAnswer("muc#roomconfig_publicroom", true);
              multiUserChat.sendConfigurationForm(submitForm);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

加入MUC房间的方法:

public void joinMultiUserChatRoom(String userName, String roomName) {
        // Get the MultiUserChatManager
        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
        // Create a MultiUserChat using an XMPPConnection for a room
        MultiUserChat multiUserChat = manager.getMultiUserChat(roomName + "@conference.localhost");
        DiscussionHistory history = new DiscussionHistory();
        history.setMaxStanzas(-1);
        try {
            multiUserChat.join(userName, "", history, connection.getPacketReplyTimeout());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

获取用户加入房间的列表:

public List<String> getJoinedGroupByUserName(String userName) {
        // Get the MultiUserChatManager
        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
        List<String> joinedRooms = null;
        try {
            // Get the rooms where user3@host.org has joined
             joinedRooms = manager.getJoinedRooms(userName+"@conference.localhost");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return joinedRooms;
    }

当用户加入房间时,我会收到此消息:"该房间是从条目中锁定的,直到确认配置为止。"

房间,它在发送配置后没有真正可用(已确认),创建者必须在

之后加入
 multiUserChat.sendConfigurationForm(submitForm);

因此,基本上也必须

multiUserChat.join(username)

(如果您不需要呆在室内,请在加入后执行muc.leave()

最新更新