public/verifier/qr.js
// Opens the scanner UI and scans single and multi-part qr codes
Opens the scanner UI and scans single and multi-part qr codes
Opens the scanner UI and scans single and multi - part qr codes
async function scanQrCodes() {
        const qrModalEl = document.getElementById('qrModal');
        const qrModal = bootstrap.Modal.getInstance(qrModalEl);
        qrModal.show();
        const multiLabel = document.getElementById('multipart');
        multiLabel.innerHTML = ''; 
        let scannedParts = [];
        while (true) {
            let label = 'Parts : ';
            const scanResult = await qrScanner.scan();
            if (scanResult?.state === 'stopped') break;
            if (!scanResult.data) continue;
            let part = parseShc(scanResult.data);
            if (!part) part = { full: scanResult.data };
            part.version = scanResult.version;
            if (part.parts === undefined) {
                scannedParts = [part];
                break;
            }
            if (scannedParts.length && (part.parts != scannedParts.length)) {
                scannedParts = [];
            }
            if (scannedParts.length === 0) {
                scannedParts.length = part.parts;
            }
            scannedParts[part.part - 1] = part;
            for (let i = 0; i < scannedParts.length; i++) {
                let part = scannedParts[i];
                label += part ? `<span class="scannedPart">${i + 1}</span>&nbsp;&nbsp;` : `<span class="unscannedPart">${i + 1}</span>&nbsp;&nbsp;`;
            }
            multiLabel.innerHTML = label;
            if (!scannedParts.includes(undefined)) break;
        }
        qrModal.hide();
        while (qrModal._isShown) {
            qrModal.hide();
            if (qrModal._isShown) await delay(10);
        }
        return scannedParts;
    }
async function scanQrCodes ( ) { const qrModalEl = document . getElementById ( 'qrModal' ) ; const qrModal = bootstrap . Modal . getInstance ( qrModalEl ) ; qrModal . show ( ) ; const multiLabel = document . getElementById ( 'multipart' ) ; multiLabel . innerHTML = '' ; let scannedParts = [ ] ; while ( true ) { let label = 'Parts : ' ; const scanResult = await qrScanner . scan ( ) ; if ( scanResult ?. state === 'stopped' ) break ; if ( ! scanResult . data ) continue ; let part = parseShc ( scanResult . data ) ; if ( ! part ) part = { full : scanResult . data } ; part . version = scanResult . version ; if ( part . parts === undefined ) { scannedParts = [ part ] ; break ; } if ( scannedParts . length && ( part . parts != scannedParts . length ) ) { scannedParts = [ ] ; } if ( scannedParts . length === 0 ) { scannedParts . length = part . parts ; } scannedParts [ part . part - 1 ] = part ; for ( let i = 0 ; i < scannedParts . length ; i ++ ) { let part = scannedParts [ i ] ; label += part ? ` ${ i + 1 } ` : ` ${ i + 1 } ` ; } multiLabel . innerHTML = label ; if ( ! scannedParts . includes ( undefined ) ) break ; } qrModal . hide ( ) ; while ( qrModal . _isShown ) { qrModal . hide ( ) ; if ( qrModal . _isShown ) await delay ( 10 ) ; } return scannedParts ; }
Opens the scanner UI and scans single and multi-part qr codes
Opens the scanner UI and scans single and multi - part qr codes
// reveal the qr scanner ui // may be dirty from previous scans // if the scanner was closed by the user // sometimes the scanner returns without data, try again // construct a part if it could not be parsed // set the qr version // if the qr code could not be parse or it's a single part qr code, return it. // if previous multi-parts scan has n parts, and this scan has m parts, // clear and start over with this single part // set the parts array to the number of expected parts // set the part. A second scan of part 'x' will replace existing part 'x' // create the label that shows the current number of parts and expected total // if we have all parts, exit the scan loop // close the scanner ui // Sometimes the scan happens so fast that the modal isn't hidden in time