【问题标题】:Error while joining MUC room in XMPP(smack)在 XMPP 中加入 MUC 房间时出错(smack)
【发布时间】:2016-10-25 07:28:28
【问题描述】:

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

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

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

【问题讨论】:

    标签: java xmpp openfire smack multiuserchat


    【解决方案1】:

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

     multiUserChat.sendConfigurationForm(submitForm);
    

    所以基本上创作者也必须这样做

    multiUserChat.join(username)
    

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

    【讨论】:

    • 我在创建房间时发送了配置。加入房间时是否需要再次发送配置?并且房间确实存在(数据库中有房间条目)
    • 不,只是在创建时间,但“创建”只有在创建者加入房间后才能完成。但是,可能对于持久性房间,您还必须将配置创建者作为所有者发送(muc#roomconfig_roomowners -> List of Owners)
    • 我正在尝试加入聊天室成员。所以为此我还需要添加房主?我需要稍后添加房间成员,所以我无法在创建 MUC 房间时添加它
    • 要解释的事情太多了……您正在创造时间,您需要 (1) 发送配置 (2) 加入。在 INSIDE 中,当前用户可以邀请任何人:将获得邀请的人需要一个监听器来接收邀请,并且必须接受/拒绝(接受这不是真正的动作,是 muc.join(displayName,passwordIfNeeded)
    • @MrOk 这意味着我不能在没有邀请的情况下将成员添加到 MUC 房间。我对发送邀请没有任何要求。我只需要在不询问他们的情况下将成员添加到房间
    猜你喜欢
    • 2016-04-09
    • 2015-05-17
    • 2012-10-18
    • 2016-10-25
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多