diff --git a/templates/channel.jade b/templates/channel.jade index 3c279578..561a0d4c 100644 --- a/templates/channel.jade +++ b/templates/channel.jade @@ -236,7 +236,7 @@ html(lang="en") #pmbar include footer mixin footer() - script(src=sioSource) + script(id="socketio-js", src=sioSource) script(src="/js/data.js") script(src="/js/util.js") script(src="/js/player.js") diff --git a/www/js/callbacks.js b/www/js/callbacks.js index 5c862d50..eb716e41 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -6,7 +6,8 @@ Callbacks = { /* fired when socket connection completes */ connect: function() { - socket.emit("initChannelCallbacks"); + SOCKETIO_CONNECT_ERROR_COUNT = 0; + $("#socketio-connect-error").remove(); socket.emit("joinChannel", { name: CHANNEL.name }); @@ -1050,14 +1051,32 @@ setupCallbacks = function() { }); })(key); } + + socket.on("connect_error", function (error) { + SOCKETIO_CONNECT_ERROR_COUNT++; + if (SOCKETIO_CONNECT_ERROR_COUNT >= 3 && + $("#socketio-connect-error").length === 0) { + var message = "Failed to connect to the server. Try clearing your " + + "cache and refreshing the page."; + makeAlert("Error", message, "alert-danger") + .attr("id", "socketio-connect-error") + .appendTo($("#announcements")); + } + }); }; (function () { if (typeof io === "undefined") { - makeAlert("Uh oh!", "It appears the socket.io connection " + - "has failed. If this error persists, a firewall or " + - "antivirus is likely blocking the connection, or the " + - "server is down.", "alert-danger") + var script = document.getElementById("socketio-js"); + var source = "unknown"; + if (script) { + source = script.src; + } + + var message = "The socket.io library could not be loaded from " + + source + ". Ensure that it is not being blocked " + + "by a script blocking extension or firewall and try again."; + makeAlert("Error", message, "alert-danger") .appendTo($("#announcements")); Callbacks.disconnect(); return; diff --git a/www/js/data.js b/www/js/data.js index 5dbfacb7..ab9a5fce 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -65,6 +65,7 @@ var PL_WAIT_SCROLL = false; var FILTER_FROM = 0; var FILTER_TO = 0; var NO_STORAGE = typeof localStorage == "undefined" || localStorage === null; +var SOCKETIO_CONNECT_ERROR_COUNT = 0; function getOpt(k) { var v = NO_STORAGE ? readCookie(k) : localStorage.getItem(k);