Skip to content

Commit

Permalink
Fix initial camera permission not set to agent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ayinloya committed Aug 23, 2024
1 parent 6b1313d commit 333fe08
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import SmartCamera from '../../../domain/camera/src/SmartCamera';
import styles from '../../../styles/src/styles';
import { version as COMPONENTS_VERSION } from '../../../package.json';

async function getPermissions(captureScreen) {
async function getPermissions(captureScreen, facingMode = 'user') {
try {
await SmartCamera.getMedia({ audio: false, video: true });
await SmartCamera.getMedia({ audio: false, video: { facingMode } });
captureScreen.removeAttribute('data-camera-error');
captureScreen.setAttribute('data-camera-ready', true);
} catch (error) {
Expand Down Expand Up @@ -47,11 +47,11 @@ class SelfieCaptureScreens extends HTMLElement {
this.selfieReview = this.querySelector('selfie-capture-review');

if (this.hideInstructions && !this.hasAttribute('hidden')) {
getPermissions(this.selfieCapture);
getPermissions(this.selfieCapture, this.getAgentMode());
}

if (this.getAttribute('initial-screen') === 'selfie-capture') {
getPermissions(this.selfieCapture);
getPermissions(this.selfieCapture, this.getAgentMode());
this.setActiveScreen(this.selfieCapture);
} else if (this.hideInstructions) {
this.setActiveScreen(this.selfieCapture);
Expand All @@ -62,6 +62,10 @@ class SelfieCaptureScreens extends HTMLElement {
this.setUpEventListeners();
}

getAgentMode() {
return this.inAgentMode ? 'environment' : 'user';
}

disconnectedCallback() {
SmartCamera.stopMedia();
if (this.activeScreen) {
Expand All @@ -75,7 +79,7 @@ class SelfieCaptureScreens extends HTMLElement {
this.selfieInstruction.addEventListener(
'selfie-capture-instructions.capture',
async () => {
await getPermissions(this.selfieCapture);
await getPermissions(this.selfieCapture, this.getAgentMode());
this.setActiveScreen(this.selfieCapture);
},
);
Expand Down Expand Up @@ -119,7 +123,7 @@ class SelfieCaptureScreens extends HTMLElement {
this._data.images = [];
if (this.hideInstructions) {
this.setActiveScreen(this.selfieCapture);
await getPermissions(this.selfieCapture);
await getPermissions(this.selfieCapture, this.getAgentMode());
} else {
this.setActiveScreen(this.selfieInstruction);
}
Expand Down Expand Up @@ -167,6 +171,10 @@ class SelfieCaptureScreens extends HTMLElement {
return this.hasAttribute('show-navigation') ? 'show-navigation' : '';
}

get inAgentMode() {
return this.getAttribute('allow-agent-mode') === 'true';
}

get allowAgentMode() {
return this.hasAttribute('allow-agent-mode')
? "allow-agent-mode='true'"
Expand Down

0 comments on commit 333fe08

Please sign in to comment.