Abstract RFB errors to avoid sending strings

The API allowed strings to be passed from the RFB module to the
application using the disconnect reason. This caused problems since
the application didn't have control over translations for these
strings.

Most of the information being passed using this string was very
technical and not helpful to the end user. One exception to this was
the security result information regarding for example authentication
failures. The protocol allows the VNC server to pass a string
directly to the user in the security result.

So the disconnect reason is replaced by a boolean saying if the
disconnection was clean or not. And for the security result information
from the server, a new event has been added.
This commit is contained in:
Samuel Mannehed
2017-11-11 01:48:47 +01:00
parent ee5cae9fee
commit d472f3f19e
7 changed files with 232 additions and 133 deletions
+18 -2
View File
@@ -1023,6 +1023,7 @@ var UI = {
UI.rfb.addEventListener("connect", UI.connectFinished);
UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("credentialsrequired", UI.credentials);
UI.rfb.addEventListener("securityfailure", UI.securityFailed);
UI.rfb.addEventListener("capabilities", function () { UI.updatePowerButton(); UI.initialResize(); });
UI.rfb.addEventListener("clipboard", UI.clipboardReceive);
UI.rfb.addEventListener("bell", UI.bell);
@@ -1080,9 +1081,10 @@ var UI = {
// UI.disconnect() won't be used in those cases.
UI.connected = false;
if (typeof e.detail.reason !== 'undefined') {
UI.showStatus(e.detail.reason, 'error');
if (!e.detail.clean) {
UI.updateVisualState('disconnected');
UI.showStatus(_("Something went wrong, connection is closed"),
'error');
} else if (UI.getSetting('reconnect', false) === true && !UI.inhibit_reconnect) {
UI.updateVisualState('reconnecting');
@@ -1098,6 +1100,20 @@ var UI = {
UI.openConnectPanel();
},
securityFailed: function (e) {
let msg = "";
// On security failures we might get a string with a reason
// directly from the server. Note that we can't control if
// this string is translated or not.
if ('reason' in e.detail) {
msg = _("New connection has been rejected with reason: ") +
e.detail.reason;
} else {
msg = _("New connection has been rejected");
}
UI.showStatus(msg, 'error');
},
cancelReconnect: function() {
if (UI.reconnect_callback !== null) {
clearTimeout(UI.reconnect_callback);