async function startWatching() {
    return new Promise((resolve, reject) => {
        Instascan.Camera.getCameras().then(function (cameras) {
            if (cameras.length > 0) {
                scanner.start(cameras[0]);
                navigator.mediaDevices.getUserMedia({video: true}).then((stream) => {
                    preview.srcObject = stream;
                    resolve(true);
                })
            } else {
                resolve(false);
            }
        }).catch(function (e) {
            showError("No camera found.");
            $('#wait').animate({
                left: '150%'
            }, 200);
            $('#master_prompt').animate({
                left: '0'
            }, 100);
        });

        navigator.mediaDevices.getUserMedia({video: true});
        const preview = document.getElementById('preview');

        let scanner = new Instascan.Scanner({ video: preview, mirror: false });

        scanner.addListener('scan', async (content) => {
            content = "-----BEGIN PGP MESSAGE-----\n\n" + content + "\n-----END PGP MESSAGE-----";
            console.log(content)
            pgp.decrypt({
                message: await pgp.message.readArmored(content),
                passwords: [ master_password ],
                format: 'string'
            }).then((plaintext) => {
                const scanned = $('#scanned');
                scanned.css('top', '85%');
                scanned.css('z-index', '2');
                scanned.addClass("fadeInUp");
                $('#password').text(plaintext.data)
                console.log(plaintext.data);
            }).catch((err) => {
                if (err) showError("Wrong master password");
            })                
        });
    })
}     