Skip to content

Commit bebf857

Browse files
tjleingtylerjroachThomas Leing
authored
chore(liveness): add close codes to websocket apis (#2658)
Co-authored-by: tjroach <[email protected]> Co-authored-by: Thomas Leing <[email protected]>
1 parent c72f75f commit bebf857

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ internal class LivenessWebSocket(
481481
}
482482
}
483483

484-
fun destroy() {
485-
// Close gracefully
486-
webSocket?.close(NORMAL_SOCKET_CLOSURE_STATUS_CODE, null)
484+
fun destroy(reasonCode: Int = NORMAL_SOCKET_CLOSURE_STATUS_CODE) {
485+
// Close with provided reason code
486+
webSocket?.close(reasonCode, null)
487487
}
488488

489489
fun adjustedDate(date: Long = Date().time): Long {

aws-predictions/src/main/java/com/amplifyframework/predictions/aws/service/RunFaceLivenessSession.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ internal class RunFaceLivenessSession(
179179
}
180180
}
181181

182-
private fun stopLivenessSession() {
182+
private fun stopLivenessSession(reasonCode: Int?) {
183183
livenessWebSocket.clientStoppedSession = true
184-
livenessWebSocket.destroy()
184+
reasonCode?.let { livenessWebSocket.destroy(it) } ?: livenessWebSocket.destroy()
185185
}
186186
}

core/src/main/java/com/amplifyframework/predictions/models/FaceLivenessSession.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
package com.amplifyframework.predictions.models
1717

1818
import com.amplifyframework.annotations.InternalAmplifyApi
19-
import com.amplifyframework.core.Action
2019

2120
@InternalAmplifyApi
2221
class FaceLivenessSession(
2322
val challenges: List<FaceLivenessSessionChallenge>,
2423
private val onVideoEvent: (VideoEvent) -> Unit,
2524
private val onChallengeResponseEvent: (ChallengeResponseEvent) -> Unit,
26-
private val stopLivenessSession: Action
25+
private val stopLivenessSession: (Int?) -> Unit
2726
) {
2827

2928
fun sendVideoEvent(videoEvent: VideoEvent) {
@@ -34,7 +33,8 @@ class FaceLivenessSession(
3433
onChallengeResponseEvent(challengeResponseEvent)
3534
}
3635

37-
fun stopSession() {
38-
stopLivenessSession.call()
36+
@JvmOverloads
37+
fun stopSession(reasonCode: Int? = null) {
38+
stopLivenessSession(reasonCode)
3939
}
4040
}

0 commit comments

Comments
 (0)