diff --git a/client/js/socket.js b/client/js/socket.js index c5593f90..a9916b0a 100644 --- a/client/js/socket.js +++ b/client/js/socket.js @@ -2,6 +2,7 @@ const $ = require("jquery"); const io = require("socket.io-client"); +const utils = require("./utils"); const path = window.location.pathname + "socket.io/"; const status = $("#loading-page-message, #connection-error"); @@ -43,6 +44,12 @@ function handleDisconnect(data) { status.text(`Waiting to reconnect… (${message})`).addClass("shown"); $(".show-more-button, #input").prop("disabled", true); $("#submit").hide(); + + // If the server shuts down, socket.io skips reconnection + // and we have to manually call connect to start the process + if (socket.io.skipReconnect) { + utils.requestIdleCallback(() => socket.connect(), 2000); + } } module.exports = socket;