[#1318] Actual 1/2: Enable “Scan QR” button only if camera available #1732
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1318.
tl;dr The actual feature work
NOTICE: This PR depends on #1730 and #1731 to be merged so defer review till then plz.
The #1318 Pull Request stack
What's this commit about?
The main feature finally. Basically, once the Private Key Login tab is clicked, the "Scan QR" button isn't enabled until a camera source is found (not "active" but rather "available" in the OS).
This enhancement to
LoginPrivateKey
is implemented with an HOCwithCameraAvailability
which adds a propcameraAvailable
to the wrapped component and automatically toggles the boolean value according to actual camera availability.The availability is determined depending on
navigator.mediaDevices.enumerateDevices()
. This required updating Flow's BOM declarations (this browser feature isn't yet supported in IE 😪...)The listener is implemented with the
util/poll.js
polling mechanism. When the state of availability changes (for instance, a usb camera was connected), the polling ends, and another is set listening to the opposite value (when the camera is disconnected). Eventually, polling is stopped when component is unmounted.LETS SEE IT IN ACTION