Fixed issues with reconnecting to the server and new profiles.

This commit is contained in:
jsrobson10 2019-04-23 11:44:31 +10:00
parent 067f06c0a2
commit 1d159570fc
3 changed files with 31 additions and 21 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2019 Copyright (c) 2019 Josua Robson
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -416,7 +416,6 @@ function connect(profile, connection_id)
} }
// Connect to the server // Connect to the server
console.log(profile.mode, port, hostname, client)
client.connect(port, hostname, function() client.connect(port, hostname, function()
{ {
console.log("Connected", profile.mode); console.log("Connected", profile.mode);
@ -426,6 +425,13 @@ function connect(profile, connection_id)
}); });
}); });
// Catch errors
client.on("error", function(e)
{
// Tell the user
console.log("Connection failed with error ", e);
});
// Create the recieve ordered memory model // Create the recieve ordered memory model
var recieve_ordered_memory = { var recieve_ordered_memory = {
buffer: new Buffer.alloc(0), buffer: new Buffer.alloc(0),
@ -501,18 +507,11 @@ function connect(profile, connection_id)
g.users = data.users; g.users = data.users;
g.chats = data.chats; g.chats = data.chats;
// Remove the disabled class // Save some global varibles
$("#profile_button_"+connection_id).removeClass("disabled"); g.logged_in = true;
// Set onclick // Reload the profiles
$("#profile_button_"+connection_id).on("click", function() profiles_reload();
{
// Switch to the profile id
profile_switch_to(connection_id);
});
// Set the href
document.getElementById("profile_button_"+connection_id).href = "#";
// Switch to this chat // Switch to this chat
profile_switch_to(connection_id); profile_switch_to(connection_id);

View File

@ -91,17 +91,14 @@ function profile_connect(id)
// Is the profile set // Is the profile set
if(profiles[id]) if(profiles[id])
{ {
// Connect to the server // Reconnect to the server
var server = connect(profiles[id], connections.length); connections[id] = connect(profiles[id], id);
// Add the server to the active connections
connections.push(server);
} }
else else
{ {
// Push an empty connection // Set an empty connection
connections.push(undefined); connections[id] = undefined;
} }
} }
@ -360,8 +357,22 @@ function profiles_reload()
// Create a list item // Create a list item
var profile = document.createElement("li"); var profile = document.createElement("li");
// Create the disabled class
var disabled_class = "class='disabled'";
// Is there a connection to the server
if(connections[i])
{
// Is the connection logged in
if(connections[i].logged_in)
{
// Remove the disabled class and make the link clickable
disabled_class = "href='#' onclick='profile_switch_to("+i+")'";
}
}
// Set the html for the list item // Set the html for the list item
profile.innerHTML = "<a class='disabled' id='profile_button_"+i+"'>"+title(i)+"</a>"; profile.innerHTML = "<a "+disabled_class+" id='profile_button_"+i+"'>"+title(i)+"</a>";
// Add the profile to the menu // Add the profile to the menu
chat_menu.appendChild(profile); chat_menu.appendChild(profile);