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

Fixes WebWorker usage to correct build issues #6

Merged
merged 1 commit into from
Jul 10, 2019
Merged
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
13 changes: 6 additions & 7 deletions src/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from "react";
import PropTypes from 'prop-types';
import VideoStream from './video_stream';
import QRWorker from './qr_decode.worker';

const wrapperStyles = {
display: 'flex',
Expand All @@ -13,7 +12,7 @@ class ReactiveQR extends Component {
webWorker = null;

componentWillMount() {
this.webWorker = new QRWorker();
this.webWorker = new Worker('qr_decode.worker.js');
this.webWorker.addEventListener('message', this.onFrameDecoded);
}

Expand All @@ -36,13 +35,13 @@ class ReactiveQR extends Component {
}

onFrame = (frameData) => this.webWorker.postMessage(frameData);
drawVideoFrame = () => {}
drawVideoFrame = () => { }

onFrameDecoded = (event) => {
const code = event.data;
if (code) {
const { data } = code;
if ( this.props.onCode && data.length > 0 ) {
if (this.props.onCode && data.length > 0) {
this.props.onCode(code);
}
}
Expand All @@ -54,7 +53,7 @@ class ReactiveQR extends Component {

render() {
return (
<div className={this.props.className} style={{...wrapperStyles, ...this.props.style}}>
<div className={this.props.className} style={{ ...wrapperStyles, ...this.props.style }}>
<VideoStream
onFrame={this.onFrame}
onInit={this.onVideoStreamInit}
Expand All @@ -77,9 +76,9 @@ ReactiveQR.propTypes = {
};

ReactiveQR.defaultProps = {
onInit: () => {},
onInit: () => { },
shouldDecode: true,
onCode: () => {},
onCode: () => { },
style: {},
videoStyle: {},
rearCamera: true,
Expand Down