Skip to content

Data Filtering

Tres Finocchiaro edited this page Jan 18, 2023 · 10 revisions

Compatibility

  • ✅ 2.2 | ✅ 2.1 | ⛔ 2.0 | ⛔ 1.9 | ...

Objective

  • Use sift library to filter/block unwanted MAC addresses, network adapters, and printers.

Prerequisites

  • Must be using QZ Tray 2.1 or later

  • Download and include sift.js

    Note: Optionally, you may npm install qz-sift

    <script type="text/javascript" src="path/to/sift.js"></script>

Contents

Printer Details

Note: The sift.js library is not needed for this.

You can get various printer information (driver, densities, default printer, trays) for system attached printers

qz.printers.details();

The result is returned as an object array

Loop through your results

function detailPrinters() {
    qz.printers.details().then(function(data) {
        for(var i = 0; i < data.length; i++) {
            console.log(data[i].name + " " + data[i].driver + " " + data[i].density + " " + data[i].trays);
        }
    }).catch(function(e) { console.error(e); });
}

Basic Syntax

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 });

Printers

Per the sift library:

  • Printers must be supplied in an object array and must contain a printer name and printer driver.

    [ { name: 'foo', driver: 'bar' }, { ... } ]

QZ Tray has a built-in function qz.printers.details(); that meets this criteria

Virtual Printers

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); });
}

Raw Printers

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); });
}

Network Information

MAC Address Filtering

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); });
}

Scales