I found this code on GitHub. I tested it on android and it doesn't seem to work. The camera output isn't always displayed (out of the 4 times I tried it it only worked once.) and the "front" and "back" buttons don't work. Only the front facing camera is displayed, the "back" button doesn't dislpay the back camera.
Here's the code:
<button onclick="stop();gum('user')">Front</button>
<button onclick="stop();gum('environment')">Back</button>
<div id="div"></div><br>
<video id="video" height="320" autoplay></video>
<script type="text/javascript">
var gum = mode =>
navigator.mediaDevices.getUserMedia({video: {facingMode: {exact: mode}}})
.then(stream => (video.srcObject = stream))
.catch(e => log(e));
var stop = () => video.srcObject && video.srcObject.getTracks().forEach(t => t.stop());
var log = msg => div.innerHTML += msg + "<br>";
</script>
Thank you for your help.