It statred with a simple tweet:
Get the first camera that is front-facing #javascript GUM.
— Hemanth.HM (@GNUmanth) September 8, 2018
Better with `?.deviceId` pic.twitter.com/1sBcP5CZjz
@_zouhir suggested facingMode
Which has the below mods:
"user": The video source is facing toward the user; this includes, for example, the front-facing camera on a smartphone.
"environment": The video source is facing away from the user, thereby viewing their environment. This is the back camera on a smartphone.
"left": The video source is facing toward the user but to their left, such as a camera aimed toward the user but over their left shoulder.
"right": The video source is facing toward the user but to their right, such as a camera aimed toward the user but over their right shoulder.
Here is some simple code to flip cameras:
Check if the browser supports facingMODE
1 2 3 4 |
|
Set options for the getUserMedia
1 2 3 4 5 6 7 8 |
|
Stream the video:
1 2 3 4 5 |
|
Toggle cams:
1 2 3 4 5 6 7 8 |
|
Demo: