-
Notifications
You must be signed in to change notification settings - Fork 277
Data Filtering
Tres Finocchiaro edited this page Jan 21, 2017
·
10 revisions
- ✅ 2.1 | ⛔ 2.0 | ⛔ 1.9 | ...
- Use
sift
library to filter/block unwanted MAC addresses, network adapters, and printers.
-
Must be using QZ Tray 2.1 or later
-
Download and include
sift.js
<script type="text/javascript" src="path/to/sift.js"></script>
- Basic Syntax
- Identify/Filter
- Printers
- MAC Addresses
- Scales
Remove whatever matches the option
from the data
object
sift.toss(data, { option });
Keep whatever matches the option
criteria from the data
object
sift.keep(data, { option });
Per the sift
library:
-
Printers must be supplied in an object array and must contain a printer
name
and printerdriver
.[ { name: 'foo', driver: 'bar' }, { ... } ]
QZ Tray has a built-in function qz.printers.details();
that meets this criteria
The sift library can be used to filter out virtual printers. This can be useful for preventing a user from printing, for example, coupons to a PDF printer.
- Return only the physical printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { physical: true }); //same as sift.toss(data, { physical: false });
console.log(data);
}).catch(function(e) { console.error(e); });
}
- Return only the virtual printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { physical: false }); //same as sift.toss(data, { physical: true });
console.log(data);
}).catch(function(e) { console.error(e); });
}
Return only raw printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { type: 'raw' });
console.log(data);
}).catch(function(e) { console.error(e); });
}
Physical Adapter 🗿 | Virtual Adapter 👾 |
---|---|
burnedIn: true |
burnedIn: false |
Return only physical adapters
function listNetworkDevices() {
qz.networking.devices().then(function(data) {
data = sift.keep(data, {burnedIn: true });
console.log(data);
}).catch(function(e) { console.error(e); });
}