Skip to content

Instantly share code, notes, and snippets.

@BrianLi101
Last active September 19, 2021 22:52
Show Gist options
  • Save BrianLi101/224a591ff7459d09bb8a21612e9ec95f to your computer and use it in GitHub Desktop.
Save BrianLi101/224a591ff7459d09bb8a21612e9ec95f to your computer and use it in GitHub Desktop.
mic-check
import {
MediaPermissionsError
MediaPermissionsErrorType,
requestMediaPermissions
} from 'mic-check';
requestMediaPermissions()
.then(() => {
// can successfully access camera and microphone streams
// DO SOMETHING HERE
})
.catch((err: MediaPermissionsError) => {
const { type, name, message } = err;
if (type === MediaPermissionsErrorType.SystemPermissionDenied) {
// browser does not have permission to access camera or microphone
} else if (type === MediaPermissionsErrorType.UserPermissionDenied) {
// user didn't allow app to access camera or microphone
} else if (type === MediaPermissionsErrorType.CouldNotStartVideoSource) {
// camera is in use by another application (Zoom, Skype) or browser tab (Google Meet, Messenger Video)
// (mostly Windows specific problem)
} else {
// not all error types are handled by this library
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment