6

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

 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;
    }

当用户加入房间时,我收到这条消息:“这个房间被锁定,直到配置被确认。”

4

1 回答 1

2

发送配置后房间实际上不可用(确认),创建者必须在之后加入

 multiUserChat.sendConfigurationForm(submitForm);

所以基本上创作者也必须

multiUserChat.join(username)

(如果您不需要留在里面,请muc.leave()在加入后执行)

于 2016-06-23T08:31:44.723 回答