forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathomi_lib.swift
More file actions
62 lines (49 loc) · 2.09 KB
/
Copy pathomi_lib.swift
File metadata and controls
62 lines (49 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// The Swift Programming Language
// https://docs.swift.org/swift-book
import AVFoundation
public struct Device {
public var id: String
}
public class OmiManager {
public init() {}
private static var singleton = OmiManager()
private static var friend_singleton = FriendManager()
var deviceCompletion: ((Device?, Error?) -> Void)?
var seen_devices: [Friend] = []
public static func startScan(completion: ((Device?, Error?) -> Void)?) {
friend_singleton.deviceCompletion = { device, error in
if let id = device?.id.uuidString {
if singleton.seen_devices.firstIndex(where: {$0.id.uuidString == id}) == nil {
singleton.seen_devices.append(device!)
}
completion?(Device(id: id), nil)
}
else {
completion?(nil, error)
}
}
friend_singleton.startScan()
}
public static func endScan() {
self.friend_singleton.deviceCompletion = nil
self.friend_singleton.bluetoothScanner.centralManager.stopScan()
}
public static func connectToDevice(device: Device) {
if let device = self.singleton.seen_devices.first(where: {$0.id.uuidString == device.id}) {
self.friend_singleton.connectToDevice(device: device)
}
}
public static func connectionUpdated(completion: @escaping(Bool) -> Void) {
self.friend_singleton.connectionStatus(completion: completion)
}
public static func getLiveTranscription(device: Device, completion: @escaping (String?) -> Void) {
if let device = self.singleton.seen_devices.first(where: {$0.id.uuidString == device.id}) {
self.friend_singleton.getLiveTranscription(device: device, completion: completion)
}
}
public static func getLiveAudio(device: Device, completion: @escaping (URL?) -> Void) {
if let device = self.singleton.seen_devices.first(where: {$0.id.uuidString == device.id}) {
self.friend_singleton.getRawAudio(device: device, completion: completion)
}
}
}