Allow graceful client reocnnection on server restart
This commit is contained in:
parent
ae5693f3ed
commit
9842d59901
5 changed files with 49 additions and 16 deletions
|
|
@ -111,6 +111,20 @@
|
|||
font-family: Monospace;
|
||||
}
|
||||
|
||||
.server-msg-disconnect {
|
||||
border: 1px solid #ff0000;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
color: #ff0000;
|
||||
}
|
||||
|
||||
.server-msg-reconnect {
|
||||
border: 1px solid #009900;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
color: #009900;
|
||||
}
|
||||
|
||||
.poll-notify {
|
||||
color: #0000aa;
|
||||
font-weight: bold;
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ function initCallbacks() {
|
|||
/* REGION Globals */
|
||||
|
||||
socket.on("disconnect", function() {
|
||||
$("<div/>").addClass("alert").addClass("alert-error")
|
||||
.insertAfter($(".row")[0])[0]
|
||||
.innerHTML = "<h3>Disconnected from server</h3>";
|
||||
handleDisconnect();
|
||||
});
|
||||
|
||||
socket.on("announcement", function(data) {
|
||||
|
|
@ -130,13 +128,14 @@ function initCallbacks() {
|
|||
div.appendTo($("#messagebuffer"));
|
||||
// Cap chatbox at most recent 100 messages
|
||||
if($("#messagebuffer").children().length > 100) {
|
||||
$($("#messagebufer").children()[0]).remove();
|
||||
$($("#messagebuffer").children()[0]).remove();
|
||||
}
|
||||
if(SCROLLCHAT)
|
||||
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
||||
});
|
||||
|
||||
socket.on("userlist", function(data) {
|
||||
$(".userlist_item").each(function() { this.remove(); });
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
addUser(data[i].name, data[i].rank, data[i].leader);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,15 +38,20 @@ var Rank = {
|
|||
Siteadmin: 255
|
||||
};
|
||||
|
||||
var socket = io.connect(IO_URL);
|
||||
initCallbacks();
|
||||
try {
|
||||
var socket = io.connect(IO_URL);
|
||||
initCallbacks();
|
||||
}
|
||||
catch(e) {
|
||||
handleDisconnect();
|
||||
}
|
||||
|
||||
$(window).focus(function() {
|
||||
FOCUSED = true;
|
||||
onWindowFocus();
|
||||
})
|
||||
.blur(function() {
|
||||
FOCUSED = false
|
||||
FOCUSED = false;
|
||||
});
|
||||
|
||||
var params = {};
|
||||
|
|
@ -89,11 +94,22 @@ else if(!params["channel"].match(/^[a-zA-Z0-9]+$/)) {
|
|||
.innerHTML = "<h3>Invalid Channel Name</h3><p>Channel names must conain only numbers and letters</p>";
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
socket.on("connect", function() {
|
||||
socket.emit("joinChannel", {
|
||||
name: params["channel"]
|
||||
});
|
||||
}
|
||||
if(uname != null && pw != null && pw != "false") {
|
||||
socket.emit("login", {
|
||||
name: uname,
|
||||
pw: pw
|
||||
});
|
||||
}
|
||||
$("<div/>").addClass("server-msg-reconnect")
|
||||
.text("Connected")
|
||||
.appendTo($("#messagebuffer"));
|
||||
setTimeout(function() { $("#reconnect_box").remove(); }, 3000);
|
||||
});
|
||||
|
||||
|
||||
// Load the youtube iframe API
|
||||
|
|
@ -102,13 +118,6 @@ tag.src = "http://www.youtube.com/iframe_api";
|
|||
var firstScriptTag = document.getElementsByTagName("script")[0];
|
||||
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||
|
||||
if(uname != null && pw != null && pw != "false") {
|
||||
socket.emit("login", {
|
||||
name: uname,
|
||||
pw: pw
|
||||
});
|
||||
}
|
||||
|
||||
var sendVideoUpdate = function() { }
|
||||
setInterval(function() {
|
||||
sendVideoUpdate();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,13 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
function handleDisconnect() {
|
||||
$("<div/>")
|
||||
.addClass("server-msg-disconnect")
|
||||
.text("Disconnected from server. Attempting reconnection...")
|
||||
.appendTo($("#messagebuffer"));
|
||||
}
|
||||
|
||||
// Adds a user to the chatbox userlist
|
||||
function addUser(name, rank, leader) {
|
||||
var div = $("<div/>").attr("class", "userlist_item");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue