client: clearer state transitions, separate disconnected state
This commit is contained in:
parent
0a5db6a015
commit
a927add8c5
@ -293,7 +293,7 @@ var submit = function() {
|
|||||||
var str = $("#chatbox").value;
|
var str = $("#chatbox").value;
|
||||||
if (! str.length) return;
|
if (! str.length) return;
|
||||||
|
|
||||||
if (hub_state === 0) {
|
if (hub_state === STATE_READY_FOR_LOGIN) {
|
||||||
transition(1); // disables #chatbox
|
transition(1); // disables #chatbox
|
||||||
|
|
||||||
hub_last_nick = str.split(":", 2)[0];
|
hub_last_nick = str.split(":", 2)[0];
|
||||||
@ -315,7 +315,7 @@ var submit = function() {
|
|||||||
sock.emit('hello', {'nick' : hub_last_nick, 'pass' : hub_pass});
|
sock.emit('hello', {'nick' : hub_last_nick, 'pass' : hub_pass});
|
||||||
write("tab-main").system("Connecting...");
|
write("tab-main").system("Connecting...");
|
||||||
|
|
||||||
} else if (hub_state === 2) {
|
} else if (hub_state === STATE_ACTIVE) {
|
||||||
if (pm_target !== false) {
|
if (pm_target !== false) {
|
||||||
sock.emit('priv', {'user': pm_target, 'message': str});
|
sock.emit('priv', {'user': pm_target, 'message': str});
|
||||||
writerFor(pm_target).pub(hub_last_nick, str );
|
writerFor(pm_target).pub(hub_last_nick, str );
|
||||||
@ -668,6 +668,11 @@ var show_joins = false;
|
|||||||
|
|
||||||
var have_cleared_once = false;
|
var have_cleared_once = false;
|
||||||
|
|
||||||
|
var STATE_DISCONNECTED = -1;
|
||||||
|
var STATE_READY_FOR_LOGIN = 0;
|
||||||
|
var STATE_CONNECTING = 1;
|
||||||
|
var STATE_ACTIVE = 2;
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
var persistence_set = function(key, value) {
|
var persistence_set = function(key, value) {
|
||||||
@ -687,17 +692,29 @@ var persistence_get = function(key, fallback) {
|
|||||||
var transition = function(new_state) {
|
var transition = function(new_state) {
|
||||||
hub_state = new_state;
|
hub_state = new_state;
|
||||||
|
|
||||||
if (new_state === 0) {
|
switch(new_state) {
|
||||||
userlist.clear();
|
case STATE_DISCONNECTED: {
|
||||||
$("#chatbox").spellcheck = false;
|
userlist.clear();
|
||||||
|
$("#chatbox").disabled = true;
|
||||||
|
$("#chatbox").value = ''; // clear
|
||||||
|
} break;
|
||||||
|
|
||||||
} else if (new_state === 1) {
|
case STATE_READY_FOR_LOGIN: {
|
||||||
$("#chatbox").disabled = true;
|
userlist.clear();
|
||||||
|
$("#chatbox").spellcheck = false;
|
||||||
|
$("#chatbox").disabled = false;
|
||||||
|
$("#chatbox").value = ''; // clear
|
||||||
|
} break;
|
||||||
|
|
||||||
} else if (new_state === 2) {
|
case STATE_CONNECTING: {
|
||||||
$("#chatbox").disabled = false;
|
$("#chatbox").disabled = true;
|
||||||
$("#chatbox").spellcheck = true;
|
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case STATE_ACTIVE: {
|
||||||
|
$("#chatbox").disabled = false;
|
||||||
|
$("#chatbox").spellcheck = true;
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -765,7 +782,7 @@ window.onload = function() {
|
|||||||
|
|
||||||
sock = io.connect(DCWEBUI_CONF.extern);
|
sock = io.connect(DCWEBUI_CONF.extern);
|
||||||
sock.on('cls', function() {
|
sock.on('cls', function() {
|
||||||
transition(0);
|
transition(STATE_READY_FOR_LOGIN);
|
||||||
|
|
||||||
var pre_login = persistence_get("login", "");
|
var pre_login = persistence_get("login", "");
|
||||||
if (pre_login.indexOf(":") !== -1) {
|
if (pre_login.indexOf(":") !== -1) {
|
||||||
@ -809,7 +826,7 @@ window.onload = function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
sock.on('hello', function() {
|
sock.on('hello', function() {
|
||||||
transition(2);
|
transition(STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
sock.on('part', function(u) {
|
sock.on('part', function(u) {
|
||||||
userlist.del(u.user);
|
userlist.del(u.user);
|
||||||
@ -832,11 +849,11 @@ window.onload = function() {
|
|||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
});
|
});
|
||||||
sock.on('close', function() {
|
sock.on('close', function() {
|
||||||
transition(0);
|
transition(STATE_DISCONNECTED);
|
||||||
write("tab-main").system("Connection closed by remote host.");
|
write("tab-main").system("Connection closed by remote host.");
|
||||||
});
|
});
|
||||||
sock.on('disconnect', function() {
|
sock.on('disconnect', function() {
|
||||||
transition(0);
|
transition(STATE_DISCONNECTED);
|
||||||
write("tab-main").system("Lost connection to the server.");
|
write("tab-main").system("Lost connection to the server.");
|
||||||
});
|
});
|
||||||
sock.on('usercommand', function(data) {
|
sock.on('usercommand', function(data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user