Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an on and off option for the webcam #208

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"presets": [
"es2015",
"stage-0",
"react"
"@babel/env",
"@babel/preset-react"
]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ node_modules
# Optional REPL history
.node_repl_history


lib/worker.js
#output directory
lib
2 changes: 0 additions & 2 deletions .storybook/addons.js

This file was deleted.

9 changes: 0 additions & 9 deletions .storybook/config.js

This file was deleted.

4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
stories: ['../stories/*.stories.js'],
addons: ['@storybook/addon-actions/register', '@storybook/addon-links/register'],
};
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[![npm version](https://badge.fury.io/js/react-qr-reader.svg)](https://badge.fury.io/js/react-qr-reader)

## Introduction
This project is adopted from [react-qr-reader](https://github.com/JodusNodus/react-qr-reader).
I made a few changes:
1. Refactor the React component to not using the deprecated componentWillReceiveProps method.
2. Uses jsqr-es6 instead of jsqr.
3. Removed webrtc-adapter, if you need that, please install that package manually
4. Updated all toolchains and cleanup the NPM package, make it much smaller

In the end, it reduced the final lib from 140KB+ to 60KB+.

A [React](https://facebook.github.io/react/) component for reading QR codes from the webcam. It uses the WebRTC standards for reading webcam data and [jsQR](https://github.com/cozmo/jsQR) is used for detecting QR codes in that data. To optimise the speed and experience, a web-worker is used to offload the heavy QR code algorithm on a separate process. The web worker is inlined and loaded on creation of the component.

Expand All @@ -17,13 +25,13 @@ A [React](https://facebook.github.io/react/) component for reading QR codes from

## Install

`npm install --save react-qr-reader`
`npm install --save react-qr-reader-es6`

## Example

```js
import React, { Component } from 'react'
import QrReader from 'react-qr-reader'
import QrReader from 'react-qr-reader-es6'

class Test extends Component {
state = {
Expand Down
18 changes: 11 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const gulp = require('gulp')
const fs = require('fs')
const del = require('del')
const inlineStr = require('gulp-inline-str')
const replace = require('gulp-replace')
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
const concat = require('gulp-concat')
Expand All @@ -11,34 +12,37 @@ const babelOptions = JSON.parse(fs.readFileSync('./.babelrc', 'utf8'))
const paths = {
scripts: [ 'src/index.js', 'src/getDeviceId.js', 'src/havePropsChanged.js', 'src/errors.js', 'src/createBlob.js' ],
worker: 'src/worker.js',
jsQR: 'node_modules/jsqr/dist/jsQR.js',
jsQR: 'node_modules/jsqr-es6/dist/jsQR.js',
destination: './lib',
}

gulp.task('clean', function() {
return del([ paths.destination + '/*.js' ])
})

gulp.task('worker', [ 'clean' ], function() {
gulp.task('worker', gulp.series('clean', function() {
return gulp
.src([ paths.jsQR, paths.worker ])
.pipe(concat('worker.js'))
.pipe(uglify())
.pipe(replace('export{jsQR as default};', ''))
.pipe(gulp.dest(paths.destination))
})
}))

gulp.task('build', [ 'worker' ], function() {
gulp.task('build', gulp.series('worker', function() {
gulp.src('src/index.d.ts')
.pipe(gulp.dest(paths.destination))
return gulp
.src(paths.scripts)
.pipe(inlineStr({ basePath: paths.destination }))
.pipe(babel(babelOptions))
.pipe(gulp.dest(paths.destination))
})
}))

// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, [ 'build' ])
gulp.watch(paths.scripts, gulp.series('build'))
})

// The default task (called when you run `gulp` from cli)
gulp.task('default', [ 'build' ])
gulp.task('default', gulp.series('build'))
22 changes: 0 additions & 22 deletions lib/createBlob.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/errors.js

This file was deleted.

55 changes: 0 additions & 55 deletions lib/getDeviceId.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/havePropsChanged.js

This file was deleted.

470 changes: 0 additions & 470 deletions lib/index.js

This file was deleted.

Loading