mobstac-private / tqrcg-barcode.js

Javascript QR Code library
Apache License 2.0
49 stars 9 forks source link

MediaStreamTrack.getSources() Deprecated #13

Closed dsanders11 closed 6 years ago

dsanders11 commented 8 years ago

According to Chrome MediaStreamTrack.getSources() is deprecated and will be removed in Chrome 56 (currently in dev channel, so coming around December or January).

Since the only current use of that function is to find any environment facing cameras and set a preference for it, this code could be replaced entirely by using constraints. The newer format would simply be {facingMode: 'environment'} to express optional preference for environment facing cameras.

While making this change it would also be useful to plumb down additional constraints through ContinuousScanner. I've implemented this as looking for a videoConstraints key in the options for ContinuousScanner and passing it to LocalVideoCapturer which now takes an optional constraints object.

Plumbing through additional constraints is very useful for multi-camera environments. I have a setup with two cameras and allow the user to set a preference (saved to LocalStorage). I can enforce this preference by providing {deviceId: {exact: "foobar"}} as an additional constraint and it works great.

Schibum commented 7 years ago

Sounds great, PR welcome :)

dsanders11 commented 7 years ago

Now that Chrome 55 has landed the deprecation notice has been updated to specify Chrome 56 will remove the feature likely in January 2017.

Unfortunately switching to just the {facingMode: 'environment'} constraint doesn't work well with Android as facingMode is currently broken there.

The code could be switched to use MediaDevices.enumerateDevices() which is the spiritual successor of MediaStreamTrack.getSources(), but compatibility is unclear. Testing on desktop, it appears to be usable for Chrome, Firefox, and Opera. I can only test Chrome Android and it appears to be accessible there as well.

I'll work on a pull request with that functionality.