Skip to content

Commit

Permalink
Show a modal when it cannot access the microphone
Browse files Browse the repository at this point in the history
refs: #3
  • Loading branch information
alexjpaz committed Dec 31, 2019
1 parent a44ce0b commit 0437c13
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/components/Permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Modal from '@material-ui/core/Modal';
import Backdrop from '@material-ui/core/Backdrop';
import Fade from '@material-ui/core/Fade';
import Typography from '@material-ui/core/Typography';

const useStyles = makeStyles(theme => ({
modal: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
paper: {
backgroundColor: theme.palette.background.paper,
border: '2px solid #000',
boxShadow: theme.shadows[5],
padding: theme.spacing(2, 4, 3),
},
}));

export default function TransitionsModal() {
const classes = useStyles();
const [open, setOpen] = React.useState(false);

React.useEffect(() => {
if(!navigator || !navigator.mediaDevices) {
console.warn("Could not detect media devices. This may be because the application was not loaded over a secure context (e.g. https). https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Security");
setOpen(true);

return;
}

navigator.mediaDevices.getUserMedia({ audio: true })
.then(() => {
setOpen(false);
})
.catch(() => {
setOpen(true);
})
;

return () => {};
});

const handleOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

return (
<div>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
className={classes.modal}
open={open}
onClose={handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={open}>
<div className={classes.paper}>
<Typography variant="h5">
This application requires access to your microphone.
</Typography>
<Typography variant="body1">

</Typography>
</div>
</Fade>
</Modal>
</div>
);
}
3 changes: 3 additions & 0 deletions src/components/layout/AppViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';

import Box from '@material-ui/core/Box';

import Permissions from '../Permissions';

import TopBar from './TopBar';

import MyBox from '../MyBox/MyBox';
Expand All @@ -11,6 +13,7 @@ export default function AppViewport() {
<Box height="100%">
<TopBar />
<MyBox />
<Permissions />
</Box>
);
};

0 comments on commit 0437c13

Please sign in to comment.