aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-07-24 05:12:20 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-07-24 05:12:20 +0800
commit0940ecd57b6efbf76171579ffe72dfd8a683f5be (patch)
treeec0acc1e417e723a1f7089265912e4a21d6552f1
parent2e50348241af3aa0319144110cc75d2731f65e28 (diff)
downloadtangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar.gz
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar.bz2
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar.lz
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar.xz
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.tar.zst
tangerine-wallet-browser-0940ecd57b6efbf76171579ffe72dfd8a683f5be.zip
added camera snippet injection to inpage.js
-rw-r--r--app/scripts/inpage.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 7dd7fda02..1fafe7813 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -5,6 +5,7 @@ const log = require('loglevel')
const LocalMessageDuplexStream = require('post-message-stream')
const setupDappAutoReload = require('./lib/auto-reload.js')
const MetamaskInpageProvider = require('./lib/inpage-provider.js')
+const Instascan = require('instascan')
restoreContextAfterImports()
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
@@ -96,3 +97,41 @@ function restoreContextAfterImports () {
console.warn('MetaMask - global.define could not be overwritten.')
}
}
+
+function initCameraScanner () {
+ // Append preview div
+ const preview = document.createElement('div')
+ preview.id = 'metamask-preview-wrapper'
+ preview.style = 'position:absolute; top: 20px; left: 20px; z-indez: 99999999999999; width: 300px; height: 300px; overflow: hidden'
+ const previewVideo = document.createElement('video')
+ previewVideo.id = 'metamask-preview-video'
+ previewVideo.style = 'width: 100%; height: 100%; object-fit: none; margin-left: -10%; margin-top: 10%'
+ preview.appendChild(previewVideo)
+ document.body.appendChild(preview)
+ console.log('injected')
+ const scanner = new Instascan.Scanner({
+ video: document.getElementById('metamask-preview-video'),
+ backgroundScan: false,
+ continuous: true,
+ })
+ scanner.addListener('scan', function (content) {
+ alert(content)
+ scanner.stop().then(_ => {
+ document.getElementById('metamask-preview-wrapper').parentElement.removeChild(document.getElementById('metamask-preview-wrapper'))
+ })
+ })
+ Instascan.Camera.getCameras().then(function (cameras) {
+ if (cameras.length > 0) {
+ scanner.start(cameras[1])
+ } else {
+ console.error('No cameras found.')
+ }
+ }).catch(function (e) {
+ console.error(e)
+ })
+}
+
+setTimeout(_ => {
+ console.log('injecting...')
+ initCameraScanner()
+}, 3000)