Skip to content

Commit f0bbd12

Browse files
committed
Fix missing and duplicate notifications
1 parent 2049c25 commit f0bbd12

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Sources/PanasonicEasyIPsetupBlueSocket/Manager.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Manager {
1010
let socket: Socket
1111

1212
private var shouldPoll = true
13-
public private (set) var configurations = Set<CameraConfiguration>()
13+
private var cameras = [Int:CameraConfiguration]()
1414

1515
public var discoveryHandler: ((CameraConfiguration)->Void)?
1616
public var errorHandler: ((Error)->Void)?
@@ -23,8 +23,12 @@ public class Manager {
2323
try search()
2424
}
2525

26+
public var configurations: Dictionary<Int, CameraConfiguration>.Values {
27+
return cameras.values
28+
}
29+
2630
public func search() throws {
27-
configurations.removeAll(keepingCapacity: true)
31+
cameras.removeAll(keepingCapacity: true)
2832
let addresses = Interface
2933
.allInterfaces()
3034
.filter {$0.family == .ipv4 && $0.broadcastAddress != nil}
@@ -55,8 +59,12 @@ public class Manager {
5559
}
5660

5761
private func notify(configuration: CameraConfiguration) {
58-
if configurations.insert(configuration).inserted, let handler = discoveryHandler {
59-
handler(configuration)
62+
let key = configuration.hashValue
63+
if !cameras.keys.contains(key) {
64+
cameras[key] = configuration
65+
discoveryHandler?(configuration)
66+
} else if cameras[key] != configuration {
67+
// Todo notify handler that a camera has changed its configuration.
6068
}
6169
}
6270

0 commit comments

Comments
 (0)