-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add enroll/authenticate example
- Loading branch information
Showing
6 changed files
with
111 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,4 @@ buck-out/ | |
ZoomAuthenticationHybrid.framework | ||
app-token.json | ||
license-key.json | ||
device-key-identifier.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,130 @@ | ||
import React from "react"; | ||
import React from 'react' | ||
import { | ||
Platform, | ||
TouchableHighlight, | ||
StyleSheet, | ||
ScrollView, | ||
View, | ||
Text, | ||
Image | ||
} from "react-native"; | ||
Image, | ||
} from 'react-native' | ||
|
||
import Zoom from "react-native-facetec-zoom"; | ||
import ZOOM_APP_TOKEN from "./license-key"; | ||
import Zoom from 'react-native-facetec-zoom' | ||
import deviceKeyIdentifier from './device-key-identifier' | ||
|
||
Zoom.preload(); | ||
const BigText = ({ children, style }) => <Text style={[styles.bigText, style]}>{children}</Text> | ||
|
||
const bigText = (text, style) => ( | ||
<Text style={[styles.bigText, style]}>{text}</Text> | ||
); | ||
const hugeText = (text, style) => ( | ||
<Text style={[styles.hugeText, style]}>{text}</Text> | ||
); | ||
const createButton = ({ text, ...props }) => ( | ||
const Button = ({ children, ...props }) => ( | ||
<TouchableHighlight {...props} style={styles.button}> | ||
{hugeText(text, styles.buttonText)} | ||
<Text style={[styles.hugeText, styles.buttonText]}>{children}</Text> | ||
</TouchableHighlight> | ||
); | ||
) | ||
|
||
const prettify = obj => (obj ? JSON.stringify(obj, null, 2) : ""); | ||
const prettify = (obj) => (obj ? JSON.stringify(obj, null, 2) : '') | ||
// don't actually do this | ||
const getFaceID = () => String(Math.random()).split('.')[1] | ||
|
||
export default class App extends React.Component { | ||
state = {}; | ||
verifyLiveness = async () => { | ||
state = {} | ||
init = async () => { | ||
const { success, status } = await Zoom.initialize({ | ||
appToken: ZOOM_APP_TOKEN, | ||
deviceKeyIdentifier, | ||
showPreEnrollmentScreen: false, | ||
showUserLockedScreen: false, | ||
showRetryScreen: false, | ||
topMargin: 200, | ||
// sizeRatio: 0.7, | ||
centerFrame: false | ||
}); | ||
centerFrame: false, | ||
returnBase64: false, | ||
}) | ||
|
||
if (!success) { | ||
// see constants.js SDKStatus for explanations of various | ||
// reasons why initialize might not have gone through | ||
throw new Error(`failed to init. SDK status: ${status}`); | ||
throw new Error(`failed to init. SDK status: ${status}`) | ||
} | ||
|
||
this.initialized = true | ||
} | ||
|
||
enroll = async () => { | ||
if (!this.initialized) await this.init() | ||
|
||
const faceID = getFaceID() | ||
this.setState({ faceID }) | ||
|
||
// launch Zoom's enrollment process | ||
return Zoom.enroll({ | ||
id: faceID, | ||
}).then(this.setResult, this.setError) | ||
} | ||
|
||
authenticate = async () => { | ||
if (!this.initialized) await this.init() | ||
|
||
// launch Zoom's enrollment process | ||
return Zoom.authenticate({ | ||
id: this.state.faceID, | ||
}).then(this.setResult, this.setError) | ||
} | ||
|
||
verifyLiveness = async () => { | ||
if (!this.initialized) await this.init() | ||
|
||
// launch Zoom's verification process | ||
return await Zoom.verify({ | ||
// no options at this point | ||
}); | ||
}; | ||
render = () => { | ||
const button = createButton({ | ||
key: "button", | ||
text: "Verify Liveness", | ||
onPress: async () => { | ||
try { | ||
this.setState({ | ||
result: await this.verifyLiveness() | ||
}); | ||
} catch (error) { | ||
this.setState({ error }); | ||
} | ||
} | ||
}); | ||
let result = this.renderResult(); | ||
let error = this.state.error && ( | ||
<View> | ||
{bigText("Error:")} | ||
{this.renderError()} | ||
</View> | ||
); | ||
return Zoom.verifyLiveness().then(this.setResult, this.setError) | ||
} | ||
|
||
setResult = (result) => this.setState({ result }) | ||
setError = (error) => this.setState({ error }) | ||
|
||
render = () => { | ||
return ( | ||
<View style={styles.container}> | ||
{bigText("Variants:")} | ||
{button} | ||
{bigText("Result:")} | ||
{result} | ||
{error} | ||
<BigText>Operations:</BigText> | ||
<Button onPress={this.verifyLiveness}>Verify Liveness</Button> | ||
<Button onPress={this.enroll}>Enroll</Button> | ||
{this.state.faceID && <Button onPress={this.authenticate}>Authenticate</Button>} | ||
{this.state.result && ( | ||
<> | ||
<BigText>Result:</BigText> | ||
<ScrollView contentContainerStyle={styles.scrollContainer}> | ||
<BigText>{prettify(this.state.result)}</BigText> | ||
</ScrollView> | ||
</> | ||
)} | ||
{this.state.error && ( | ||
<> | ||
<BigText>Error:</BigText> | ||
<BigText>{prettify(this.state.error)}</BigText> | ||
</> | ||
)} | ||
</View> | ||
); | ||
}; | ||
renderResult = () => { | ||
const { result } = this.state; | ||
if (!result) return; | ||
|
||
const { faceMetrics = {} } = result; | ||
const { facemap, auditTrail = [] } = faceMetrics; | ||
const images = auditTrail.map((uri, i) => ( | ||
<Image key={`image${i}`} style={styles.image} source={{ uri }} /> | ||
)); | ||
return ( | ||
<ScrollView contentContainerStyle={styles.scrollContainer}> | ||
{bigText(prettify(result))} | ||
{images} | ||
</ScrollView> | ||
); | ||
}; | ||
renderError = () => { | ||
return ( | ||
this.state.error && ( | ||
<View key="error">{bigText(prettify(this.state.error))}</View> | ||
) | ||
); | ||
}; | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
scrollContainer: {}, | ||
container: { | ||
flex: 1, | ||
justifyContent: "center", | ||
alignItems: "center" | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
button: { | ||
padding: 10 | ||
padding: 10, | ||
}, | ||
buttonText: { | ||
color: "blue" | ||
color: 'blue', | ||
fontSize: 30, | ||
}, | ||
bigText: { | ||
fontSize: 20 | ||
}, | ||
hugeText: { | ||
fontSize: 30 | ||
fontSize: 20, | ||
}, | ||
image: { | ||
flex: 1, | ||
resizeMode: "contain", | ||
resizeMode: 'contain', | ||
minWidth: 300, | ||
minHeight: 300 | ||
} | ||
}); | ||
minHeight: 300, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters