|
| 1 | +import './HelloWorld.css'; |
| 2 | +import reactLogo from '../../logo.svg'; |
| 3 | +import "../../dbr"; // import side effects. The license, engineResourcePath, so on. |
| 4 | +import { BarcodeReader } from "dynamsoft-javascript-barcode"; |
| 5 | +import React from 'react'; |
| 6 | +import VideoDecode from '../VideoDecode/VideoDecode'; |
| 7 | +import ImgDecode from '../ImgDecode/ImgDecode'; |
| 8 | + |
| 9 | +interface isState { |
| 10 | + bShowScanner: boolean, |
| 11 | + bShowImgDecode: boolean |
| 12 | +} |
| 13 | + |
| 14 | +class HelloWorld extends React.Component<any, isState> { |
| 15 | + state = { |
| 16 | + bShowScanner: true, |
| 17 | + bShowImgDecode: false |
| 18 | + }; |
| 19 | + |
| 20 | + async componentDidMount() { |
| 21 | + try { |
| 22 | + await BarcodeReader.loadWasm(); |
| 23 | + } catch (ex: any) { |
| 24 | + if (ex.message.indexOf("network connection error")) { |
| 25 | + let customMsg = "Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license."; |
| 26 | + console.log(customMsg); |
| 27 | + alert(customMsg); |
| 28 | + } |
| 29 | + throw ex; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + showScanner = () => { |
| 34 | + this.setState({ |
| 35 | + bShowScanner: true, |
| 36 | + bShowImgDecode: false |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + showImgDecode = () => { |
| 41 | + this.setState({ |
| 42 | + bShowScanner: false, |
| 43 | + bShowImgDecode: true |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + render() { |
| 48 | + return ( |
| 49 | + <div className="helloWorld"> |
| 50 | + <h1>Hello World for React<img src={reactLogo} className="App-logo" alt="logo" /></h1> |
| 51 | + <div className="btn-group"> |
| 52 | + <button style={{ marginRight: '10px', backgroundColor: this.state.bShowScanner ? 'rgb(255,174,55)' : 'white' }} onClick={this.showScanner}>Video Decode</button> |
| 53 | + <button style={{ backgroundColor: this.state.bShowImgDecode ? 'rgb(255,174,55)' : 'white' }} onClick={this.showImgDecode}>Image Decode</button> |
| 54 | + </div> |
| 55 | + <div className="container"> |
| 56 | + {this.state.bShowScanner ? (<VideoDecode></VideoDecode>) : ""} |
| 57 | + {this.state.bShowImgDecode ? (<ImgDecode></ImgDecode>) : ""} |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + ); |
| 61 | + } |
| 62 | +} |
| 63 | +export default HelloWorld; |
0 commit comments