1
votes

I am trying to create multi user chat using XMPP(smack). After creation of room when i try to join to chat room then there is no entry of joined member in ofmucmember.

Creation of room code is as below :

public void createMultiUserChatRoom(String roomName, String nickName) {

        MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);

        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);
            submitForm.setAnswer("muc#roomconfig_enablelogging", true);
            submitForm.setAnswer("x-muc#roomconfig_reservednick", false);
            submitForm.setAnswer("x-muc#roomconfig_canchangenick", false);
            submitForm.setAnswer("x-muc#roomconfig_registration", false);
            submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", false);
            submitForm.setAnswer("muc#roomconfig_roomname", roomName);
             submitForm.setAnswer("muc#roomconfig_whois", Arrays.asList("none"));
            multiUserChat.sendConfigurationForm(submitForm);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

Code for joining the created room is as below:

    public void joinMultiUserChatRoom(String userName, String roomName) {
            MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);

            MultiUserChat multiUserChat = manager.getMultiUserChat(roomName + "@conference.localhost");
            DiscussionHistory history = new DiscussionHistory();
            history.setMaxStanzas(0);
            try {
                multiUserChat.join(userName);
                multiUserChat.sendMessage(userName +" : You have joined the group : " + roomName);

                Presence presence = multiUserChat.getOccupantPresence(roomName + "@conference.localhost/" + userName);
                presence.setMode(Presence.Mode.available);
                connection.sendStanza(presence);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

Response from server :

<message to="admin@localhost/Smack" id="h7axM-14" type="groupchat" from="[email protected]/roy"><body>roy : You have joined the group : team6</body><x xmlns="jabber:x:delay" stamp="20160623T12:15:50" from="[email protected]/roy"/></message>
presence :<presence to='admin@localhost/Smack' id='WR9Dy-12'><x xmlns='http://jabber.org/protocol/muc#user'><item affiliation='owner' jid='admin@localhost/Smack' role='moderator'></item></x><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='NfJ3flI83zSdUDzCEICtbypursw='/></presence>

I am not getting any error. Can anybody tell me where i am wrong here?

2

2 Answers

1
votes

When you fill the configuration form, you need to fill following sections:

<field
      label='Room Admins'
      type='jid-multi'
      var='muc#roomconfig_roomadmins'>
    <value>[email protected]</value>
    <value>[email protected]</value>
  </field>

<field
          label='Room Owners'
          type='jid-multi'
          var='muc#roomconfig_roomowners'/>

Admins and Owner are saved in ofMucAffiliation table and if the configuration is updated and existing admin or owner is not mentioned then server assumes that it's affiliation has been changed to member, so it moves the entry to ofMucMember table.

0
votes

You don't get a member just because you join a room. After you have joined a room, you are a Participant in the terminology of XEP-0045.