java - 在 XMPP 中向 MUC 添加成员(SMACK)

标签 java xmpp openfire smack multiuserchat

我正在尝试使用 XMPP(smack) 创建多用户聊天。创建房间后,当我尝试加入聊天室时,ofmucmember 中没有已加入成员的条目。

房间代码的创建如下:

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

    }

加入创建的房间代码如下:

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

服务器响应:

<message to="admin@localhost/Smack" id="h7axM-14" type="groupchat" from="team6@conference.localhost/roy"><body>roy : You have joined the group : team6</body><x xmlns="jabber:x:delay" stamp="20160623T12:15:50" from="team6@conference.localhost/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>

我没有收到任何错误。谁能告诉我我错在哪里?

最佳答案

填写配置表单时,您需要填写以下部分:

<field
      label='Room Admins'
      type='jid-multi'
      var='muc#roomconfig_roomadmins'>
    <value>wiccarocks@shakespeare.lit</value>
    <value>hecate@shakespeare.lit</value>
  </field>

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

管理员和所有者保存在ofMucAffiliation表中,如果更新配置并且未提及现有管理员或所有者,则服务器假定其从属关系已更改为成员,因此会将条目移动到ofMucMember 表。

关于java - 在 XMPP 中向 MUC 添加成员(SMACK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37991820/

相关文章:

java - tess4J 应用程序的 JUnit 测试

java - 从 MySql 迁移 : MariaDB server closing client connections unexpectedly

python - xmppy。文件描述符超出选择范围

xml - 使用命名空间迭代 xml 中的元素

java - 如何在 java 中使用 smack api 从 openfire 检索存档消息?

ios - 如何从 XMPP/OpenFire 在 iOS 中检索 vCard

android xabber 未授权 openfire xmpp 帐户

JNLP 中的 java.security.properties

java - 是否有任何命令行函数可以从一个巨大的 Java 文件中返回主类的名称?

rest - 是否可以通过 websockets 进行 ReST?