javascriptstrophe

Strophe.js MUC: creating a room and joining more than one room


I'm creating a chat website and I'm using Strophe.js and the Strophe.muc.js plugin. The single chat functionalities work fine, but I also wan't to implement a group chat function where users can create rooms and invite other users to their room. Using the muc plugin, I can create a room, but the problem is that until I don't configure it (I guess), other users can't join and the room isn't persistent. I know that the muc plugin has configuration methods, but I don't know how to create the config Form object, I have no idea how should it look. This would be my first problem. Second: Is it possible that I join more then one room and get messages from all the rooms I'm in? If not, then there's no need to give me an answer to my first question...


Solution

    1. You can set the rooms to be persistent by default on your jabber server.
    2. Creating rooms is a 2 step process. First creating the room then configuring the room.
    3. You can join as many rooms as you like.

    A room config is like (you'll get a form on the first step of available fields if you check the response from the server).

    The 2nd step looks like:

    var iq, stanza;
    iq = $iq({
        to: newroomjid,
        type: "set"
    }).c("query", {
        xmlns: Strophe.NS.MUC_OWNER
    });
    iq.c("x", {
        xmlns: "jabber:x:data",
        type: "submit"
    });
    iq.c('field', { 'var': 'FORM_TYPE' }).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
    iq.c('field', { 'var': 'muc#roomconfig_roomname' }).c('value').t(roomName).up().up();
    stanza = iq.tree();