From ef58bebe539d87014ddceff6b6ca6217d422b4f2 Mon Sep 17 00:00:00 2001 From: jgeboski Date: Mon, 4 Jan 2016 19:28:45 -0500 Subject: facebook-api: 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. --- facebook/facebook-api.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c index e552e3a..a073c5d 100644 --- a/facebook/facebook-api.c +++ b/facebook/facebook-api.c @@ -47,6 +47,7 @@ struct _FbApiPrivate FbHttp *http; FbMqtt *mqtt; GHashTable *data; + gboolean retrying; FbId uid; gint64 sid; @@ -789,7 +790,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 @@ -941,6 +950,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 -- cgit v1.2.3