Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         function tick() {
  2.             if (videoElement.readyState === videoElement.HAVE_ENOUGH_DATA) {
  3.                 canvasElement.hidden = false;
  4.                 canvasElement.height = videoElement.videoHeight;
  5.                 canvasElement.width = videoElement.videoWidth;
  6.  
  7.                 canvas.drawImage(videoElement, 0, 0, canvasElement.width, canvasElement.height);
  8.  
  9.                 var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
  10.                 var code = jsQR(imageData.data, canvasElement.width, canvasElement.height, {
  11.                     inversionAttempts: "dontInvert"
  12.                 });
  13.                 if (code && !scanned) {
  14.                     scanned = true;
  15.                     console.log(code);
  16.                     drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58");
  17.                     drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58");
  18.                     drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58");
  19.                     drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58");
  20.                     // console.log(code);
  21.                     // search for a macaddress
  22.                     var content = code.data;
  23.                     var params = content.split('/');
  24.                     var macaddr = false, key = false;
  25.  
  26.                     for (var k in params) {
  27.                         if (MACRegex.test(params[k])) {
  28.                             macaddr = params[k];
  29.                             console.log(macaddr)
  30.                         }
  31.                         if (KEYRegex.test(params[k])) {
  32.                             key = params[k];
  33.                             console.log(key)
  34.                         }
  35.                     }
  36.  
  37.                     if (macaddr && key) {
  38.                         // Hide the camera
  39.                         console.log("initDiGIdotScanner - 7");
  40.                         canvasElement.hidden = true;
  41.                         console.log("initDiGIdotScanner - 8");
  42.  
  43.                         var alreadyScanned = false;
  44.                         $('.macaddress').each(function () {
  45.                             console.log($(this).text(), macaddr);
  46.                             if ($(this).text() == macaddr) {
  47.                                 alreadyScanned = true;
  48.                             }
  49.                         });
  50.                         if (!alreadyScanned) {
  51.                             videoElement.pause();
  52.                             canvasElement.hidden = true;
  53.                             $('#registered-devices').before('<div class="scan-loader"><i class="c4-loader"></i><br>Getting information of device: ' + macaddr + '  </div>');
  54.                             lookupMyDevice(macaddr, key, function (resultLookup) {
  55.                                 //console.log('lookup finised')
  56.                                 console.log("initDiGIdotScanner - 9");
  57.                                 if (resultLookup.have_products) {
  58.                                     // if auto register is checked
  59.                                     console.log("initDiGIdotScanner - 10");
  60.                                     scannedProduct = resultLookup;
  61.  
  62.                                     if ($('[data-id="autoRegisterScanResults"]').is(':checked')) {
  63.                                         console.log("initDiGIdotScanner - 11");
  64.                                         saveNewDevice(resultLookup.products, function (result) {
  65.                                             console.log("initDiGIdotScanner - 12");
  66.                                             if (result['result'] == "OK") {
  67.                                                 addNewRegisterProduct(result);
  68.                                                 console.log("initDiGIdotScanner - 13");
  69.                                                 digidotScannerStart(); //restart the camera for a new scan
  70.                                             }
  71.                                             else {
  72.                                                 $('.scan-loader').remove();
  73.                                                 $('.no-device-registerd').remove();
  74.                                                 digidotScannerStart(); //restart the camera for a new scan
  75.                                                 alert("Failed to save to my devices..");
  76.                                                 console.log("initDiGIdotScanner - 14");
  77.                                             }
  78.                                         });
  79.                                     } else {
  80.                                         console.log("initDiGIdotScanner - 15");
  81.                                         resultLookup['macaddr'] = macaddr;
  82.                                         $('.scan-loader').remove();
  83.                                         $('.no-device-registerd').remove();
  84.                                         digidot_devicelist_results(resultLookup); // Show result and the registration button
  85.                                     }
  86.                                 }
  87.                             });
  88.                         } else {
  89.                             alert("This product is already scanned");
  90.                             stopCamera();
  91.                             scannerInit = false;
  92.                             digidotScannerStart();//restart the camera for a new scan
  93.                         }
  94.                     } else {
  95.                         console.log("initDiGIdotScanner - 5");
  96.                         if (!macaddr) {
  97.                             $('.search-device-container').before('<span class="error">No valid mac address found</div>');
  98.                         }
  99.                         if (!key) {
  100.                             $('.search-device-container').before('<span class="error">No valid key found</div>');
  101.                         }
  102.                     }
  103.                 }
  104.             }
  105.             requestAnimationFrame(tick);
  106.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement