From bebf85729dbbda2034b85872e2e5a1bb90d089c4 Mon Sep 17 00:00:00 2001 From: Thomas Leing Date: Fri, 22 Dec 2023 00:20:52 -0800 Subject: [PATCH] chore(liveness): add close codes to websocket apis (#2658) Co-authored-by: tjroach Co-authored-by: Thomas Leing --- .../predictions/aws/http/LivenessWebSocket.kt | 6 +++--- .../predictions/aws/service/RunFaceLivenessSession.kt | 4 ++-- .../predictions/models/FaceLivenessSession.kt | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt index e4a34d29a7..d676621d6b 100644 --- a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt +++ b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt @@ -481,9 +481,9 @@ internal class LivenessWebSocket( } } - fun destroy() { - // Close gracefully - webSocket?.close(NORMAL_SOCKET_CLOSURE_STATUS_CODE, null) + fun destroy(reasonCode: Int = NORMAL_SOCKET_CLOSURE_STATUS_CODE) { + // Close with provided reason code + webSocket?.close(reasonCode, null) } fun adjustedDate(date: Long = Date().time): Long { diff --git a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/service/RunFaceLivenessSession.kt b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/service/RunFaceLivenessSession.kt index 0028e46359..d6d1000fdd 100644 --- a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/service/RunFaceLivenessSession.kt +++ b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/service/RunFaceLivenessSession.kt @@ -179,8 +179,8 @@ internal class RunFaceLivenessSession( } } - private fun stopLivenessSession() { + private fun stopLivenessSession(reasonCode: Int?) { livenessWebSocket.clientStoppedSession = true - livenessWebSocket.destroy() + reasonCode?.let { livenessWebSocket.destroy(it) } ?: livenessWebSocket.destroy() } } diff --git a/core/src/main/java/com/amplifyframework/predictions/models/FaceLivenessSession.kt b/core/src/main/java/com/amplifyframework/predictions/models/FaceLivenessSession.kt index 10e6e62f59..bd5d5dd6f3 100644 --- a/core/src/main/java/com/amplifyframework/predictions/models/FaceLivenessSession.kt +++ b/core/src/main/java/com/amplifyframework/predictions/models/FaceLivenessSession.kt @@ -16,14 +16,13 @@ package com.amplifyframework.predictions.models import com.amplifyframework.annotations.InternalAmplifyApi -import com.amplifyframework.core.Action @InternalAmplifyApi class FaceLivenessSession( val challenges: List, private val onVideoEvent: (VideoEvent) -> Unit, private val onChallengeResponseEvent: (ChallengeResponseEvent) -> Unit, - private val stopLivenessSession: Action + private val stopLivenessSession: (Int?) -> Unit ) { fun sendVideoEvent(videoEvent: VideoEvent) { @@ -34,7 +33,8 @@ class FaceLivenessSession( onChallengeResponseEvent(challengeResponseEvent) } - fun stopSession() { - stopLivenessSession.call() + @JvmOverloads + fun stopSession(reasonCode: Int? = null) { + stopLivenessSession(reasonCode) } }