Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

instascan

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instascan

Webcam-driven QR code scanner.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
decreased by-26.74%
Maintainers
1
Weekly downloads
 
Created
Source

Instascan

Webcam-driven HTML5 QR code scanner.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Instascan</title>
    <script type="text/javascript" src="dist/instascan.min.js"></script>
  </head>
  <body>
    <video id="monitor"></video>
    <script type="text/javascript">
      var opts = {
        monitor: document.getElementById('monitor'),
        mirror: true,
        backgroundScan: false,
        refractoryPeriod: 3 * 1000,
        scanPeriod: 5,
        captureImage: false
      };
  
      var scanner = new Instascan.Scanner(opts);
      scanner.addListener('scan', function (content, image) {
        console.log(content);
      });
  
      Instascan.Camera.getCameras(function (err, cameras) {
        if (cameras && cameras.length > 0) {
          scanner.start(cameras[0]);
        }
      });
    </script>
  </body>
</html>

API

new Instascan.Scanner(opts)

  • Create a new scanner with options.
  • opts.monitor: The HTML element to use for the camera's video preview. Must be a <video> element. By default, an invisible element will be created.
  • opts.mirror: Whether to mirror the video preview. Default true.
  • opts.backgroundScan: Whether to scan when the tab is not shown/focused. When false, this reduces CPU usage when the page is not active. Default false.
  • opts.refractoryPeriod: The period, in milliseconds, before the same QR code will be consecutively recognized. Default 5000.
  • opts.scanPeriod: The period, in rendered frames, between scans. A lower scan period increases CPU usage but makes scan response faster. Default 1 (i.e. analyze every frame).
  • opts.captureImage: Whether to include the scanned image data as part of the scan result. See the scan event for format details. Default false.

scanner.start(camera)

  • Start scanning using camera as the source.
  • camera: Instance of Instascan.Camera from Instascan.Camera.getCameras.

scanner.stop()

  • Stop scanning. This releases the camera as well.

scanner.addListener('scan', callback)

  • Raised when a QR code is scanned using the camera.
  • callback: function (content, image)
  • content: Scanned content decoded from the QR code.
  • image: null if scanner.captureImage is false, otherwise, a base64-encoded WebP-compressed data URI of the camera frame used to decode the QR code.

scanner.addListener('active', callback)

  • Raised when the scanner becomes active as the result of scanner.start or the tab gaining focus.
  • callback: function ()

scanner.addListener('inactive', callback)

  • Raised when the scanner becomes inactive as the result of scanner.stop or the tab losing focus.
  • callback: function ()

scanner.addListener('error', callback)

  • Raised when an error occurs while trying to scan.
  • callback: function (err)
  • err: Error details.

Instascan.Camera.getCameras(callback)

  • Enumerate available video devices.
  • callback: function (err, cameras)
  • err: Any errors that occurred when enumerating cameras.
  • cameras: Array of Instascan.Camera instances available for use.

camera.id

  • Unique camera ID. Assigned by the browser.

camera.name

  • Camera name, including manufacturer and model, e.g. Microsoft Lifecam HD-3000.

Notes

License

Copyright © 2016 Chris Schmich
MIT License. See LICENSE for details.

Keywords

FAQs

Package last updated on 12 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc