Skip to content

Commit

Permalink
chore(liveness): add close codes to websocket apis (#2658)
Browse files Browse the repository at this point in the history
Co-authored-by: tjroach <[email protected]>
Co-authored-by: Thomas Leing <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2023
1 parent c72f75f commit bebf857
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FaceLivenessSessionChallenge>,
private val onVideoEvent: (VideoEvent) -> Unit,
private val onChallengeResponseEvent: (ChallengeResponseEvent) -> Unit,
private val stopLivenessSession: Action
private val stopLivenessSession: (Int?) -> Unit
) {

fun sendVideoEvent(videoEvent: VideoEvent) {
Expand All @@ -34,7 +33,8 @@ class FaceLivenessSession(
onChallengeResponseEvent(challengeResponseEvent)
}

fun stopSession() {
stopLivenessSession.call()
@JvmOverloads
fun stopSession(reasonCode: Int? = null) {
stopLivenessSession(reasonCode)
}
}

0 comments on commit bebf857

Please sign in to comment.