scanthng.js

The scanthng.js SDK is a plugin to be used in combination with evrythng.js to allow easy access to the Identifier Recognition API. This allows JavaScript applications to use local images or image capture devices to look up Platform resources when presented with a barcode or pre-specified image.

πŸ“˜

Note

scanthng.js v3.1.0 is compatible with evrythng.js v4.7.2 and below.

scanthng.js v4.0.0 is compatible with evrythng.js v5.1.0 and above.

To learn more about implementing identification of codes associated with Platform Thngs and products, read Real-time Web Product Scanning.


Installation

Installation for this SDK is like the evrythng.js SDK installation, but the library name is scanthng instead of evrythng.

πŸ“˜

Note

Installation of evrythng.js or evrythng-extended.js is required to use this plugin.

Including the library in an application and performing initialization are identical. However, because this is a plugin, be sure to apply it to the base SDK:

evrythng.use(ScanThng);

Function Reference

All the functions available below must be used with an instance of an Application scope.

See the Identifier Recognition page for full details on params specified below, which determine the type of scan performed.

.scan(params);  // Start image capture with params containing the filter

.scan(base64Data, params);  // Scan a pre-shot image converted to a Base64 string
app.scan({
  filter: { method: '2d', type: 'qr_code' },
}).then(console.log);
.scanStream(params);  // Scan a barcode using a video stream from a device camera.
// Fast 2D QR code scanning
app.scanStream({
  filter: { method: '2d', type: 'qr_code' },
  
  // HTML element the video stream is displayed in
  containerId: 'stream_container',
}).then(console.log);

// Slower than other barcode scanning, but still using video
app.scanStream({
  filter: { method: '2d', type: 'dm' },
  containerId: 'stream_container',
}).then(console.log);
.identify(params);  // Read Thng/product linked to a predetermined Platform identifier value
app.identify({
  filter: { value: 'https://tn.gg/C1SNa4dtKF', type: 'qr_code' }
}).then(console.log);
.redirect(url);  // Redirect the browser to a URL, usually provided by an identification.
app.scan({
  filter: { method: '2d', type: 'qr_code' }
}).then((res) => {
  // Redirect to the specified URL
  app.redirect(res[0].results[0].redirections[0]);
});

Additional Options

Additional options are available to enhance the functionality of the scan. These must be included in the params alongside filter.

  • createAnonymousUser - Set to true to create an anonymous Application User to perform the scan.
  • perPage - Set to the desired maximum number of results per page.
  • imageConversion - Specify the conversion that takes place before the scan is performed.