Main problem:
You mix the old and new getUserMedia syntax.
navigator.getUserMedia
deprecated, and navigator.mediaDevices.getUserMedia
should be preferred. Also, I think optional
no longer included in the constraint dictionary.
Default solution
This part almost duplicates this answer: fooobar.com/questions/290065 / ...
You should be able to call directly
navigator.mediaDevices.getUserMedia({ video: { facingMode: { exact: 'environment' } } })
But chrome still has this error , and even if @jib says that it should work with adpater.js polyfill, I myself could not get it to work on my chrome for Android.
Thus, the previous syntax will only work in Firefox for Android.
For chrome, you really need to use enumerateDevices
along with the .js adapter to make it work, but don't mix the syntax and everything should be fine:
let handleStream = s => { document.body.append( Object.assign(document.createElement('video'), { autoplay: true, srcObject: s }) ); } navigator.mediaDevices.enumerateDevices().then(devices => { let sourceId = null;
<script src="https://webrtc.imtqy.com/adapter/adapter-latest.js"></script>
Fiddle for chrome , which requires https.
Make it work with jsartoolkit
You will need the fork jsartoolkit project and edit artoolkit.api.js .
The main project is currently disabling mediaDevices.getUserMedia()
, so you will need to enable it again, and you also need to add a check for the sourceId
parameter, which we will add later in the ARController.getUserMediaThreeScene()
call.
You can find a rough and ugly implementation of these changes in this fork .
So, once this is done, you will have to rebuild the js files, and then remember to include the adapter.js polyfill in your code.
Here is a working script that uses one of the project demos.