From 3dc905264185b1032842530305d012421c796363 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 17 Jul 2018 15:19:28 +0300 Subject: XMPP: start broadcasting only after component authentication --- .../src/main/java/com/juick/server/XMPPConnection.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'juick-server/src') diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index 78995e7a..3f15a2b9 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -38,6 +38,7 @@ import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; +import rocks.xmpp.core.session.XmppSession; import rocks.xmpp.core.stanza.AbstractIQHandler; import rocks.xmpp.core.stanza.model.*; import rocks.xmpp.core.stanza.model.client.ClientMessage; @@ -124,8 +125,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { public void init() { logger.info("stream router start connecting to {}", componentPort); xmpp.addStanzaListener(this); - router = ExternalComponent.create(componentName, password, session.getConfiguration(), "localhost", - componentPort); + router = ExternalComponent.create(componentName, password, "localhost", componentPort); EntityCapabilitiesManager entityCapabilitiesManager = router.getManager(EntityCapabilitiesManager.class); entityCapabilitiesManager.setNode("https://juick.com/caps"); MessageDeliveryReceiptsManager messageDeliveryReceiptsManager = router.getManager(MessageDeliveryReceiptsManager.class); @@ -249,13 +249,18 @@ public class XMPPConnection implements StanzaListener, NotificationListener { logger.info("component connected"); } }); + router.addSessionStatusListener(event -> { + if (event.getStatus().equals(XmppSession.Status.AUTHENTICATED)) { + logger.info("Authenticated, broadcasting..."); + broadcastPresence(null); + } + }); router.addInboundPresenceListener(event -> { incomingPresence(event.getPresence()); }); service.submit(() -> { try { router.connect(); - broadcastPresence(null); } catch (XmppException e) { logger.warn("xmpp exception", e); } -- cgit v1.2.3