diff --git a/packages/stream/stream_client.js b/packages/stream/stream_client.js index f7e86985cb..c7486bcdd6 100644 --- a/packages/stream/stream_client.js +++ b/packages/stream/stream_client.js @@ -99,13 +99,6 @@ if (typeof Sky === "undefined") Sky = {}; status_changed(); - }; - var disconnected = function () { - if (connection_timer) { - clearTimeout(connection_timer); - connection_timer = undefined; - } - retry_later(); // sets status. no need to do it here. }; var cleanup_socket = function () { if (socket) { @@ -115,6 +108,14 @@ if (typeof Sky === "undefined") Sky = {}; socket.disconnect(); } }; + var disconnected = function () { + if (connection_timer) { + clearTimeout(connection_timer); + connection_timer = undefined; + } + cleanup_socket(); + retry_later(); // sets status. no need to do it here. + }; var fake_connect_failed = function () { // sometimes socket.io just doesn't tell us when it failed. we // detect this with a timer and force failure. @@ -134,6 +135,7 @@ if (typeof Sky === "undefined") Sky = {}; }; var retry_later = function () { var timeout = retry_timeout(status.retry_count) + if (retry_timer) { clearTimeout(retry_timer); } retry_timer = setTimeout(retry_now, timeout); status.status = "waiting" @@ -152,7 +154,7 @@ if (typeof Sky === "undefined") Sky = {}; }; var launch_connection = function () { - cleanup_socket(); // cleanup the old socket. + cleanup_socket(); // cleanup the old socket, if there was one. socket = io.connect('/', { reconnect: false, 'connect timeout': CONNECT_TIMEOUT,