如何使用strophe在openfire中创建持久性房间?

时间:2017-08-09 10:46:19

标签: xmpp openfire strophe

我使用以下iq消息在openfire中创建持久性房间:

var configiq = $iq({
        to : chatObj.getActiveChatRoomName() + "@" + chatObj.groupChatService,
        type : "set"
    }).c("x", {
        xmlns : "jabber:x:data",
        type : "submit"
    }).c('field', {
        "var" : "FORM_TYPE"
    })
    .c('value').t("http://jabber.org/protocol/muc#roomconfig")
    .up().up()
    .c('field', {
        "var" : "muc#roomconfig_persistentroom"
    })
    .c('value').t("1");


chatObj.connection.sendIQ(configiq.tree(), function () {
    console.log('success');
}, function (err) {
    console.log('error', err);
});

但是,我收到以下错误:

error <iq xmlns=​"jabber:​client" type=​"error" id=​"1356:​sendIQ" from=​"msrtc0711@conference.stslp239" to=​"ashishjmeshram@stslp239/​ax8nb2atg1">​<x xmlns=​"jabber:​x:​data" type=​"submit">​…​</x>​<error code=​"400" type=​"modify">​<bad-request xmlns=​"urn:​ietf:​params:​xml:​ns:​xmpp-stanzas">​</bad-request>​</error>​</iq>​

1 个答案:

答案 0 :(得分:2)

使用Strophe.muc插件更容易:

1)首先加入房间(这会创建一个即时房间):

connection.muc.join(room_jid, nick);

2)然后创建一个“配置的房间”,最终与主题和描述相关联:

var config = {"muc#roomconfig_publicroom": "1", "muc#roomconfig_persistentroom": "1"};
if (descr)  config["muc#roomconfig_roomdesc"] = descr;
if (subject)  config["muc#roomconfig_subject"] = subject;
connection.muc.createConfiguredRoom(room_jid, config, onCreateRoomSuccess, onCreateRoomError);

此处提供了一个工作示例:http://plnkr.co/edit/Mbi15HDZ2yW5vXskS2X6?p=preview