From a016f8b05a6ee18362084184afa0398945fa83aa Mon Sep 17 00:00:00 2001 From: JoseCDB Date: Mon, 11 Dec 2017 10:23:36 +0100 Subject: [PATCH] Update camera.js Some changes to start the camera with the rear camera if we are using Safari. --- src/camera.js | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/camera.js b/src/camera.js index 5403b3ca..4dab51e3 100644 --- a/src/camera.js +++ b/src/camera.js @@ -16,20 +16,40 @@ class Camera { this.name = name; this._stream = null; } - + + async start() { - let constraints = { - audio: false, - video: { - mandatory: { - sourceId: this.id, - minWidth: 600, - maxWidth: 800, - minAspectRatio: 1.6 - }, - optional: [] - } - }; + let constraints; + var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; + + if (iOS) { + constraints = { + audio: false, + video: { + facingMode: 'environment', + mandatory: { + sourceId: this.id, + minWidth: 600, + maxWidth: 800, + minAspectRatio: 1.6 + }, + optional: [] + } + }; + } else { + constraints = { + audio: false, + video: { + mandatory: { + sourceId: this.id, + minWidth: 600, + maxWidth: 800, + minAspectRatio: 1.6 + }, + optional: [] + } + }; + } this._stream = await Camera._wrapErrors(async () => { return await navigator.mediaDevices.getUserMedia(constraints);