-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
132 lines (116 loc) · 3.2 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React, { Component } from 'react'
import {
StyleSheet,
Text,
View,
Button,
Alert,
SafeAreaView,
NativeEventEmitter
} from 'react-native'
import IProov from '@iproov/react-native'
import ApiClient, {
CLAIM_TYPE_ENROL,
ASSURANCE_TYPE_GENUINE_PRESENCE
} from './ApiClient.js'
import uuid from 'react-native-uuid'
import RNProgressHud from 'progress-hud'
import config from './credentials.js'
export default class App extends Component {
apiClient = new ApiClient(
'https://' + config.baseUrl + '/api/v2/',
config.apiKey,
config.secret
)
launchIProov = async () => {
RNProgressHud.showWithStatus('Getting token')
const response = await this.apiClient.getToken(
ASSURANCE_TYPE_GENUINE_PRESENCE,
CLAIM_TYPE_ENROL,
uuid.v4()
)
const body = await response.json()
RNProgressHud.dismiss()
if (!response.ok) {
Alert.alert('API Client Error', body.error_description)
return
}
var options = new IProov.Options()
options.enableScreenshots = true
const eventEmitter = new NativeEventEmitter(IProov.IProovReactNative)
IProov.launch('wss://' + config.baseUrl + '/ws', body.token, options, eventEmitter, (event) => {
switch (event.name) {
case IProov.EVENT_CONNECTING:
RNProgressHud.showWithStatus('Connecting')
break
case IProov.EVENT_CONNECTED:
RNProgressHud.dismiss()
break
case IProov.EVENT_PROCESSING:
RNProgressHud.showProgressWithStatus(
event.params.progress,
event.params.message
)
break
case IProov.EVENT_CANCELED:
RNProgressHud.showErrorWithStatus('Canceled by ' + event.params.canceler)
break
case IProov.EVENT_FAILURE:
RNProgressHud.showErrorWithStatus('Failed: ' + event.params.reason)
break
case IProov.EVENT_SUCCESS:
RNProgressHud.showSuccessWithStatus('Success')
break
case IProov.EVENT_ERROR:
RNProgressHud.showErrorWithStatus('Error: ' + event.params.reason)
break
}
})
}
render() {
return (
<View style={{ flex: 1 }}>
<SafeAreaView style={styles.container}>
<View style={styles.toolbar}>
<Text style={styles.welcome}>iProov Example</Text>
</View>
<View style={styles.contentContainer}>
<Button
onPress={this.launchIProov}
title="🚀 Launch"
color="#841584"
/>
</View>
</SafeAreaView>
{/* Change bottom safe area background color */}
<SafeAreaView style={{ flex: 1, backgroundColor: '#F5FCFF' }} />
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'column',
flex: 9,
backgroundColor: '#4998f2'
},
toolbar: {
flex: 1,
backgroundColor: '#4998f2',
justifyContent: 'center',
alignItems: 'center'
},
contentContainer: {
flex: 9,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
fontWeight: 'bold',
color: 'white'
}
})