Merge pull request #6985 from gustavotrott/ios-webcam-list-problem

Change webcam resolution to 640x480 if using iOS
This commit is contained in:
Anton Georgiev 2019-03-11 16:11:58 -04:00 committed by GitHub
commit c0c4ce77c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,14 +156,9 @@ class VideoPreview extends Component {
const webcams = [];
// set webcam
if (webcamDeviceId) {
changeWebcam(webcamDeviceId);
this.setState({ webcamDeviceId });
isInitialDeviceSet = true;
}
devices.forEach((device) => {
if (device.kind === 'videoinput') {
if (!isInitialDeviceSet) {
if (!isInitialDeviceSet || (webcamDeviceId && webcamDeviceId === device.deviceId)) {
changeWebcam(device.deviceId);
this.setState({ webcamDeviceId: device.deviceId });
isInitialDeviceSet = true;
@ -175,6 +170,14 @@ class VideoPreview extends Component {
}
constraints.video.deviceId = { exact: this.state.webcamDeviceId };
const iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
if (iOS) {
constraints.video.width = { max: 640 };
constraints.video.height = { max: 480 };
}
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
// display the preview
this.video.srcObject = stream;