diff --git a/RippleChat/BTPeripheral.swift b/RippleChat/BTPeripheral.swift index 5babc0e..37e457d 100644 --- a/RippleChat/BTPeripheral.swift +++ b/RippleChat/BTPeripheral.swift @@ -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)") diff --git a/RippleChat/BluetoothController.swift b/RippleChat/BluetoothController.swift index ba5a0d1..b871b78 100644 --- a/RippleChat/BluetoothController.swift +++ b/RippleChat/BluetoothController.swift @@ -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) diff --git a/RippleChat/Views/PeeringView.swift b/RippleChat/Views/PeeringView.swift index 421d70c..2ea0636 100644 --- a/RippleChat/Views/PeeringView.swift +++ b/RippleChat/Views/PeeringView.swift @@ -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)}") } }