Back to Demos List

GSW CipherLab Scanner

This demonstration will show the ability to access CipherLab scanner from the soft button in the browser.









The fields below will contain the extra data captured by the scan.








About This Demo

This demo is using the GSW CipherLab Scanner plugin. For more information click here:

 
var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onGswScannerReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswcipherlabscanner.initialize(function(data) {
        console.log('initialize OK');
        document.getElementById('scan_now').addEventListener("touchstart", GSW.Tests.scanPressed);
        document.getElementById('scan_now').addEventListener("touchend", GSW.Tests.scanReleased);
        document.getElementById('scan_now').addEventListener("touchmove", GSW.Tests.scanReleased);
        document.getElementById('scan_now').addEventListener("touchcancel", GSW.Tests.scanReleased);
        GSW.Tests.disable();
    }, function(error) {
        if (error == "CipherLab scanner decode service is unavailable on this device") {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device was not manufactured by CipherLab and is not compatible with this demo."
        } else console.log('Initialize error occured: ' + error);
    });
}

GSW.Tests.scanPressed = function() {
    console.log("scanPressed");
    navigator.gswcipherlabscanner.enableTrigger(function(result) {
        navigator.gswcipherlabscanner.softwareTriggerStart(function(result) {
            document.getElementById('userid').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            console.log('Software scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Error occured: ' + error);
        });
    }, function(error) {
        console.log('Unable to enable trigger: ' + error);
    })
}

GSW.Tests.scanReleased = function() {
    console.log("scanReleased");
    navigator.gswcipherlabscanner.disableTrigger(function(result) {
        navigator.gswcipherlabscanner.softwareTriggerStop();
    }, function(error) {
        console.log('Unable to disable trigger: ' + error);
    })
}

GSW.Tests.disable = function() {
    navigator.gswcipherlabscanner.disableTrigger(function(result) {
        console.log('Trigger disabled');
    }, function(error) {
        console.log('Unable to disable trigger: ' + error);
    })
}
document.addEventListener('gswscannerready', GSW.Tests.onGswScannerReady, false);