sdk final
This commit is contained in:
@@ -6,9 +6,11 @@ import CommonCrypto
|
||||
public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
|
||||
private var appId: String?
|
||||
private var secretKey: String?
|
||||
private var apiUrl: String?
|
||||
private var primaryServiceHost: String?
|
||||
private var backupServiceHost: String?
|
||||
private var servicePort: Int = 443
|
||||
private var serviceScheme: String = "https"
|
||||
|
||||
private var desiredLogEnabled: Bool?
|
||||
private var desiredHttpsEnabled: Bool?
|
||||
@@ -20,7 +22,7 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
|
||||
}()
|
||||
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: "new_httpdns", binaryMessenger: registrar.messenger())
|
||||
let channel = FlutterMethodChannel(name: "TrustAPP_httpdns", binaryMessenger: registrar.messenger())
|
||||
let instance = NewHttpDnsPlugin()
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
}
|
||||
@@ -29,26 +31,46 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
|
||||
switch call.method {
|
||||
case "initialize":
|
||||
let options = call.arguments as? [String: Any] ?? [:]
|
||||
guard let rawAppId = options["appId"] as? String,
|
||||
let rawPrimaryHost = options["primaryServiceHost"] as? String else {
|
||||
guard let rawAppId = options["appId"] as? String else {
|
||||
result(false)
|
||||
return
|
||||
}
|
||||
|
||||
let normalizedAppId = rawAppId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let normalizedPrimaryHost = rawPrimaryHost.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if normalizedAppId.isEmpty || normalizedPrimaryHost.isEmpty {
|
||||
if normalizedAppId.isEmpty {
|
||||
result(false)
|
||||
return
|
||||
}
|
||||
|
||||
appId = normalizedAppId
|
||||
primaryServiceHost = normalizedPrimaryHost
|
||||
apiUrl = (options["apiUrl"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
primaryServiceHost = (options["primaryServiceHost"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
backupServiceHost = (options["backupServiceHost"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
secretKey = (options["secretKey"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
if let p = options["servicePort"] as? Int, p > 0 {
|
||||
servicePort = p
|
||||
}
|
||||
|
||||
if let urlStr = apiUrl, !urlStr.isEmpty {
|
||||
var normalized = urlStr
|
||||
if !urlStr.lowercased().hasPrefix("http://") && !urlStr.lowercased().hasPrefix("https://") {
|
||||
normalized = "https://" + urlStr
|
||||
}
|
||||
if let url = URL(string: normalized) {
|
||||
primaryServiceHost = url.host
|
||||
if let p = url.port {
|
||||
servicePort = p
|
||||
}
|
||||
serviceScheme = url.scheme ?? "https"
|
||||
}
|
||||
} else if let host = primaryServiceHost {
|
||||
// Keep as is, using defaults
|
||||
} else {
|
||||
result(false)
|
||||
return
|
||||
}
|
||||
|
||||
result(true)
|
||||
|
||||
case "setLogEnabled":
|
||||
@@ -180,7 +202,7 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
|
||||
|
||||
let serviceHost = hosts[index]
|
||||
var components = URLComponents()
|
||||
components.scheme = "https"
|
||||
components.scheme = serviceScheme
|
||||
components.host = serviceHost
|
||||
components.port = servicePort
|
||||
components.path = "/resolve"
|
||||
|
||||
Reference in New Issue
Block a user