fix: add pending browser permission state #1718
Merged
+129
−45
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.
Overview
Previously there was no way to track if the SDK is currently prompting browser for a device permission. For example:
hasBrowserPermission
is true forprompt
state, andoptimisticStatus
isenabled
).We now introduce another permission state apart from
prompt
,granted
anddenied
:prompting
. This state is in effect while browser prompt is visible, i.e. when permission state isprompt
andgetUserMedia
promise is pending.Implementation notes
New browser permission state
prompting
is added toBrowserPermission
class.This state is exposed via the
isPermissionPending$
observable in input media device manager state.State hooks for camera and microphone state also return this flag.
Default device toggles support this flag and display the new "?" badge while permission is pending:
Docs are to follow.
There are also two other minor changes in this PR.
The
settled()
check in concurrency.ts is fixed to prevent possible race conditions. Previously, it was possible to check forsettled()
, then add more promises to the queue, andsettled()
will resolve before these newly added promises are resolved.isTogglePending
flag is returned from device-related call state hooks. It can be used to display a loader while camera/microphone are enabled/disabled. It's not used by our default toggle buttons, but it's nice to have.