From 2c7c466bb9b987974941a8aa79ae6a66d0a2e1a9 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sat, 2 Sep 2017 04:06:15 +0000 Subject: [PATCH] Better websockets reconnect logic --- webapp/titanembeds/static/js/embed.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 4ae3436..b731155 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -318,6 +318,7 @@ function initialize_embed(guildobj) { if (socket) { socket.disconnect(); + socket = null; } if (guildobj === undefined) { var guild = query_guild(); @@ -856,8 +857,9 @@ if (socket) { run_fetch_routine(); socket.disconnect(); - initiate_websockets(); + socket = null; } + initiate_websockets(); }); usr.fail(function(data) { if (data.status == 429) { @@ -938,12 +940,13 @@ }); socket.on("disconnect", function () { - socket = null; + }); socket.on("revoke", function () { + socket.disconnect(); + socket = null; $('#loginmodal').modal('open'); - setVisitorMode(true); primeEmbed(); Materialize.toast('Authentication error! You have been disconnected by the server.', 10000); });