Skip to content

Data Filtering

Tres Finocchiaro edited this page Jan 21, 2017 · 10 revisions

Compatibility

  • ✅ 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

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

Contents

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

Clone this wiki locally