2
votes

I'm now trying to build XMPP MUC room in android using asmack-android-7.jar the api. First, I create a instant room,then I add a muc listener to the room. the code snippet as follows:

    //create the an instant room if the same room has not been created.
    MultiUserChat muc = new MultiUserChat(mConnection, roomJid);
    muc.create(ownerNickname);
    muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
    // join a room  and add listener 
   mMuc = new MultiUserChat(mConnection, roomJid);
   mMuc.join(vistorNickname);
   addListenerToMuc(mMuc);
   // the listener function
   private void addListenerToMuc(MultiUserChat muc){
    if(null != muc){
        muc.addMessageListener(new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                Log.i("processPacket", "receiving message");
                }
        });
    }
}

then things get really confusing to me,first ,some times when the listener works well but when I leave the room then rejoin ,then the listener may always fail to process message as the form like this:

 RCV  (723971008): <message id="FdkcR-24" to="寻李白@xjopenfire/KascendVideo" type="groupchat" from="哈特的战争@conference.xjopenfire/nutch"><body> from nutch</body></message>

However ,the listener always works fairly well when the coming message like this:

 <message id="S7JfM-111" to="寻李白@xjopenfire/KascendVideo" type="groupchat" from="哈特的战争@conference.xjopenfire/hangzhou@video"><body>I love you</body><x xmlns="jabber:x:event"><offline/><delivered/><displayed/><composing/></x></message>

it seems like the messages with one or more extensions always work well,while the ones without extension tends to fail sometimes. I am really confused about this,can any body tell me what has happened? I will be really grateful for your idea.

another question I found is that if I first create an Instant room,then join the room without create a new object of MulitUserChat, then the room can not be join in by others, for example, using spark client, then get error,saying that the room does not exist,to be specific ,the code snippet is like this:

MultiUserChat mMuc = new MultiUserChat(mConnection, roomJid);
        muc.create(ownerNickname);
        muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
        // join a room  and add listener 
       mMuc.join(vistorNickname);

I'm really feel frustrated about these things,all ideas are welcomed. Thanks very much.

1

1 Answers

0
votes

I have a simple solution to second question , you don't have to and shall not join in the room right after you have created it. Because they really means the same thing to some extend,and the Phenomenon I described above have something to do with the smack library's implementation of the create( ) and join( ) function.