mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Better reconnect logic. Refetch messages over http once reconnected when exceeded 1 min
This commit is contained in:
parent
503327b693
commit
32b47921e5
@ -86,6 +86,8 @@ class Gateway(Namespace):
|
|||||||
emit("revoke")
|
emit("revoke")
|
||||||
time.sleep(1000)
|
time.sleep(1000)
|
||||||
disconnect()
|
disconnect()
|
||||||
|
else:
|
||||||
|
emit("ack")
|
||||||
else:
|
else:
|
||||||
if not guild_accepts_visitors(guild_id):
|
if not guild_accepts_visitors(guild_id):
|
||||||
disconnect()
|
disconnect()
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
var current_user_discord_id; // Current user discord snowflake id, eg mine is 140252024666062848
|
var current_user_discord_id; // Current user discord snowflake id, eg mine is 140252024666062848
|
||||||
var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
|
var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
|
||||||
var socket = null; // Socket.io object
|
var socket = null; // Socket.io object
|
||||||
|
var socket_last_ack = null; // Socket.io last acknowledgement Moment obj
|
||||||
|
var socket_error_should_refetch = false; // If true, the next ack will trigger a http refetch if socket connected
|
||||||
var authenticated_users_list = []; // List of all authenticated users
|
var authenticated_users_list = []; // List of all authenticated users
|
||||||
var unauthenticated_users_list = []; // List of all guest users
|
var unauthenticated_users_list = []; // List of all guest users
|
||||||
var discord_users_list = []; // List of all discord users that are probably online
|
var discord_users_list = []; // List of all discord users that are probably online
|
||||||
@ -1255,6 +1257,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fet.done(function(data) {
|
fet.done(function(data) {
|
||||||
|
socket_error_should_refetch = false;
|
||||||
var status = data.status;
|
var status = data.status;
|
||||||
if (visitor_mode) {
|
if (visitor_mode) {
|
||||||
update_embed_userchip(false, null, "Titan", null, "0001", null);
|
update_embed_userchip(false, null, "Titan", null, "0001", null);
|
||||||
@ -1929,6 +1932,13 @@
|
|||||||
socket.on("guest_icon_change", function (icon) {
|
socket.on("guest_icon_change", function (icon) {
|
||||||
global_guest_icon = icon.guest_icon;
|
global_guest_icon = icon.guest_icon;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("ack", function () {
|
||||||
|
socket_last_ack = moment();
|
||||||
|
if (socket && socket_error_should_refetch) {
|
||||||
|
run_fetch_routine();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_socket_channels() {
|
function update_socket_channels() {
|
||||||
@ -1939,6 +1949,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function send_socket_heartbeat() {
|
function send_socket_heartbeat() {
|
||||||
|
if (socket_last_ack) {
|
||||||
|
var now = moment();
|
||||||
|
var duration = moment.duration(now.diff(socket_last_ack)).minutes();
|
||||||
|
if (socket && duration >= 1) { // server must hanged, lets reconnect
|
||||||
|
socket_error_should_refetch = true;
|
||||||
|
socket.disconnect();
|
||||||
|
socket = null;
|
||||||
|
initiate_websockets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.emit("heartbeat", {"guild_id": guild_id, "visitor_mode": visitor_mode});
|
socket.emit("heartbeat", {"guild_id": guild_id, "visitor_mode": visitor_mode});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user