|
16 | 16 | import org.jivesoftware.smack.StanzaListener; |
17 | 17 | import org.jivesoftware.smack.XMPPConnection; |
18 | 18 | import org.jivesoftware.smack.XMPPException; |
| 19 | +import org.jivesoftware.smack.filter.StanzaFilter; |
19 | 20 | import org.jivesoftware.smack.packet.Stanza; |
20 | 21 | import org.jivesoftware.smack.provider.ExtensionElementProvider; |
21 | 22 | import org.jivesoftware.smack.provider.ProviderManager; |
| 23 | +import org.jivesoftware.smack.sm.predicates.ForEveryStanza; |
22 | 24 | import org.jivesoftware.smack.tcp.XMPPTCPConnection; |
23 | 25 | import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; |
24 | 26 | import org.json.simple.JSONValue; |
@@ -157,11 +159,20 @@ public void connected(XMPPConnection arg0) { |
157 | 159 | }); |
158 | 160 |
|
159 | 161 | // Handle incoming packets (the class implements the StanzaListener) |
160 | | - connection.addAsyncStanzaListener(this, |
161 | | - stanza -> stanza.hasExtension(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE)); |
| 162 | + connection.addAsyncStanzaListener(this, new StanzaFilter() { |
| 163 | + @Override |
| 164 | + public boolean accept(Stanza stanza) { |
| 165 | + return stanza.hasExtension(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE); |
| 166 | + } |
| 167 | + }); |
162 | 168 |
|
163 | 169 | // Log all outgoing packets |
164 | | - connection.addPacketInterceptor(stanza -> logger.log(Level.INFO, "Sent: {}", stanza.toXML()), stanza -> true); |
| 170 | + connection.addPacketInterceptor(new StanzaListener() { |
| 171 | + @Override |
| 172 | + public void processPacket(Stanza stanza) throws NotConnectedException { |
| 173 | + logger.log(Level.INFO, "Sent: {}", stanza.toXML()); |
| 174 | + } |
| 175 | + }, ForEveryStanza.INSTANCE); |
165 | 176 |
|
166 | 177 | connection.login(fcmServerUsername, mApiKey); |
167 | 178 | logger.log(Level.INFO, "Logged in: " + fcmServerUsername); |
|
0 commit comments