2
votes

I'm trying to establish a simple xmpp group chat on Android using the smack/asmack xmpp library. And basically everything is working, except: UNAVAILABLE presences, i.e., when a user leaves a chat room, seem to be ignored. Presences from users entering the group chat are fine.

Both my local Openfire server as well as a xmpp client (Instantbird) tell me that there is a UNAVAILABLE presence when user leaves. Only my stuff has troubles.

Here's the main snippet of my code. In short, when a user (re-)enters the room I see the console output ("presenceListener.processPacket"), when a user leaves nothing happens.

public boolean join(String room, user) {

    this.chat = new MultiUserChat(this.xmppConn, room);

    this.presenceListener = new PacketListener() {
        @Override
        public void processPacket(Packet packet) {
            System.out.println("presenceListener.processPacket");
            if (packet instanceof Presence)
                // Handle presence
        }
    };
    this.chat.addParticipantListener(this.presenceListener);

    this.messageListener = ...
    this.chat.addMessageListener(this.messageListener);
    ...
    try {
        this.chat.join(user);
        ...
    } catch (...) {
        ...
    }
}

I would understand when the listener would pick up nothing. But this is too weird for me at the moment. I'm happy about any hint...thanks!

Christian

1

1 Answers

0
votes

I found a working solution here.

It uses a PacketFilter with a filter for presence packets, attaching it to the xmpp connection; inspite my solution via attaching a ParticipantListener to the MultiUserChat.

I still don't know why my original attempt fails, but...well...it works now.