Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy connection on transfer complete #26

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ios/Openid4vpBle/Openid4vpBle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

Expand Down
16 changes: 8 additions & 8 deletions ios/Wallet/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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!!")
Expand Down
2 changes: 2 additions & 0 deletions ios/ble/Utility/TransferHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion ios/ble/central/CentralManagerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down