Friends and their log-sequence Numbers now get listed when receiving WANT-Vector
This commit is contained in:
parent
653c2068e7
commit
1582f57eab
@ -11,6 +11,7 @@ import CoreBluetooth
|
||||
class BluetoothPeripheral: NSObject, ObservableObject {
|
||||
|
||||
@Published var incomingMsg: String = ""
|
||||
@Published var wantVector: WantMessage = WantMessage()
|
||||
private var peripheralManager: CBPeripheralManager?
|
||||
|
||||
let BLE_SERVICE_UUID = CBUUID(string: "6e400001-7646-4b5b-9a50-71becce51558")
|
||||
@ -98,6 +99,7 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
|
||||
// Use the received object to update your app state as needed
|
||||
print("Received Write")
|
||||
self.incomingMsg = receivedObject.printMsg()
|
||||
self.wantVector = receivedObject
|
||||
print(receivedObject.printMsg())
|
||||
} catch {
|
||||
print("Failed to decode JSON: \(error)")
|
||||
|
||||
@ -55,6 +55,10 @@ extension BluetoothController: CBCentralManagerDelegate, CBPeripheralDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
|
||||
// Not implemented yet
|
||||
}
|
||||
|
||||
// func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
|
||||
// print("Discovering services...")
|
||||
// peripheral.discoverCharacteristics(BLE_CHARACTERISTIC_UUID_RX)
|
||||
|
||||
@ -19,6 +19,12 @@ struct PeeringView: View {
|
||||
}
|
||||
.navigationTitle("Peering")
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
List {
|
||||
ForEach(btPeripheral.wantVector.friends.keys.sorted(), id: \.self) { friend in
|
||||
Text("Feed: \(friend.description), SEQ: \(btPeripheral.wantVector.friends[friend] ?? -1)")
|
||||
// Send new log Entries...
|
||||
}
|
||||
}
|
||||
Text("Incoming msg: \(btPeripheral.incomingMsg)")
|
||||
Button(action: {
|
||||
do {
|
||||
@ -51,6 +57,6 @@ struct WantMessage: Codable {
|
||||
var friends = [String:Int]()
|
||||
|
||||
func printMsg() -> String {
|
||||
return ("\(command) : \(friends.description)")
|
||||
return ("{\(command) : \(friends.description)}")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user