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
628c5025
Commit
628c5025
authored
4 years ago
by
Reiter, Christoph
Browse files
Options
Downloads
Patches
Plain Diff
Move the video element creation into its own function
parent
4bd285dc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/qr-code-scanner/src/qr-code-scanner.js
+40
-29
40 additions, 29 deletions
packages/qr-code-scanner/src/qr-code-scanner.js
with
40 additions
and
29 deletions
packages/qr-code-scanner/src/qr-code-scanner.js
+
40
−
29
View file @
628c5025
...
@@ -63,6 +63,38 @@ async function getVideoDevices() {
...
@@ -63,6 +63,38 @@ async function getVideoDevices() {
}
}
}
}
/**
* @param {string} deviceId
* @returns {object|null} a video element or null
*/
async
function
createVideoElement
(
deviceId
)
{
let
videoId
=
deviceId
;
let
constraint
=
{
video
:
{
deviceId
:
videoId
}
};
if
(
(
videoId
===
'
environment
'
||
videoId
===
''
)
)
{
console
.
log
(
"
vid:
"
,
videoId
);
constraint
=
{
video
:
{
facingMode
:
"
environment
"
}
};
}
else
if
(
videoId
===
'
user
'
)
{
console
.
log
(
"
vid2:
"
,
videoId
);
constraint
=
{
video
:
{
facingMode
:
"
user
"
}
};
}
let
stream
=
null
;
try
{
stream
=
await
navigator
.
mediaDevices
.
getUserMedia
(
constraint
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
if
(
stream
!==
null
)
{
let
video
=
document
.
createElement
(
"
video
"
);
video
.
srcObject
=
stream
;
return
video
;
}
return
null
;
}
/**
/**
* Notification web component
* Notification web component
...
@@ -164,45 +196,21 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -164,45 +196,21 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this
.
stopScanning
();
this
.
stopScanning
();
this
.
stopScan
=
false
;
this
.
stopScan
=
false
;
this
.
_askPermission
=
true
;
let
video
=
document
.
createElement
(
"
video
"
);
let
canvasElement
=
this
.
_
(
"
#canvas
"
);
let
canvasElement
=
this
.
_
(
"
#canvas
"
);
let
qrContainer
=
this
.
_
(
"
#qr
"
);
let
qrContainer
=
this
.
_
(
"
#qr
"
);
let
scroll
=
false
;
let
scroll
=
false
;
let
okColor
=
getComputedStyle
(
this
).
getPropertyValue
(
'
--dbp-success-bg-color
'
);
this
.
_askPermission
=
true
;
let
notOkColor
=
getComputedStyle
(
this
).
getPropertyValue
(
'
--dbp-danger-bg-color
'
);
let
videoId
=
this
.
_activeCamera
;
let
constraint
=
{
video
:
{
deviceId
:
videoId
}
};
if
(
(
videoId
===
'
environment
'
||
videoId
===
''
)
)
{
console
.
log
(
"
vid:
"
,
videoId
);
constraint
=
{
video
:
{
facingMode
:
"
environment
"
}
};
}
else
if
(
videoId
===
'
user
'
)
{
console
.
log
(
"
vid2:
"
,
videoId
);
constraint
=
{
video
:
{
facingMode
:
"
user
"
}
};
}
let
stream
=
null
;
this
.
_loadingMessage
=
i18n
.
t
(
'
no-camera-access
'
);
this
.
_loadingMessage
=
i18n
.
t
(
'
no-camera-access
'
);
try
{
let
video
=
await
createVideoElement
(
this
.
_activeCamera
);
stream
=
await
navigator
.
mediaDevices
.
getUserMedia
(
constraint
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
this
.
_askPermission
=
false
;
this
.
_askPermission
=
false
;
if
(
stream
!==
null
)
{
if
(
video
!==
null
)
{
video
.
srcObject
=
stream
;
video
.
setAttribute
(
"
playsinline
"
,
true
);
// required to tell iOS safari we don't want fullscreen
video
.
setAttribute
(
"
playsinline
"
,
true
);
// required to tell iOS safari we don't want fullscreen
video
.
play
();
video
.
play
();
this
.
_videoRunning
=
true
;
this
.
_videoRunning
=
true
;
if
(
this
.
_requestID
!==
null
)
{
cancelAnimationFrame
(
this
.
_requestID
);
this
.
_requestID
=
null
;
}
console
.
assert
(
this
.
_requestID
===
null
);
console
.
assert
(
this
.
_requestID
===
null
);
this
.
_videoElement
=
video
;
this
.
_videoElement
=
video
;
this
.
_loading
=
true
;
this
.
_loading
=
true
;
...
@@ -264,10 +272,13 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -264,10 +272,13 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
canvas
.
fill
();
canvas
.
fill
();
canvas
.
beginPath
();
canvas
.
beginPath
();
if
(
code
)
if
(
code
)
{
let
okColor
=
getComputedStyle
(
that
).
getPropertyValue
(
'
--dbp-success-bg-color
'
);
let
notOkColor
=
getComputedStyle
(
that
).
getPropertyValue
(
'
--dbp-danger-bg-color
'
);
canvas
.
fillStyle
=
matched
?
okColor
:
notOkColor
;
canvas
.
fillStyle
=
matched
?
okColor
:
notOkColor
;
else
}
else
{
canvas
.
fillStyle
=
'
white
'
;
canvas
.
fillStyle
=
'
white
'
;
}
let
borderWidth
=
Math
.
max
(
maskWidth
,
maskHeight
)
/
50
;
let
borderWidth
=
Math
.
max
(
maskWidth
,
maskHeight
)
/
50
;
canvas
.
moveTo
(
maskStartX
,
maskStartY
);
canvas
.
moveTo
(
maskStartX
,
maskStartY
);
...
...
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