aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjgeboski <jgeboski@gmail.com>2016-01-04 19:28:45 -0500
committerjgeboski <jgeboski@gmail.com>2016-01-04 19:28:45 -0500
commitef58bebe539d87014ddceff6b6ca6217d422b4f2 (patch)
tree8bc2d7b6fb6cf37e8b67a6c0fb706527c782f661
parent074cfd563cf75f37b9fafbd9dfc1ed8f130dd343 (diff)
downloadbitlbee-facebook-ef58bebe539d87014ddceff6b6ca6217d422b4f2.tar.gz
bitlbee-facebook-ef58bebe539d87014ddceff6b6ca6217d422b4f2.tar.bz2
bitlbee-facebook-ef58bebe539d87014ddceff6b6ca6217d422b4f2.tar.xz
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.
-rw-r--r--facebook/facebook-api.c16
1 files changed, 15 insertions, 1 deletions
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