Skip to content

Commit

Permalink
feat: Adding new error when the camera is not available even though p…
Browse files Browse the repository at this point in the history
…ermissions were granted.
  • Loading branch information
ruisebas committed Aug 2, 2024
1 parent b1bb0db commit fddb32b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HostApp/HostApp/Views/ExampleLivenessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct ExampleLivenessView: View {
viewModel.presentationState = .error(.countdownFaceTooClose)
case .failure(.invalidSignature):
viewModel.presentationState = .error(.invalidSignature)
case .failure(.cameraNotAvailable):
viewModel.presentationState = .error(.cameraNotAvailable)
default:
viewModel.presentationState = .liveness
}
Expand Down Expand Up @@ -74,6 +76,8 @@ struct ExampleLivenessView: View {
LivenessCheckErrorContentView.failedDuringCountdown
case .invalidSignature:
LivenessCheckErrorContentView.invalidSignature
case .cameraNotAvailable:
LivenessCheckErrorContentView.cameraNotAvailable
default:
LivenessCheckErrorContentView.unexpected
}
Expand Down
5 changes: 5 additions & 0 deletions HostApp/HostApp/Views/LivenessCheckErrorContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ extension LivenessCheckErrorContentView {
name: "The signature on the request is invalid.",
description: "Ensure the device time is correct and try again."
)

static let cameraNotAvailable = LivenessCheckErrorContentView(
name: "The camera could not be started.",
description: "There might be a hardware issue with the camera."
)
}

struct LivenessCheckErrorContentView_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public struct FaceLivenessDetectionError: Error, Equatable {
recoverySuggestion: "Ensure the device time is correct and try again."
)

public static let cameraNotAvailable = FaceLivenessDetectionError(
code: 18,
message: "The camera is not available.",
recoverySuggestion: "There might be a hardware issue."
)

public static func == (lhs: FaceLivenessDetectionError, rhs: FaceLivenessDetectionError) -> Bool {
lhs.code == rhs.code
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public struct FaceLivenessDetectorView: View {
return .faceInOvalMatchExceededTimeLimitError
case .socketClosed:
return .socketClosed
case .cameraNotAvailable:
return .cameraNotAvailable
default:
return .cameraPermissionDenied
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ class FaceLivenessDetectionViewModel: ObservableObject {
switch captureSessionError {
case LivenessCaptureSessionError.cameraUnavailable,
LivenessCaptureSessionError.deviceInputUnavailable:

livenessError = .missingVideoPermission
let authStatus = AVCaptureDevice.authorizationStatus(for: .video)
livenessError = authStatus == .authorized ? .cameraNotAvailable : .missingVideoPermission
case LivenessCaptureSessionError.captureSessionOutputUnavailable,
LivenessCaptureSessionError.captureSessionInputUnavailable:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct LivenessStateMachine {
static let couldNotOpenStream = LivenessError(code: 5, webSocketCloseCode: .unexpectedRuntimeError)
static let socketClosed = LivenessError(code: 6, webSocketCloseCode: .normalClosure)
static let viewResignation = LivenessError(code: 8, webSocketCloseCode: .viewClosure)
static let cameraNotAvailable = LivenessError(code: 9, webSocketCloseCode: .cameraNotAvailable)

static func == (lhs: LivenessError, rhs: LivenessError) -> Bool {
lhs.code == rhs.code
Expand All @@ -173,4 +174,5 @@ extension URLSessionWebSocketTask.CloseCode {
static let viewClosure = URLSessionWebSocketTask.CloseCode(rawValue: 4004)
static let unexpectedRuntimeError = URLSessionWebSocketTask.CloseCode(rawValue: 4005)
static let missingVideoPermission = URLSessionWebSocketTask.CloseCode(rawValue: 4006)
static let cameraNotAvailable = URLSessionWebSocketTask.CloseCode(rawValue: 4007)
}

0 comments on commit fddb32b

Please sign in to comment.