Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while joining MUC room in XMPP(smack)

I am trying to create a multi user chat. I am getting error while joining the room. Method for creating chat room :

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

Method for joining MUC room :

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

Getting list of joined room by user :

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

        return joinedRooms;
    }

While user join the room i get this message : "This room is locked from entry until configuration is confirmed."

like image 729
Jennifer Avatar asked Jun 23 '16 06:06

Jennifer


1 Answers

Room it's not really available (confirmed) after sending a configuration, the creator has to join after

 multiUserChat.sendConfigurationForm(submitForm);

so basically creator must also

multiUserChat.join(username)

(if you don't need to stay inside, perform a muc.leave() after a join)

like image 147
MrPk Avatar answered Oct 04 '22 05:10

MrPk