/pidgin/main: 45f10c23412d: facebook: attempt to silently reconn...

James Geboski jgeboski at gmail.com
Thu Jan 7 15:34:25 EST 2016


Changeset: 45f10c23412ded435f9f859e10a9ebf226c01356
Author:	 James Geboski <jgeboski at gmail.com>
Date:	 2016-01-04 19:28 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/45f10c23412d

Description:

facebook: attempt to silently reconnect the MQTT stream

Often times, the MQTT stream is disconnected by Facebook for whatever
reason. The only thing I can think of is some sort of load balancing on
Facebook's end. It has also been reported that when a user logs out on
the Facebook website, their MQTT connections are killed. Whenever the
connection is killed by Facebook, the user is able to reconnect right
after.

In order to make for a quieter experience, the plugin should attempt
to silently reconnect before notifying the user of an error. This is
done by relying on the sequence identifier and the message queue to
ensure everything remains synchronized for when the connection returns.

diffstat:

 libpurple/protocols/facebook/api.c |  16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diffs (40 lines):

diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -54,6 +54,7 @@ struct _FbApiPrivate
 	FbHttpConns *cons;
 	PurpleConnection *gc;
 	GHashTable *data;
+	gboolean retrying;
 
 	FbId uid;
 	gint64 sid;
@@ -837,7 +838,15 @@ static void
 fb_api_cb_mqtt_error(FbMqtt *mqtt, GError *error, gpointer data)
 {
 	FbApi *api = data;
-	g_signal_emit_by_name(api, "error", error);
+	FbApiPrivate *priv = api->priv;
+
+	if (!priv->retrying) {
+		priv->retrying = TRUE;
+		fb_util_debug_info("Attempting to reconnect the MQTT stream...");
+		fb_api_connect(api, priv->invisible);
+	} else {
+		g_signal_emit_by_name(api, "error", error);
+	}
 }
 
 static void
@@ -991,6 +1000,11 @@ fb_api_connect_queue(FbApi *api)
 		msg = g_queue_peek_head(priv->msgs);
 		fb_api_message_send(api, msg);
 	}
+
+	if (priv->retrying) {
+		priv->retrying = FALSE;
+		fb_util_debug_info("Reconnected the MQTT stream");
+	}
 }
 
 static void



More information about the Commits mailing list