How to create persistent rooms in openfire using s

2019-07-08 11:00发布

问题:

I'm using the following iq message to create persistent rooms in 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);
});

But, I am getting the following error:

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:

Using the Strophe.muc plugin is easier:

1) firstly join the room (this creates an instant room):

connection.muc.join(room_jid, nick);

2) then create a "configured room", eventually with a subject and a description associated:

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

A working example is available here: http://plnkr.co/edit/Mbi15HDZ2yW5vXskS2X6?p=preview