QXmpp creating a MUC room (xep--0045) on the server

529 Views Asked by At

I am trying to add MUC capabilities to my application with QXmpp, I am following this info in the QXmppMucManager.h header file

/// \brief The QXmppMucManager class makes it possible to interact with
/// multi-user chat rooms as defined by XEP-0045: Multi-User Chat.
///
/// To make use of this manager, you need to instantiate it and load it into
/// the QXmppClient instance as follows:
///
/// \code
/// QXmppMucManager *manager = new QXmppMucManager;
/// client->addExtension(manager);
/// \endcode
///
/// You can then join a room as follows:
///
/// \code
/// QXmppMucRoom *room = manager->addRoom("[email protected]");
/// room->setNickName("mynick");
/// room->join();
/// \endcode
///
/// \ingroup Managers

In a constructor of one of my classes I am adding a MuCManager like this

QXmppMucManager *manager = new QXmppMucManager;

    m_xmppClient.addExtension(manager);

and in a slot to create an Muc group I am doing this

QXmppMucRoom *room = manager->addRoom("livefit@mthinkpad");

    room->setNickName("mThinkpad");

    room->join();

I expect this to create a room and join if it doesn't exist and join if it already exists but it is just crashing my application.I can't wrap my brains around how qxmpp implements the xep--0045.I would appreciate it if somebody helped point what I am doing wrong or how I can create an Muc room on my server from my client. My server is a local ejabberd installation and I can access it at the "mthinkpad" domain.

1

There are 1 best solutions below

0
On BEST ANSWER

In case somebody has the same issues ,I was able to create the rooms.Here is the code that does that.I create and configure the room on the fly(I am using Openfire and it allows it) but you can request the configuration form if you want.

String jid=roomName.text()+"@conference."+serverName;
       if(jid.isEmpty())
               return ;
           QList<QXmppMucRoom*> rooms = manager->rooms();
           QXmppMucRoom* r;
           foreach(r, rooms)
           {
               if(r->jid() == jid)
               {
                   //LOG_MODEL_DEBUG("Group chat", "had joined room[%s]", qPrintable(jid));
                   return ;
               }
           }
           m_pRoom = manager->addRoom(jid);
           if(m_pRoom)
           {
               //nick
               m_pRoom->setNickName("theDip");
               //join the room.
               m_pRoom->join();
           }

           //Prepare the dataform.
           QXmppDataForm form(QXmppDataForm::Submit);
           QList<QXmppDataForm::Field> fields;
           {
               QXmppDataForm::Field field(QXmppDataForm::Field::HiddenField);
               field.setKey("FORM_TYPE");
               field.setValue("http://jabber.org/protocol/muc#roomconfig");
               fields.append(field);
           }
           QXmppDataForm::Field field;
           field.setKey("muc#roomconfig_roomname");
           field.setValue(roomName.text());
           fields.append(field);

           field.setKey("muc#roomconfig_subject");
           field.setValue(roomSubject.text());
           fields.append(field);

           field.setKey("muc#roomconfig_roomdesc");
           field.setValue(roomDesc.text());
           fields.append(field);
           {
               QXmppDataForm::Field field(QXmppDataForm::Field::BooleanField);
               field.setKey("muc#roomconfig_persistentroom");
               field.setValue(true);
               fields.append(field);
           }

           form.setFields(fields);
           //The dataform ends here.
           m_pRoom->setConfiguration(form);