diff --git a/ios/Openid4vpBle/Openid4vpBle.swift b/ios/Openid4vpBle/Openid4vpBle.swift index 60db1545..04c6e49b 100644 --- a/ios/Openid4vpBle/Openid4vpBle.swift +++ b/ios/Openid4vpBle/Openid4vpBle.swift @@ -57,7 +57,8 @@ class Openid4vpBle: RCTEventEmitter { @objc(destroyConnection:) func destroyConnection(withCallback callback: @escaping RCTResponseSenderBlock) -> Any { - Wallet.shared.destroyConnection() + Wallet.shared.destroyConnection(isSelfDisconnect: true) + callback([]) return "check" as! Any } @@ -113,7 +114,7 @@ class Openid4vpBle: RCTEventEmitter { } fileprivate func handleError(_ message: String) { - Wallet.shared.destroyConnection() + Wallet.shared.destroyConnection(isSelfDisconnect: false) EventEmitter.sharedInstance.emitNearbyErrorEvent(message: message) } diff --git a/ios/Wallet/Wallet.swift b/ios/Wallet/Wallet.swift index e64d6922..6b812517 100644 --- a/ios/Wallet/Wallet.swift +++ b/ios/Wallet/Wallet.swift @@ -30,8 +30,8 @@ class Wallet: NSObject { verifierPublicKey = publicKeyData } - func destroyConnection(){ - onDeviceDisconnected(isManualDisconnect: false) + func destroyConnection(isSelfDisconnect: Bool){ + onDeviceDisconnected(isSelfDisconnect: isSelfDisconnect) } func isSameAdvIdentifier(advertisementPayload: Data) -> Bool { @@ -97,11 +97,11 @@ class Wallet: NSObject { central?.write(serviceUuid: Peripheral.SERVICE_UUID, charUUID: NetworkCharNums.IDENTIFY_REQUEST_CHAR_UUID, data: iv + publicKey) } - func onDeviceDisconnected(isManualDisconnect: Bool) { - if(!isManualDisconnect) { - if let connectedPeripheral = central?.connectedPeripheral { - central?.centralManager.cancelPeripheralConnection(connectedPeripheral) - } + func onDeviceDisconnected(isSelfDisconnect: Bool) { + if let connectedPeripheral = central?.connectedPeripheral { + central?.centralManager.cancelPeripheralConnection(connectedPeripheral) + } + if(!isSelfDisconnect) { EventEmitter.sharedInstance.emitNearbyEvent(event: "onDisconnected") } } @@ -118,7 +118,7 @@ extension Wallet: WalletProtocol { let connStatusID = Int(data[0]) if connStatusID == 1 { print("con statusid:", connStatusID) - destroyConnection() + destroyConnection(isSelfDisconnect: false) } } else { print("weird reason!!") diff --git a/ios/ble/Utility/TransferHandler.swift b/ios/ble/Utility/TransferHandler.swift index b0d87c2e..97e9ed89 100644 --- a/ios/ble/Utility/TransferHandler.swift +++ b/ios/ble/Utility/TransferHandler.swift @@ -90,6 +90,7 @@ class TransferHandler { if (r.type == .SUCCESS) { currentState = States.TransferVerified EventEmitter.sharedInstance.emitNearbyMessage(event: "send-vc:response", data: "\"RECEIVED\"") + sendMessage(message: imessage(msgType: .RESPONSE_TRANSFER_COMPLETE)) print("Emitting send-vc:response RECEIVED message") } else if r.type == .MISSING_CHUNKS { currentState = .PartiallyTransferred @@ -193,6 +194,7 @@ extension TransferHandler: PeripheralCommunicatorProtocol { } else if status == 1 { EventEmitter.sharedInstance.emitNearbyMessage(event: "send-vc:response", data: "\"REJECTED\"") } + Wallet.shared.destroyConnection(isSelfDisconnect: true) } } } diff --git a/ios/ble/central/CentralManagerDelegate.swift b/ios/ble/central/CentralManagerDelegate.swift index 73b24694..49d873ce 100644 --- a/ios/ble/central/CentralManagerDelegate.swift +++ b/ios/ble/central/CentralManagerDelegate.swift @@ -34,7 +34,7 @@ extension Central { if let connectedPeripheral = connectedPeripheral { central.cancelPeripheralConnection(connectedPeripheral) } - Wallet.shared.destroyConnection() + Wallet.shared.destroyConnection(isSelfDisconnect: false) } func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {