Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
93134cd9
Commit
93134cd9
authored
4 years ago
by
Reiter, Christoph
Browse files
Options
Downloads
Patches
Plain Diff
Add qr-scanner as an alternative backend
parent
8fcc4b0d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Checking pipeline status
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/qr-code-scanner/rollup.config.js
+1
-0
1 addition, 0 deletions
packages/qr-code-scanner/rollup.config.js
packages/qr-code-scanner/src/qr-code-scanner.js
+42
-5
42 additions, 5 deletions
packages/qr-code-scanner/src/qr-code-scanner.js
with
43 additions
and
5 deletions
packages/qr-code-scanner/rollup.config.js
+
1
−
0
View file @
93134cd9
...
...
@@ -72,6 +72,7 @@ export default (async () => {
{
src
:
'
assets/index.html
'
,
dest
:
'
dist
'
},
{
src
:
'
assets/favicon.ico
'
,
dest
:
'
dist
'
},
{
src
:
await
getPackagePath
(
'
dbp-common
'
,
'
assets/icons/*.svg
'
),
dest
:
'
dist/local/dbp-common/icons
'
},
{
src
:
await
getPackagePath
(
'
qr-scanner
'
,
'
qr-scanner-worker.*
'
),
dest
:
'
dist/local/qr-code-scanner
'
},
]
}),
(
process
.
env
.
ROLLUP_WATCH
===
'
true
'
)
?
serve
({
...
...
This diff is collapsed.
Click to expand it.
packages/qr-code-scanner/src/qr-code-scanner.js
+
42
−
5
View file @
93134cd9
...
...
@@ -5,9 +5,11 @@ import * as commonStyles from 'dbp-common/styles';
import
{
ScopedElementsMixin
}
from
'
@open-wc/scoped-elements
'
;
import
{
Icon
,
MiniSpinner
}
from
'
dbp-common
'
;
import
{
classMap
}
from
'
lit-html/directives/class-map.js
'
;
import
*
as
commonUtils
from
'
dbp-common/utils
'
;
import
jsQR
from
"
jsqr
"
;
import
{
getIconSVGURL
}
from
'
dbp-common
'
;
import
{
Mutex
}
from
'
async-mutex
'
;
import
QrScanner
from
'
qr-scanner
'
;
/**
...
...
@@ -98,6 +100,42 @@ async function createVideoElement(deviceId) {
}
class
jsQRScanner
{
// eslint-disable-line no-unused-vars
constructor
()
{
}
async
scan
(
canvas
,
x
,
y
,
width
,
height
)
{
let
imageData
=
canvas
.
getContext
(
"
2d
"
).
getImageData
(
x
,
y
,
width
,
height
);
const
code
=
jsQR
(
imageData
.
data
,
imageData
.
width
,
imageData
.
height
,
{
inversionAttempts
:
"
dontInvert
"
,
});
if
(
code
===
null
)
return
null
;
return
{
'
data
'
:
code
.
data
};
}
}
class
QRScanner
{
constructor
()
{
QrScanner
.
WORKER_PATH
=
commonUtils
.
getAssetURL
(
'
qr-code-scanner
'
,
'
qr-scanner-worker.min.js
'
);
this
.
_engine
=
null
;
this
.
_canvas
=
document
.
createElement
(
"
canvas
"
);
}
async
scan
(
canvas
,
x
,
y
,
width
,
height
)
{
if
(
this
.
_engine
===
null
)
{
this
.
_engine
=
await
QrScanner
.
createQrEngine
(
QrScanner
.
WORKER_PATH
);
}
try
{
return
{
data
:
await
QrScanner
.
scanImage
(
canvas
,
{
x
:
x
,
y
:
y
,
width
:
width
,
height
:
height
},
this
.
_engine
,
this
.
_canvas
)};
}
catch
(
e
)
{
return
null
;
}
}
}
export
class
QrCodeScanner
extends
ScopedElementsMixin
(
DBPLitElement
)
{
constructor
()
{
super
();
...
...
@@ -214,7 +252,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
let
lastCode
=
null
;
let
lastSentData
=
null
;
const
tick
=
()
=>
{
let
detector
=
new
QRScanner
();
const
tick
=
async
()
=>
{
this
.
_requestID
=
null
;
if
(
video
.
readyState
===
video
.
HAVE_ENOUGH_DATA
)
{
this
.
_loading
=
false
;
...
...
@@ -242,10 +282,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
let
shouldAnalyze
=
Math
.
abs
(
lastVideoScanTime
-
video
.
currentTime
)
>=
1
/
3
;
if
(
shouldAnalyze
)
{
lastVideoScanTime
=
video
.
currentTime
;
let
imageData
=
canvas
.
getImageData
(
maskStartX
,
maskStartY
,
maskWidth
,
maskHeight
);
code
=
jsQR
(
imageData
.
data
,
imageData
.
width
,
imageData
.
height
,
{
inversionAttempts
:
"
dontInvert
"
,
});
code
=
await
detector
.
scan
(
canvasElement
,
maskStartX
,
maskStartY
,
maskWidth
,
maskHeight
);
lastCode
=
code
;
}
else
{
code
=
lastCode
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment