There's no reliable way of determining if a device has both front and back cameras.
The MediaStream API supports the method navigator.mediaDevices.enumerateDevices(), which returns a Promise object that must be resolved. Once resolved, an array of MediaDeviceInfo objects is obtained, containing data about all the devices in the system. However, this information is highly dependent on the device itself and on the user agent implementation of the API. The only clue we have to know if a device is a camera is the 'kind' property in the MediaDeviceInfo object, which can have a value of 'videoinput':
https://w3c.github.io/mediacapture-main/getusermedia.html#dom-mediadevicekind-videoinput
In the tests I made I found that there's no other information given about whether it's actually a camera or some other type of video input or about the location of this camera, which could simply be an additional, external webcam.
The algorithm would consist of simply checking to see if there are at least two 'videoinput' devices for rendering the toggle button, but as mentioned above, there's no reliable way of knowing if the device actually has both front and back cameras.
I guess it would work in most cases, and in some cases the button would be rendered even if there are no front and back cameras, but simply an integrated and an external camera.
Another way of approaching this is to avoid rendering this button if there's only one 'videoinput' device.
Judy notes:
.