minimum viable product now seems to work
This commit is contained in:
parent
740e1a7091
commit
93a240dad8
2 changed files with 22 additions and 1 deletions
|
|
@ -37,6 +37,13 @@ struct SubscriptionManager {
|
|||
}
|
||||
|
||||
func poll(_ subscription: Subscription, completionHandler: @escaping ([Message]) -> Void) {
|
||||
// This is a bit of a hack but it prevents us from polling dead subscriptions
|
||||
if (subscription.baseUrl == nil) {
|
||||
Log.d(tag, "Attempting to poll dead subscription failed")
|
||||
completionHandler([])
|
||||
return
|
||||
}
|
||||
|
||||
let user = store.getUser(baseUrl: subscription.baseUrl!)?.toBasicUser()
|
||||
Log.d(tag, "Polling from \(subscription.urlString()) with user \(user?.username ?? "anonymous")")
|
||||
ApiService.shared.poll(subscription: subscription, user: user) { messages, error in
|
||||
|
|
|
|||
|
|
@ -45,14 +45,28 @@ struct QRScannerUIView: UIViewRepresentable {
|
|||
|
||||
class Coordinator: NSObject, AVCaptureMetadataOutputObjectsDelegate {
|
||||
var onCodeDetected: (String) -> Void
|
||||
private var lastScanDate: Date?
|
||||
private let debounceInterval: TimeInterval = 3.0
|
||||
|
||||
init(onCodeDetected: @escaping (String) -> Void) {
|
||||
self.onCodeDetected = onCodeDetected
|
||||
}
|
||||
|
||||
func qrCodeScanned(_ code: String) {
|
||||
let now = Date()
|
||||
|
||||
// If it's the first scan or the interval since the last scan is more than the debounce interval
|
||||
if let lastScan = lastScanDate, now.timeIntervalSince(lastScan) < debounceInterval {
|
||||
return
|
||||
}
|
||||
|
||||
onCodeDetected(code)
|
||||
lastScanDate = now
|
||||
}
|
||||
|
||||
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
|
||||
if let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject, let stringValue = metadataObject.stringValue {
|
||||
onCodeDetected(stringValue)
|
||||
qrCodeScanned(stringValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue