Skip to content

Commit c9844f3

Browse files
committed
updated to fix replication configuration passed in values
1 parent c0f4e56 commit c9844f3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CbliteSwiftJsLib/Classes/ReplicatorHelper.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,36 @@ public struct ReplicatorHelper {
1515
guard let target = data["target"] as? [String: Any],
1616
let url = target["url"] as? String,
1717
let replicatorType = data["replicatorType"] as? String,
18-
let continuous = data["continuous"] as? Bool else {
18+
let continuous = data["continuous"] as? Bool,
19+
let acceptParentDomainCookies = data["acceptParentDomainCookies"] as? Bool,
20+
let acceptSelfSignedCerts = data["acceptSelfSignedCerts"] as? Bool,
21+
let allowReplicationInBackground = data["allowReplicationInBackground"] as? Bool,
22+
let autoPurgeEnabled = data["autoPurgeEnabled"] as? Bool,
23+
let heartbeat = data["heartbeat"] as? NSNumber,
24+
let maxAttempts = data["maxAttempts"] as? NSNumber,
25+
let maxAttemptWaitTime = data["maxAttemptWaitTime"] as? NSNumber
26+
else {
1927
throw ReplicatorError.fatalError(message: "Invalid JSON data")
2028
}
2129

2230
let endpoint = URLEndpoint(url: URL(string: url)!)
31+
32+
//set values from data
2333
var replConfig = ReplicatorConfiguration(target: endpoint)
34+
replConfig.acceptParentDomainCookie = acceptSelfSignedCerts
35+
replConfig.acceptParentDomainCookie = acceptParentDomainCookies
36+
replConfig.allowReplicatingInBackground = allowReplicationInBackground
37+
replConfig.continuous = continuous
38+
replConfig.enableAutoPurge = autoPurgeEnabled
39+
40+
replConfig.heartbeat = TimeInterval(exactly: heartbeat.int64Value) ?? 300
41+
replConfig.maxAttemptWaitTime = TimeInterval(exactly: maxAttemptWaitTime.int64Value) ?? 0
42+
replConfig.maxAttempts = maxAttempts.uintValue
43+
44+
//check for headers
45+
if let headers = data["headers"] as? [String: String] {
46+
replConfig.headers = headers
47+
}
2448

2549
if let authenticatorData = data["authenticator"], !(authenticatorData is String && authenticatorData as! String == "") {
2650
if let authenticatorConfig = authenticatorData as? [String: Any] {
@@ -43,10 +67,6 @@ public struct ReplicatorHelper {
4367
default:
4468
throw ReplicatorError.fatalError(message: "Invalid replicatorType")
4569
}
46-
47-
replConfig.continuous = continuous
48-
49-
5070
return replConfig
5171
}
5272

CbliteSwiftJsLib/Classes/ReplicatorManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class ReplicatorManager {
4343
public func replicator(_ replicatorConfig: [String: Any], collectionConfiguration: [CollectionConfigItem]) throws -> String {
4444
let id = UUID().uuidString
4545
let config = try ReplicatorHelper.replicatorConfigFromJson(replicatorConfig, collectionConfiguration: collectionConfiguration)
46+
4647
let replicator = Replicator(config: config)
4748
replicators[id] = replicator
4849
return id

0 commit comments

Comments
 (0)