1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(console): a console the server closes says Connection lost, not Disconnected

The VNC and serial pages showed "Disconnected", as if the user had ended
the session, when the VM stopped, was migrated or the console daemon
restarted: noVNC calls a close by the server clean, and the serial page
had a single text. "Disconnected" is now kept for the user's own
Disconnect; any other end of a working connection is "Connection lost"
(the serial terminal still prints the server's reason).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-10 18:58:20 +03:00
parent 450ffbba30
commit 16ad625cda
3 changed files with 8 additions and 3 deletions

View file

@ -14,6 +14,7 @@
{% block navbarstatus %}
<span id="status" class="badge text-bg-secondary" role="status"
data-connected="{% trans "Connected" %}" data-disconnected="{% trans "Disconnected" %}"
data-lost="{% trans "Connection lost" %}"
data-taken-over="{% trans "Taken over by %(name)s" %}"
data-hint="{% trans "Connected. If the VM shows nothing, press Enter." %}">{% trans "Connecting" %}</span>
{% endblock %}

View file

@ -58,13 +58,14 @@ socket.on('connect', () => {
socket.on('taken_over', (data) => {
takenBy = data.by;
});
socket.on('disconnect', () => {
socket.on('disconnect', (reason) => {
if (takenBy) {
const text = status.dataset.takenOver.replace('%(name)s', takenBy);
term.write('\r\n[' + text + ']\r\n');
showStatus(text, 'danger');
} else {
showStatus(status.dataset.disconnected, 'danger');
// the user's Disconnect, or the server's end (the terminal says why) or a lost connection
showStatus(reason === 'io client disconnect' ? status.dataset.disconnected : status.dataset.lost, 'danger');
}
});
// the server says why: serial console off, an expired link, the console open elsewhere

View file

@ -23,6 +23,7 @@ const rfb = new RFB(document.getElementById('screen'), url,
let connected = false;
let closed = false;
let disconnecting = false; // the user's Disconnect, not a lost connection
let refusal = null;
function showStatus(text, color) {
@ -47,7 +48,8 @@ rfb.addEventListener('disconnect', (e) => {
} else if (!connected) {
showStatus(status.dataset.failed, 'danger');
} else {
showStatus(e.detail.clean ? status.dataset.disconnected : status.dataset.lost, 'danger');
// noVNC calls a server's close clean too: the VM's stop, a migration, a restarted proxy
showStatus(disconnecting ? status.dataset.disconnected : status.dataset.lost, 'danger');
}
connectionButton.textContent = connectionButton.dataset.reconnect;
credentialsDialog.hide();
@ -58,6 +60,7 @@ connectionButton.addEventListener('click', () => {
if (closed) {
window.location.reload();
} else {
disconnecting = true;
rfb.disconnect();
}
});