1let anyline = null; 2let mirrored = false; 3 4async function mountAnylineWebSDK(root, anylineLicenseKey) { 5 if (window.location.hostname.indexOf('smartstartinc') == -1) return; 6 try { 7 anyline = window.anylinejs.init({ 8 config: { 9 module: 'barcode', 10 barcodeConfig: { 11 barcodeFormats: ['PDF_417'], 12 parseAAMVA: true, 13 multiBarcode: false 14 } 15 }, 16 hapticFeedback: true, 17 //viewConfig: { 18 // cutouts: [ 19 // { 20 // cancelOnResult: true, 21 // }, 22 // ], 23 //}, 24 preset: "barcode", 25 license: anylineLicenseKey, 26 element: root, 27 debugAnyline: false, 28 anylinePath: '../../lib/anyline/anylinejs', 29 }); 30 31 anyline.onResult = (data) => { 32 console.log('Anyline Result: ', data); 33 var licenseData = data.result.barcodeResult.barcodes[0].aamva['body-part']; 34 35 VmStore.DriverLicenseVm.showDriverLicenseScanResults(licenseData); 36 }; 37 38 /** 39 * Uncomment this to use the callback that 40 * gets all scanned barcodes passed which 41 * are visible within the cutout. 42 */ 43 anyline.onScannedBarcodes = (result) => { 44 console.log('Barcode Result: ', result); 45 }; 46 47 await appendCameraSelector(anyline); 48 49 await anyline.startScanning().catch((e) => alert(e.message)); 50 } catch (e) { 51 alert(e.message); 52 console.error(e); 53 } 54} 55 56/** 57 * Appends camera selector. 58 */ 59async function appendCameraSelector(anyline) { 60 if (document.getElementById('camera-switcher')) return; 61 62 const stream = await navigator.mediaDevices.getUserMedia({ 63 video: {}, 64 audio: false, 65 }); 66 67 stream.getTracks().forEach((track) => { 68 stream.removeTrack(track); 69 track.stop(); 70 }); 71 72 const devices = (await navigator.mediaDevices.enumerateDevices()) || []; 73 74 //renderSelect({ 75 // options: devices 76 // .filter((m) => m.kind === 'videoinput') 77 // .map((camera) => ({ 78 // text: camera.label, 79 // value: camera.deviceId, 80 // })) 81 // .reduce((acc, camera) => [...acc, camera], [{ text: 'switch cam' }]), 82 // onSelect: (deviceId) => deviceId && anyline.camera.setCamera(deviceId), 83 //}); 84} 85 86/** 87 * Remount the Anyline Web SDK. 88 */ 89function remountWebSDK(root) { 90 anyline.stopScanning(); 91 anyline.dispose(); 92 mountAnylineJS(root); 93} 94 95/** 96 * Disable/Enable flash (for Chrome on Android). 97 */ 98async function disableFlash() { 99 if (!anyline) return; 100 try { 101 await anyline.camera.activateFlash(false); 102 } catch (e) { 103 alert(e.message); 104 } 105} 106async function enableFlash() { 107 if (!anyline) return; 108 try { 109 await anyline.camera.activateFlash(true); 110 } catch (e) { 111 alert(e.message); 112 } 113} 114 115/** 116 * Mirrors the camera. 117 */ 118function mirrorCamera() { 119 if (!anyline) return; 120 const newState = !mirrored; 121 anyline.camera.mirrorStream(newState); 122 mirrored = newState; 123} 124 125/** 126 * Reappends the camera. 127 */ 128function reappendCamera() { 129 if (!anyline) return; 130 anyline.camera.reappend(); 131} 132 133/** 134 * Renders a drop-down for selecting the available cameras. 135 */
136function renderSelect({ options, onSelect }) { 137 //const parent = document.getElementById('sidebar'); 138 139 //Create and append select list 140 //const selectEl = document.createElement('select'); 141 //selectEl.id = 'camera-switcher'; 142 //selectEl.classList.add('preset-select'); 143 //parent.appendChild(selectEl); 144 145 //options.forEach((option) => { 146 // const optionEl = document.createElement('option'); 147 // optionEl.value = option.value; 148 // optionEl.text = option.text; 149 // selectEl.appendChild(optionEl); 150 //}); 151 152 //selectEl.onchange = (e) => onSelect(e.target.value); 153} 154 155/** 156 * Refocus camera (for Chrome on Android). 157 */ 158async function refocus() { 159 if (!anyline) return; 160 try { 161 await anyline.camera.refocus(); 162 } catch (e) { 163 alert(e.message); 164 } 165}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.