How do i intercept XMPP Packets/messages within a Sparkplug plugin? The only way I can think of so far is to use the Connetion object and login using the current username and pasword, but this seems cumbersome (unless I can retrieve it from the current session?).
You’'d write a PacketListener, which would look something similar to this:
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
// Do what you want with the packet.
}
};
Then you would get the current Connection like I showed before.
// Get the current Spark XMPP connection.
XMPPConnection connection = SparkManager.getConnection();
Then association the PacketListener to this connection.
// Add the packetlistener.
// packetFilter is something you will need to set in order to filter
// the type of packets you want.
connect.addPacketListener(packetListener, packetFilter);