diff --git a/js/qz-websocket.js b/js/qz-websocket.js index 5952113..4e4f728 100644 --- a/js/qz-websocket.js +++ b/js/qz-websocket.js @@ -326,6 +326,11 @@ function mapMethods(websocket, methods) { window["qz"][key](setupMethods); } + // Special case for getNetworkUtilities + qz.getNetworkUtilities = function() { + return {setHostname: qz.setHostname, setPort: qz.setPort} + }; + logger.log("Sent methods off to get rehabilitated"); } diff --git a/sample.html b/sample.html index 953e2b7..486b5d7 100644 --- a/sample.html +++ b/sample.html @@ -869,8 +869,8 @@ if (isLoaded()) { // Makes a quick connection to www.google.com to determine the active interface // Note, if you don't wish to use google.com, you can customize the host and port - // qz.getNetworkUtilities().setHostname("qzindustries.com"); - // qz.getNetworkUtilities().setPort(80); + qz.getNetworkUtilities().setHostname("qz.io"); // optional, default is google.com + qz.getNetworkUtilities().setPort(80); // optional, default is 80 qz.findNetworkInfo(); // Automatically gets called when "qz.findPrinter()" is finished. diff --git a/src/qz/PrintFunction.java b/src/qz/PrintFunction.java index 4bfed8e..fe43596 100644 --- a/src/qz/PrintFunction.java +++ b/src/qz/PrintFunction.java @@ -718,6 +718,14 @@ public String getIP() { return this.getIPAddress(); } + public void setHostname(String hostname) throws SocketException, ReflectException, UnknownHostException { + getNetworkUtilities().setHostname(hostname); + } + + public void setPort(int port) throws SocketException, ReflectException, UnknownHostException { + getNetworkUtilities().setPort(port); + } + /** * Returns a comma separated String containing all MAC * Addresses found on the system, or null if none are found. diff --git a/src/qz/utils/NetworkUtilities.java b/src/qz/utils/NetworkUtilities.java index 1ce4072..48ca125 100644 --- a/src/qz/utils/NetworkUtilities.java +++ b/src/qz/utils/NetworkUtilities.java @@ -41,14 +41,6 @@ public class NetworkUtilities { private String hostname = "www.google.com"; private int port = 80; - public NetworkUtilities() throws SocketException, ReflectException, UnknownHostException { - try { - gatherNetworkInfo(); - } catch (IOException e) { - e.printStackTrace(); - } - } - public void setHostname(String hostname) { this.hostname = hostname; } @@ -75,11 +67,17 @@ public void gatherNetworkInfo() throws IOException, ReflectException { } } - public String getHardwareAddress() { + public String getHardwareAddress() throws IOException { + if (this.macAddress == null) { + gatherNetworkInfo(); + } return this.macAddress; } - public String getInetAddress() { + public String getInetAddress() throws IOException { + if (this.ipAddress == null) { + gatherNetworkInfo(); + } return this.ipAddress; } } diff --git a/src/qz/ws/PrintSocket.java b/src/qz/ws/PrintSocket.java index d15146c..faaf1a1 100644 --- a/src/qz/ws/PrintSocket.java +++ b/src/qz/ws/PrintSocket.java @@ -78,7 +78,7 @@ public class PrintSocket { private final List printingMethods = Arrays.asList("print", "printHTML", "printPS", "printToFile", "printToHost"); // List of methods that will cause the gateway dialog to pop-up private final List privilegedMethods = Arrays.asList("findNetworkInfo", "closePort", "findPrinter", "findPrinters", - "findPorts", "openPort", "send", "setSerialProperties", "setSerialBegin", "setSerialEnd", "getSerialIO"); + "findPorts", "openPort", "send", "setSerialProperties", "setSerialBegin", "setSerialEnd", "getSerialIO", "setHostname", "setPort"); private final TrayManager trayManager = PrintWebSocketServer.getTrayManager();