WIP: Add abiity to receive using iOS app

This commit is contained in:
Leon Böttger committed 2025-08-17 11:46:47 +02:00
1 parent 608ab41c0b
commit 6ec3902788
13 files changed
+473 -214

No files matched your search

@@ -7,6 +7,7 @@
#if os(iOS)
import UIKit
import RNDeviceName
#endif
import Foundation
@@ -31,12 +32,19 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
private var qrCodeAdvertisingToken: Data?
private var qrCodeNameEncryptionKey: SymmetricKey?
public let deviceInfo: EndpointInfo
public let endpointID: [UInt8] = generateEndpointID()
public var mainAppDelegate: (any InboundAppDelegate)?
public static let shared = NearbyConnectionManager()
override init() {
#if os(macOS)
self.deviceInfo = EndpointInfo(name: Host.current().localizedName ?? "Mac", deviceType: .computer)
#else
self.deviceInfo = EndpointInfo(name: UIDevice.current.marketingName, deviceType: .phone)
#endif
tcpListener = try! NWListener(using: NWParameters(tls: .none))
super.init()
}
@@ -104,7 +112,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
let service = NetService(domain: "", type: serviceType, name: name, port: port)
service.delegate = self
service.setTXTRecord(NetService.data(fromTXTRecord: [
"n": getEndpointInfo().serialize().urlSafeBase64EncodedString().data(using: .utf8)!,
"n": deviceInfo.serialize().urlSafeBase64EncodedString().data(using: .utf8)!,
]))
service.publish()
return service
@@ -112,17 +120,6 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
}
func getEndpointInfo() -> EndpointInfo {
#if os(macOS)
let endpointInfo = EndpointInfo(name: Host.current().localizedName ?? "Mac", deviceType: .computer)
#else
let endpointInfo = EndpointInfo(name: UIDevice.current.name, deviceType: .phone)
#endif
return endpointInfo
}
func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo, connection _: InboundNearbyConnection) {
mainAppDelegate?.obtainUserConsent(for: transfer, from: device)
}
@@ -167,7 +167,7 @@ class OutboundNearbyConnection: NearbyConnection {
private func sendConnectionRequest() throws {
let endpointInfo = NearbyConnectionManager.shared.getEndpointInfo()
let endpointInfo = NearbyConnectionManager.shared.deviceInfo
var frame = Location_Nearby_Connections_OfflineFrame()
frame.version = .v1