Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Add setHostname, setPort to QZ Tray 1.9 API
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Mar 16, 2016
1 parent fdcc9dd commit ec46038
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions js/qz-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
4 changes: 2 additions & 2 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/qz/PrintFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>String</code> containing all MAC
* Addresses found on the system, or <code>null</code> if none are found.
Expand Down
18 changes: 8 additions & 10 deletions src/qz/utils/NetworkUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/qz/ws/PrintSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class PrintSocket {
private final List<String> printingMethods = Arrays.asList("print", "printHTML", "printPS", "printToFile", "printToHost");
// List of methods that will cause the gateway dialog to pop-up
private final List<String> 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();

Expand Down

0 comments on commit ec46038

Please sign in to comment.