Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer-companion
Commits
2444e9d3
Unverified
Commit
2444e9d3
authored
Oct 25, 2021
by
Andrei Eres
Committed by
GitHub
Oct 25, 2021
Browse files
Fix camera access checking in firefox (#84)
parent
098505cc
Pipeline
#163512
passed with stages
in 1 minute and 10 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/utils/checkCameraAccess.ts
View file @
2444e9d3
...
...
@@ -3,7 +3,32 @@ export async function checkCameraAccess() {
const
permission
=
await
navigator
.
permissions
.
query
({
name
:
'
camera
'
as
PermissionName
,
})
return
permission
.
state
==
'
granted
'
return
permission
.
state
===
'
granted
'
}
catch
(
error
)
{
// Firefox can't query 'camera' permission
if
(
isCameraPermissionDescriptorError
(
error
as
Error
))
{
return
await
checkIfVideoDeviceHasLabel
()
}
console
.
error
(
error
)
return
false
}
}
function
isCameraPermissionDescriptorError
(
error
:
Error
)
{
return
(
(
error
as
Error
).
name
===
'
TypeError
'
&&
(
error
as
Error
).
message
.
startsWith
(
"
'camera'
"
)
)
}
// For security reasons, the `label` field is always blank
// unless the user has granted persistent permission for media device access
// @see: https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo
async
function
checkIfVideoDeviceHasLabel
()
{
try
{
const
devices
=
await
navigator
.
mediaDevices
.
enumerateDevices
()
return
devices
.
some
((
d
)
=>
d
.
kind
===
'
videoinput
'
&&
d
.
label
)
}
catch
(
error
)
{
console
.
error
(
error
)
return
false
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment