Skip to content

Commit

Permalink
Small changes around remote connections (qzind#857)
Browse files Browse the repository at this point in the history
* Also deselect secure option if protocol disables it

* Log but dont show error message for client timeouts
  • Loading branch information
Brett Berenz authored Sep 3, 2021
1 parent 399733c commit 4116e4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
28 changes: 18 additions & 10 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -1401,17 +1401,19 @@ <h4 class="panel-title">Options</h4>
}

function startConnection(config) {
host = $('#connectionHost').val().trim();
usingSecure = $("#connectionUsingSecure").prop('checked');
var host = $('#connectionHost').val().trim();
var usingSecure = $("#connectionUsingSecure").prop('checked');

// Connect to a print-server instance, if specified
if(host != "" && host != 'localhost') {
if(config) {
if (host != "" && host != 'localhost') {
if (config) {
config.host = host;
config.usingSecure = usingSecure;
} else {
config = { host: host, usingSecure: usingSecure };
config = { host: host, usingSecure: usingSecure };
}
}

if (!qz.websocket.isActive()) {
updateState('Waiting', 'default');

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

qz.networking.devices().then(function(data) {
var list = '';
var hostname = '';
var username = '';

for(var i = 0; i < data.length; i++) {
var info = data[i];

Expand All @@ -1466,8 +1467,8 @@ <h4 class="panel-title">Options</h4>
" <strong>Hostname:</strong> <code>" + info.hostname + "</code>" +
"</li>" +
"<li>" +
" <strong>Username:</strong> <code>" + info.username + "</code>"
"</li>";
" <strong>Username:</strong> <code>" + info.username + "</code>" +
"</li>";
}
list += "<li>" +
" <strong>Interface:</strong> <code>" + (info.name || "UNKNOWN") + (info.id ? "</code> (<code>" + info.id + "</code>)" : "</code>") +
Expand Down Expand Up @@ -2407,7 +2408,14 @@ <h4 class="panel-title">Options</h4>
function resetGeneralOptions() {
//connection
$("#connectionHost").val('localhost');
$("#connectionUsingSecure").prop('disabled', location.protocol !== 'https:');

var secureOpt = $("#connectionUsingSecure");
if (location.protocol !== 'https:') {
secureOpt.prop('disabled', true);
secureOpt.prop('checked', false);
} else {
secureOpt.prop('disabled', false);
}
}

function resetRawOptions() {
Expand Down
8 changes: 8 additions & 0 deletions src/qz/ws/PrintSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.websocket.api.CloseException;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.annotations.*;
Expand Down Expand Up @@ -34,6 +35,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeoutException;


@WebSocket
Expand Down Expand Up @@ -82,6 +84,12 @@ public void onClose(Session session, int closeCode, String reason) {
@OnWebSocketError
public void onError(Session session, Throwable error) {
if (error instanceof EOFException) { return; }

if (error instanceof CloseException && error.getCause() instanceof TimeoutException) {
log.error("Timeout error (Lost connection with client)", error);
return;
}

log.error("Connection error", error);
trayManager.displayErrorMessage(error.getMessage());
}
Expand Down

0 comments on commit 4116e4e

Please sign in to comment.