|
1 | 1 | import { iframeStyles } from "../styles/styles"; |
2 | | -import {verificationUrl} from "../helpers/defaultConfig"; |
3 | 2 |
|
4 | 3 | import {ORBA_ONE_MESSAGE_CHANNEL,ORBA_ONE_SUCCESS,ORBA_ONE_CANCEL} from "./constants"; |
5 | 4 |
|
6 | 5 | type State = "loading" | "success" | "error" | "idle"; |
7 | 6 |
|
8 | 7 | export function createIframe( |
9 | 8 | url: string, |
| 9 | + applicantId: string, |
10 | 10 | onSuccess: (...args) => void, |
11 | 11 | onCancelled: (...args) => void, |
12 | 12 | onError: (...args) => void, |
13 | 13 | onChange: (state: State) => void, |
14 | 14 | ) { |
15 | 15 | const frame = document.createElement("iframe"); |
16 | | - frame.allow = "geolocation; microphone; camera"; |
| 16 | + frame.allow = "geolocation; microphone; camera; fullscreen;"; |
17 | 17 | frame.src = url; |
18 | 18 | frame.setAttribute("style", iframeStyles); |
19 | 19 |
|
20 | 20 | //Set Test Id for DOM checking |
21 | 21 | frame.dataset.testid = "orba-iframe"; |
22 | | - return iframeManager(frame, onSuccess, onCancelled, onError, onChange); |
| 22 | + return iframeManager(frame, applicantId, onSuccess, onCancelled, onError, onChange); |
23 | 23 | } |
24 | 24 |
|
25 | 25 | export function iframeManager( |
26 | 26 | iframe: HTMLIFrameElement, |
| 27 | + applicantId, |
27 | 28 | onSuccess: (...args) => void, |
28 | 29 | onCancelled: (...args) => void, |
29 | 30 | onError: (...args) => void, |
@@ -52,18 +53,14 @@ export function iframeManager( |
52 | 53 | } |
53 | 54 |
|
54 | 55 | function handler(event: any) { |
55 | | - console.log(event) |
56 | | - if (event.origin != verificationUrl) { |
57 | | - const json = JSON.parse(event.data) |
58 | | - if (json.status === ORBA_ONE_SUCCESS) { |
59 | | - onSuccess(json); |
60 | | - disconnect(); |
61 | | - } else if (json.status === ORBA_ONE_CANCEL) { |
62 | | - onCancelled(json); |
63 | | - disconnect(); |
64 | | - } else { |
65 | | - onError(json); |
66 | | - } |
| 56 | + if (event.data === ORBA_ONE_SUCCESS) { |
| 57 | + onSuccess({applicantId, status:"success"}); |
| 58 | + disconnect(); |
| 59 | + } else if (event.data === ORBA_ONE_CANCEL) { |
| 60 | + onCancelled({applicantId, status:"cancelled"}); |
| 61 | + disconnect(); |
| 62 | + } else { |
| 63 | + onError({applicantId, status:"error"}); |
67 | 64 | } |
68 | 65 |
|
69 | 66 | } |
|
0 commit comments