Omit the connection warning if the socket connected at least once before

This commit is contained in:
calzoneman 2016-06-08 22:58:34 -07:00
parent 6e772c6837
commit 5b9948f709
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Callbacks = {
/* fired when socket connection completes */
connect: function() {
HAS_CONNECTED_BEFORE = true;
SOCKETIO_CONNECT_ERROR_COUNT = 0;
$("#socketio-connect-error").remove();
socket.emit("joinChannel", {
@ -1034,6 +1035,7 @@ Callbacks = {
partitionChange: function (socketConfig) {
window.socket.disconnect();
HAS_CONNECTED_BEFORE = false;
ioServerConnect(socketConfig);
setupCallbacks();
}
@ -1059,6 +1061,14 @@ setupCallbacks = function() {
}
socket.on("connect_error", function (error) {
// If the socket has connected at least once during this
// session and now gets a connect error, it is likely because
// the server is down temporarily and not because of any configuration
// issue. Therefore, omit the warning message about refreshing.
if (HAS_CONNECTED_BEFORE) {
return;
}
SOCKETIO_CONNECT_ERROR_COUNT++;
if (SOCKETIO_CONNECT_ERROR_COUNT >= 3 &&
$("#socketio-connect-error").length === 0) {

View File

@ -66,6 +66,7 @@ var FILTER_FROM = 0;
var FILTER_TO = 0;
var NO_STORAGE = typeof localStorage == "undefined" || localStorage === null;
var SOCKETIO_CONNECT_ERROR_COUNT = 0;
var HAS_CONNECTED_BEFORE = false;
function getOpt(k) {
var v = NO_STORAGE ? readCookie(k) : localStorage.getItem(k);