AnsweredAssumed Answered

Packet Interceptor doesn't get Presence

Question asked by Barabas on Apr 30, 2015
Latest reply on Apr 30, 2015 by Barabas

Hi, I apologize for posting another thread, but it seems that I have another roadblock with Smack/XMPP. I am trying to create a friends/roster addition request right now.

I've set the Subscriptionmode to manual in order for the receiver to process requests. I then created a packet listener to receive packets pertaining to Presence. However, sent packets are received, but the sender sending the presence receives said packet. According to the debug, the presence stanza is being received by the recipient but not found in the PacketInterceptor.

 

Here's my code:

 

Roster roster = Roster.getInstanceFor(connection);
        roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
        connection.addPacketInterceptor(new StanzaListener() {
            @Override
            public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
                Log.e(TAG, "something called");
                Presence presence = (Presence) packet;
                if(((Presence) packet).getType() == Presence.Type.subscribe) {
                    Log.e(TAG, "Packet type subscribe");
                }
                if(presence.getType() == Presence.Type.subscribe) {
                    Log.e(TAG, "Subscribe type from: " + presence.getFrom());
                }
                if(presence.getType() == Presence.Type.subscribed) {
                    Log.e(TAG, "SUBSCRIBED type from: " + presence.getFrom());
                }
            }
        }, new StanzaTypeFilter(Presence.class));

 

Here's how I send the presence:

String myJID = connectionManager.getConnection().getUser();


        Presence response = new Presence(Presence.Type.subscribe);


        response.setTo(eventListAdapter.getItem(position).getSender() + "/Smack");
        response.setFrom(myJID);


        try {
            LoginFragment.connectionManager.getConnection().sendStanza(response);
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        }

 

Here is the DEBUG line the receiver receives:

<?xml version="1.0" encoding="UTF-8"?>
<presence from="radar@example.com" to="asd@example.com/Smack" xml:lang="en" id="eTer5-50" type="subscribe">
   <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.igniterealtime.org/projects/smack" ver="NfJ3flI83zSdUDzCEICtbypursw=" />
</presence>
So it seems that my client is receiving the presence but the packet listener isn't processing it for some reason. However, the sending client recognizes it fine

Outcomes