1212 < h1 style ="font-size: 1.5em; "> Read Barcodes from Camera - Debug</ h1 >
1313 < button id ="btn-show-scanner "> show scanner</ button >
1414 < br >
15- < div id ="div-video-container " style ="width:100%;height:calc(100vh - 100px); "> </ div >
15+ < label > < input type ="radio " name ="video-settings " checked value ="default "> default</ label >
16+ < label > < input type ="radio " name ="video-settings " value ="back-camera "> back camera</ label >
17+ < label > < input type ="radio " name ="video-settings " value ="only-video "> only video</ label >
18+ < br >
19+ < label > < input id ="cb-send-img " type ="checkbox "> send image to</ label > < input id ="ipt-server-url " placeholder ="server url, default ./collect ">
20+ < br >
21+ < div id ="div-video-container " style ="width:100%;height:calc(100vh - 150px); "> </ div >
22+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/eruda/2.4.1/eruda.min.js "> </ script >
1623 < script src ="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.3/dist/dbr.js "> </ script >
1724 < script >
25+ eruda . init ( ) ;
26+ Dynamsoft . DBR . _onLog = console . log ;
1827 /** LICENSE ALERT - README
1928 * The library requires a license to work, you use the API organizationID to tell the program where to fetch your license.
2029 * If the Organizaion ID is not specified, a 7-day (public) trial license will be used by default which is the case in this sample.
@@ -49,11 +58,12 @@ <h1 style="font-size: 1.5em;">Read Barcodes from Camera - Debug</h1>
4958 scanner . ifSaveOriginalImageInACanvas = true ;
5059 let processingCount = 0 ;
5160 scanner . onFrameRead = async results => {
61+ let bSendImg = ! ! document . getElementById ( "cb-send-img" ) . checked ;
5262 /**
5363 * The barcode reading speed is very fast, we must limit
5464 * the number of uploaded frames (4), so that it is feasible.
5565 */
56- if ( processingCount < 4 ) {
66+ if ( bSendImg && processingCount < 4 ) {
5767 ++ processingCount ;
5868 try {
5969 /**
@@ -69,7 +79,7 @@ <h1 style="font-size: 1.5em;">Read Barcodes from Camera - Debug</h1>
6979 cvs . toBlob ( blob => resolve ( blob ) ) ;
7080 } ) ;
7181 fd . append ( "img" , blob ) ;
72- await fetch ( "collect" , {
82+ await fetch ( document . getElementById ( "ipt-server-url" ) . value || "collect" , {
7383 method : "POST" ,
7484 body : fd
7585 } ) ;
@@ -87,6 +97,24 @@ <h1 style="font-size: 1.5em;">Read Barcodes from Camera - Debug</h1>
8797 throw ex ;
8898 }
8999 } ) ;
100+
101+ let switchVideoSettings = async ( ) => {
102+ if ( ! pScanner ) return ;
103+ let scanner = await pScanner ;
104+ switch ( document . querySelector ( 'input[name="video-settings"]:checked' ) . value ) {
105+ case "back-camera" :
106+ await scanner . updateVideoSettings ( { video :{ facingMode :"environment" } } ) ;
107+ break ;
108+ case "only-video" :
109+ await scanner . updateVideoSettings ( { video :true } ) ;
110+ break ;
111+ default :
112+ await scanner . updateVideoSettings ( { video :{ width :{ ideal :1280 } , height :{ ideal :720 } , facingMode :{ ideal :"environment" } } } ) ;
113+ }
114+ } ;
115+ for ( let ipt of document . querySelectorAll ( 'input[name="video-settings"]' ) ) {
116+ ipt . addEventListener ( "change" , switchVideoSettings ) ;
117+ }
90118 </ script >
91119</ body >
92120
0 commit comments