Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ internal class LivenessCoordinator(
)
processSessionError(faceLivenessException, true)
}
livenessState.loadingCameraPreview = false
}
}
}
Expand Down Expand Up @@ -222,7 +221,7 @@ internal class LivenessCoordinator(
{
livenessState.onLivenessSessionReady(it)
if (!challengeOptions.hasOneCameraConfigured()) {
val foundChallenge = challengeOptions.getOptions(it.challengeType)
val foundChallenge = challengeOptions.getLivenessChallenge(it.challengeType)
launchCamera(foundChallenge.camera)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import kotlinx.coroutines.launch
* @param region AWS region to stream the video to. Current supported regions are listed in [add link here]
* @param credentialsProvider to provide custom CredentialsProvider for authentication. Default uses initialized Amplify.Auth CredentialsProvider
* @param disableStartView to bypass warmup screen.
* @param challengeOptions is the list of ChallengeOptions that are to be overridden from the default configuration
* @param onComplete callback notifying a completed challenge
* @param onError callback containing exception for cause
*/
Expand All @@ -83,9 +82,36 @@ fun FaceLivenessDetector(
region: String,
credentialsProvider: AWSCredentialsProvider<AWSCredentials>? = null,
disableStartView: Boolean = false,
challengeOptions: ChallengeOptions = ChallengeOptions(),
onComplete: Action,
onError: Consumer<FaceLivenessDetectionException>
) = FaceLivenessDetector(
sessionId,
region,
credentialsProvider,
disableStartView,
onComplete,
onError,
ChallengeOptions()
)

/**
* @param sessionId of challenge
* @param region AWS region to stream the video to. Current supported regions are listed in [add link here]
* @param credentialsProvider to provide custom CredentialsProvider for authentication. Default uses initialized Amplify.Auth CredentialsProvider
* @param disableStartView to bypass warmup screen.
* @param challengeOptions is the list of ChallengeOptions that are to be overridden from the default configuration
* @param onComplete callback notifying a completed challenge
* @param onError callback containing exception for cause
*/
@Composable
fun FaceLivenessDetector(
sessionId: String,
region: String,
credentialsProvider: AWSCredentialsProvider<AWSCredentials>? = null,
disableStartView: Boolean = false,
onComplete: Action,
onError: Consumer<FaceLivenessDetectionException>,
challengeOptions: ChallengeOptions = ChallengeOptions(),
) {
val scope = rememberCoroutineScope()
val key = Triple(sessionId, region, credentialsProvider)
Expand Down Expand Up @@ -421,7 +447,7 @@ data class ChallengeOptions(
val faceMovementAndLight: LivenessChallenge.FaceMovementAndLight = LivenessChallenge.FaceMovementAndLight,
val faceMovement: LivenessChallenge.FaceMovement = LivenessChallenge.FaceMovement()
) {
fun getOptions(challengeType: FaceLivenessChallengeType): LivenessChallenge =
internal fun getLivenessChallenge(challengeType: FaceLivenessChallengeType): LivenessChallenge =
when (challengeType) {
FaceLivenessChallengeType.FaceMovementAndLightChallenge -> faceMovementAndLight
FaceLivenessChallengeType.FaceMovementChallenge -> faceMovement
Expand All @@ -430,25 +456,25 @@ data class ChallengeOptions(
/**
* @return true if all of the challenge options are configured to use the same camera configuration
*/
fun hasOneCameraConfigured(): Boolean =
internal fun hasOneCameraConfigured(): Boolean =
listOf(
faceMovementAndLight,
faceMovement
).all { it.camera == faceMovementAndLight.camera }
}

sealed class LivenessChallenge(
val camera: Camera = Camera.Front
open val camera: Camera = Camera.Front
) {
class FaceMovement(camera: Camera = Camera.Front) : LivenessChallenge(
data class FaceMovement(override val camera: Camera = Camera.Front) : LivenessChallenge(
camera = camera
)
object FaceMovementAndLight : LivenessChallenge()
data object FaceMovementAndLight : LivenessChallenge()
}

sealed class Camera {
object Front : Camera()
object Back : Camera()
data object Front : Camera()
data object Back : Camera()
}

private fun FaceLivenessSession?.isFaceMovementAndLightChallenge(): Boolean =
Expand Down