From bc599a6dd63ad9410f5a7135f97ab2c0dac3cc60 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 18 Jul 2020 12:50:08 +0200 Subject: [PATCH] Add callback method for when Smack is connecting --- .../jivesoftware/smack/AbstractXMPPConnection.java | 9 +++++++++ .../org/jivesoftware/smack/ConnectionListener.java | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index bbb104fe8..246f05eb2 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -514,6 +514,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { // Check if not already connected throwAlreadyConnectedExceptionIfAppropriate(); + // Notify connection listeners that we are trying to connect + callConnectionConnectingListener(); + // Reset the connection state initState(); closingStreamReceived = false; @@ -1680,6 +1683,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } + protected void callConnectionConnectingListener() { + for (ConnectionListener listener : connectionListeners) { + listener.connecting(this); + } + } + protected void callConnectionConnectedListener() { for (ConnectionListener listener : connectionListeners) { listener.connected(this); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionListener.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionListener.java index 3e85191b9..304c8c75a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionListener.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionListener.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software. + * Copyright 2003-2007 Jive Software, 2020 Paul Schaub * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,16 @@ package org.jivesoftware.smack; */ public interface ConnectionListener { + /** + * Notification that the connection is in the process of connecting. + * This method is called when {@link AbstractXMPPConnection#connect()} is executed. + * + * @param connection connection + * @since 4.4 + */ + default void connecting(XMPPConnection connection) { + } + /** * Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server). *