Fixed issues with reconnecting to the server and new profiles.
This commit is contained in:
parent
067f06c0a2
commit
1d159570fc
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019
|
||||
Copyright (c) 2019 Josua Robson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -416,7 +416,6 @@ function connect(profile, connection_id)
|
|||
}
|
||||
|
||||
// Connect to the server
|
||||
console.log(profile.mode, port, hostname, client)
|
||||
client.connect(port, hostname, function()
|
||||
{
|
||||
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
|
||||
var recieve_ordered_memory = {
|
||||
buffer: new Buffer.alloc(0),
|
||||
|
@ -501,18 +507,11 @@ function connect(profile, connection_id)
|
|||
g.users = data.users;
|
||||
g.chats = data.chats;
|
||||
|
||||
// Remove the disabled class
|
||||
$("#profile_button_"+connection_id).removeClass("disabled");
|
||||
// Save some global varibles
|
||||
g.logged_in = true;
|
||||
|
||||
// Set onclick
|
||||
$("#profile_button_"+connection_id).on("click", function()
|
||||
{
|
||||
// Switch to the profile id
|
||||
profile_switch_to(connection_id);
|
||||
});
|
||||
|
||||
// Set the href
|
||||
document.getElementById("profile_button_"+connection_id).href = "#";
|
||||
// Reload the profiles
|
||||
profiles_reload();
|
||||
|
||||
// Switch to this chat
|
||||
profile_switch_to(connection_id);
|
||||
|
|
|
@ -91,17 +91,14 @@ function profile_connect(id)
|
|||
// Is the profile set
|
||||
if(profiles[id])
|
||||
{
|
||||
// Connect to the server
|
||||
var server = connect(profiles[id], connections.length);
|
||||
|
||||
// Add the server to the active connections
|
||||
connections.push(server);
|
||||
// Reconnect to the server
|
||||
connections[id] = connect(profiles[id], id);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Push an empty connection
|
||||
connections.push(undefined);
|
||||
// Set an empty connection
|
||||
connections[id] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,8 +357,22 @@ function profiles_reload()
|
|||
// Create a list item
|
||||
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
|
||||
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
|
||||
chat_menu.appendChild(profile);
|
||||
|
|
Loading…
Reference in New Issue