Socket
Socket
Sign inDemoInstall

qr-scanner-maa

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    qr-scanner-maa

qr scanner frame to include in your app as iframe


Version published
Maintainers
1
Install size
5.88 MB
Created

Readme

Source

Based on code-kotis/qr-code-scanner

QR scanner frame to embed to your project as an iframe. You can communicate with it using postMessage. You can switch cameras. Fallback to single image if streaming is not supported.

Features

  • Switch camera

  • Fallback to single image scan

  • Encapsulated logic in iframe and communicate with it through postMessage

  • Listen for scan results and other events through window.addEventListener

Installation

  1. Clone this repo
git clone https://github.com/maa105/qr-code-scanner
  1. Installation
npm install
  1. Run (Dev)
npm run start
  1. Build
npm run build
  1. Move dist folder to your app and use the index.html in your app as src of iframe

  2. communicate with iframe through:

6.1. listen to events:


  window.addEventListener('message', (message) => {
    if(message.data.event === 'scan-result') {
      console.log('Scan Result: ', message.data.result);
    }
    else if(message.data.event === 'init-status') {
      if(message.data.streaming) {
        console.log('Cameras available:', message.data.devices);
        console.log('Selected camera:', message.data.devices[message.data.selected]);
      }
      else {
        console.log('Fallback use postMessage { command: "scan" }');
      }
    }
    else if(message.data.event === 'next-device-result') {
      if(message.data.success) {
        console.log('Cameras available:', message.data.devices);
        console.log('Selected camera:', message.data.devices[message.data.selected]);
      }
      else {
        console.log('OOPS');
      }
    }
  });

6.2. send commands through postMessage


  document.getElementById('qr-scanner-frame').contentWindow.postMessage({
    command: 'next-device'
  });

// only use incase streaming is false
  document.getElementById('qr-scanner-frame').contentWindow.postMessage({
    command: 'scan'
  });

FAQs

Last updated on 17 Dec 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc