Last active
September 19, 2021 22:52
-
-
Save BrianLi101/224a591ff7459d09bb8a21612e9ec95f to your computer and use it in GitHub Desktop.
mic-check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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