mirror of
https://github.com/ProxymanApp/atlantis.git
synced 2026-05-20 20:20:35 +00:00
Attempt to connect by HostName
This commit is contained in:
@@ -57,9 +57,12 @@ public final class Atlantis: NSObject {
|
||||
public static let buildVersion: String = "1.1.0"
|
||||
|
||||
/// Start Swizzle all network functions and monitoring the traffic
|
||||
/// It also starts looking Bonjour network from Proxyman app
|
||||
public class func start() {
|
||||
let configuration = Configuration.default()
|
||||
/// It also starts looking Bonjour network from Proxyman app.
|
||||
/// If hostName is nil, it will looking for the first Proxyman app in the network. It's useful if we have only one machine.
|
||||
/// If hostName is not nil, Atlantis will try to connect to particular mac machine. It's useful if you have multiple Proxyman.
|
||||
/// - Parameter hostName: Host name of Mac machine. You can find your current Host Name in Proxyman -> Certificate -> Install on iOS -> By Atlantis...
|
||||
public class func start(hostName: String? = nil) {
|
||||
let configuration = Configuration.default(hostName: hostName)
|
||||
|
||||
// don't start the service if it's unavailable
|
||||
guard Atlantis.isServiceAvailable else {
|
||||
|
||||
@@ -13,17 +13,20 @@ struct Configuration {
|
||||
let projectName: String
|
||||
let deviceName: String
|
||||
let id: String
|
||||
let hostName: String?
|
||||
|
||||
static func `default`() -> Configuration {
|
||||
static func `default`(hostName: String? = nil) -> Configuration {
|
||||
let project = Project.current
|
||||
let deviceName = Device.current
|
||||
return Configuration(projectName: project.name,
|
||||
deviceName: deviceName.name)
|
||||
deviceName: deviceName.name,
|
||||
hostName: hostName)
|
||||
}
|
||||
|
||||
init(projectName: String, deviceName: String) {
|
||||
private init(projectName: String, deviceName: String, hostName: String?) {
|
||||
self.projectName = projectName
|
||||
self.deviceName = deviceName
|
||||
self.hostName = hostName
|
||||
self.id = "\(Project.current.bundleIdentifier)-\(Device.current.model)" // Use this ID to distinguish the message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ final class NetServiceTransport: NSObject {
|
||||
private var task: URLSessionStreamTask?
|
||||
private var pendingPackages: [Serializable] = []
|
||||
private var config: Configuration?
|
||||
private var moreComing: Bool = false
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -146,6 +147,25 @@ extension NetServiceTransport {
|
||||
|
||||
private func connectToService(_ service: NetService) {
|
||||
|
||||
// If user want to connect to particular host name
|
||||
// We shoul check
|
||||
// by default, config.hostName is nil, it will connect to the first Proxyman
|
||||
if let hostName = config?.hostName,
|
||||
var serviceHostName = service.hostName {
|
||||
if serviceHostName.hasSuffix(".") {
|
||||
serviceHostName = String(serviceHostName.dropLast())
|
||||
}
|
||||
|
||||
if hostName.lowercased() != serviceHostName.lowercased() {
|
||||
// If there is no coming service, tell the user
|
||||
if !moreComing {
|
||||
print("[Atlantis][ERROR] Could not connect to Proxyman with Host Name = \(hostName)")
|
||||
print("[Atlantis][INFO] Please find the correct Host Name in Proxyman app -> Certificate -> Install on iOS -> By Atlantis")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Stop previous connection if need
|
||||
if let task = task {
|
||||
task.closeWrite()
|
||||
@@ -192,8 +212,10 @@ extension NetServiceTransport {
|
||||
extension NetServiceTransport: NetServiceBrowserDelegate {
|
||||
|
||||
func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
|
||||
print("")
|
||||
queue.async {[weak self] in
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.moreComing = moreComing
|
||||
strongSelf.services.append(service)
|
||||
service.delegate = strongSelf
|
||||
service.resolve(withTimeout: 30)
|
||||
@@ -211,6 +233,10 @@ extension NetServiceTransport: NetServiceBrowserDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func netServiceBrowser(_ browser: NetServiceBrowser, didFindDomain domainString: String, moreComing: Bool) {
|
||||
print(domainString)
|
||||
}
|
||||
|
||||
func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {
|
||||
// Retry again after going from the foregronud
|
||||
start()
|
||||
|
||||
Reference in New Issue
Block a user