【问题标题】:how to create persistent muc room in smack 4.1 beta2如何在 smack 4.1 beta2 中创建持久的 muc 房间
【发布时间】:2015-04-09 05:12:36
【问题描述】:

从 asmack 迁移到 smack 4.1 beta2。 创建的 muc 房间不再持久。

MultiUserChatManager mucm=MultiUserChatManager.getInstanceFor(connection);
muc=mucm.getMultiUserChat(groupid+"@conference.localhost");
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.createOrJoin(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage();

当使用 gajim 创建时,房间是持久的。

编辑:这是我们之前使用的代码。默认情况下,聊天室是持久的,

muc = new MultiUserChat(connection, groupid+"@conference.localhost");

if(!muc.isJoined())
{
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.join(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage(0);
}

【问题讨论】:

  • 您之前是如何创建永久房间的?我认为您需要使用MultiUserChat.create 发送正确的数据论坛以创建持久房间。
  • 您好@flow,请检查已编辑的问题。

标签: xmpp ejabberd smack multiuserchat


【解决方案1】:

您需要提交这样的表格来创建一个持久组:

private void setConfig(MultiUserChat multiUserChat) {
    try {
        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm();
        for (Iterator<FormField> fields = submitForm.getFields(); fields.hasNext();) {
            FormField field = (FormField) fields.next();
            if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }
        submitForm.setAnswer("muc#roomconfig_publicroom", true);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);
        multiUserChat.sendConfigurationForm(submitForm);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

【讨论】:

    【解决方案2】:

    创建房间时,您需要在 MUC 配置中将 muc#roomconfig_persistentroom 设置为 true

    MultiuserChat muc = manager.getMultiUserChat("myroom@muc.example.org");
    muc.create("myNick");
    // room is now created by locked
    Form form = muc.getConfigurationForm();
    Form answerForm = form.createAnswerForm();
    answerForm.setAnswer("muc#roomconfig_persistentroom", true);
    muc.sendConfigurationForm(answerForm);
    // sending the configuration form unlocks the room
    

    请注意,并非所有 XMPP MUC 服务都支持永久房间。欲了解更多信息,请参阅:

    【讨论】:

    • 我认为 answerForm.setAnswer("muc#roomconfig_persistentroom", "true");应该是 answerForm.setAnswer("muc#roomconfig_persistentroom", true);而不是 String 一个布尔值。
    • @flow 应该放置什么来代替“muc#roomconfig_persistentroom”?
    【解决方案3】:

    在 smack 4.1.1 中,@saurabh dixit 给出的答案引发异常。请在 ignite 网站上查看此主题Correct implementation for persistent rooms smack 4.1.1

    【讨论】:

      【解决方案4】:
              multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
      
              multiUserChat = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(roomJID));
      
              multiUserChat.create(Resourcepart.from(nickname));
      
              Form form = multiUserChat.getConfigurationForm();
              Form submitForm = form.createAnswerForm();
              submitForm.getField("muc#roomconfig_enablelogging").addValue("1");
              submitForm.getField("x-muc#roomconfig_reservednick").addValue("0");
              submitForm.getField("x-muc#roomconfig_canchangenick").addValue("0");
              submitForm.getField("x-muc#roomconfig_registration").addValue("0");
              submitForm.getField("muc#roomconfig_passwordprotectedroom").addValue("0");
              submitForm.getField("muc#roomconfig_roomname").addValue(roomName);
              submitForm.getField("muc#roomconfig_whois").addValue("participants");
              submitForm.getField("muc#roomconfig_membersonly").addValue("1");
              submitForm.getField("muc#roomconfig_persistentroom").addValue("1");
              multiUserChat.sendConfigurationForm(submitForm);
      

      这是您可以发送房间配置和配置房间的方式。 有关更多详细信息,请参阅问题。 How to send room configuration form and create persistce rooms from android using smack 4.3.4

      【讨论】:

        猜你喜欢
        • 2020-04-19
        • 2016-10-25
        • 2015-05-17
        • 1970-01-01
        • 2018-01-17
        • 1970-01-01
        • 2015-01-14
        • 1970-01-01
        • 2011-10-10
        相关资源
        最近更新 更多