Skip to content

Commit 4116e4e

Browse files
author
Brett Berenz
authored
Small changes around remote connections (#857)
* Also deselect secure option if protocol disables it * Log but dont show error message for client timeouts
1 parent 399733c commit 4116e4e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

sample.html

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,17 +1401,19 @@ <h4 class="panel-title">Options</h4>
14011401
}
14021402

14031403
function startConnection(config) {
1404-
host = $('#connectionHost').val().trim();
1405-
usingSecure = $("#connectionUsingSecure").prop('checked');
1404+
var host = $('#connectionHost').val().trim();
1405+
var usingSecure = $("#connectionUsingSecure").prop('checked');
1406+
14061407
// Connect to a print-server instance, if specified
1407-
if(host != "" && host != 'localhost') {
1408-
if(config) {
1408+
if (host != "" && host != 'localhost') {
1409+
if (config) {
14091410
config.host = host;
14101411
config.usingSecure = usingSecure;
14111412
} else {
1412-
config = { host: host, usingSecure: usingSecure };
1413+
config = { host: host, usingSecure: usingSecure };
14131414
}
14141415
}
1416+
14151417
if (!qz.websocket.isActive()) {
14161418
updateState('Waiting', 'default');
14171419

@@ -1456,8 +1458,7 @@ <h4 class="panel-title">Options</h4>
14561458

14571459
qz.networking.devices().then(function(data) {
14581460
var list = '';
1459-
var hostname = '';
1460-
var username = '';
1461+
14611462
for(var i = 0; i < data.length; i++) {
14621463
var info = data[i];
14631464

@@ -1466,8 +1467,8 @@ <h4 class="panel-title">Options</h4>
14661467
" <strong>Hostname:</strong> <code>" + info.hostname + "</code>" +
14671468
"</li>" +
14681469
"<li>" +
1469-
" <strong>Username:</strong> <code>" + info.username + "</code>"
1470-
"</li>";
1470+
" <strong>Username:</strong> <code>" + info.username + "</code>" +
1471+
"</li>";
14711472
}
14721473
list += "<li>" +
14731474
" <strong>Interface:</strong> <code>" + (info.name || "UNKNOWN") + (info.id ? "</code> (<code>" + info.id + "</code>)" : "</code>") +
@@ -2407,7 +2408,14 @@ <h4 class="panel-title">Options</h4>
24072408
function resetGeneralOptions() {
24082409
//connection
24092410
$("#connectionHost").val('localhost');
2410-
$("#connectionUsingSecure").prop('disabled', location.protocol !== 'https:');
2411+
2412+
var secureOpt = $("#connectionUsingSecure");
2413+
if (location.protocol !== 'https:') {
2414+
secureOpt.prop('disabled', true);
2415+
secureOpt.prop('checked', false);
2416+
} else {
2417+
secureOpt.prop('disabled', false);
2418+
}
24112419
}
24122420

24132421
function resetRawOptions() {

src/qz/ws/PrintSocketClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.codehaus.jettison.json.JSONException;
77
import org.codehaus.jettison.json.JSONObject;
88
import org.eclipse.jetty.server.Server;
9+
import org.eclipse.jetty.websocket.api.CloseException;
910
import org.eclipse.jetty.websocket.api.Session;
1011
import org.eclipse.jetty.websocket.api.WebSocketException;
1112
import org.eclipse.jetty.websocket.api.annotations.*;
@@ -34,6 +35,7 @@
3435
import java.util.HashMap;
3536
import java.util.Locale;
3637
import java.util.concurrent.Semaphore;
38+
import java.util.concurrent.TimeoutException;
3739

3840

3941
@WebSocket
@@ -82,6 +84,12 @@ public void onClose(Session session, int closeCode, String reason) {
8284
@OnWebSocketError
8385
public void onError(Session session, Throwable error) {
8486
if (error instanceof EOFException) { return; }
87+
88+
if (error instanceof CloseException && error.getCause() instanceof TimeoutException) {
89+
log.error("Timeout error (Lost connection with client)", error);
90+
return;
91+
}
92+
8593
log.error("Connection error", error);
8694
trayManager.displayErrorMessage(error.getMessage());
8795
}

0 commit comments

Comments
 (0)