Skip to content

Commit

Permalink
Change logic to still leave in event that user cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjroach committed Nov 10, 2023
1 parent 42115ba commit 97d18dd
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,29 @@ internal class LivenessWebSocket(
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
LOG.debug("WebSocket onClosed")
super.onClosed(webSocket, code, reason)
val recordedError = webSocketError
/*
If the server reports an invalid signature due to a time difference between the local clock and the
server clock, AND we haven't already tried to reconnect, then we should try to reconnect with an offset
*/
if (reconnectState == ConnectionState.NORMAL &&
!isTimeDiffSafe(timeDiffOffsetInMillis) &&
recordedError is PredictionsException &&
recordedError.cause is InvalidSignatureException
) {
LOG.info("The server rejected the connection due to a likely time difference. Attempting reconnect.")
reconnectState = ConnectionState.ATTEMPT_RECONNECT
webSocketError = null
start()
} else if (code != NORMAL_SOCKET_CLOSURE_STATUS_CODE && !clientStoppedSession) {
val faceLivenessException = recordedError ?: PredictionsException(
"An error occurred during the face liveness check.",
reason
)
onErrorReceived.accept(faceLivenessException)
if (code != NORMAL_SOCKET_CLOSURE_STATUS_CODE && !clientStoppedSession) {
val recordedError = webSocketError

/*
If the server reports an invalid signature due to a time difference between the local clock and the
server clock, AND we haven't already tried to reconnect, then we should try to reconnect with an offset
*/
if (reconnectState == ConnectionState.NORMAL &&
!isTimeDiffSafe(timeDiffOffsetInMillis) &&
recordedError is PredictionsException &&
recordedError.cause is InvalidSignatureException
) {
LOG.info("The server rejected the connection due to a likely time difference. Attempting reconnect")
reconnectState = ConnectionState.ATTEMPT_RECONNECT
webSocketError = null
start()
} else {
val faceLivenessException = recordedError ?: PredictionsException(
"An error occurred during the face liveness check.",
reason
)
onErrorReceived.accept(faceLivenessException)
}
} else {
onComplete.call()
}
Expand Down

0 comments on commit 97d18dd

Please sign in to comment.