Replication Callback not received when document updated/added from another phone
harshOnAndroid opened this issue · comments
I am trying to implement just a basic demo. The following code runs. properly on an android device. But when the app ran on iPhone, the replication listener is not working. I am expecting a callback in DocumentReplicationListener. The callback never happens in the case of iPhone.
Following is the code. Only posting relevant code. Everything else is a copy of the example code of this repo.
Future<String> runExample() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
database = await Database.initWithName("myDb");
} on PlatformException {
return "Error initializing database";
}
// Create a query to fetch documents of type SDK.
var query = QueryBuilder.select([SelectResult.all()])
.from("getting-started-db");
// Note wss://10.0.2.2:4984/my-database is for the android simulator on your local machine's couchbase database
// Create replicators to push and pull changes to and from the cloud.
ReplicatorConfiguration config =ReplicatorConfiguration(database, "ws://ipAddress/myDb");
config.replicatorType = ReplicatorType.pushAndPull;
config.continuous = true;
// Add authentication.
config.authenticator = BasicAuthenticator("myDb", "myPassword");
// Create replicator (make sure to add an instance or static variable named replicator)
var replicator = Replicator(config);
replicator.addDocumentReplicationListener((callback){
var docs = callback.documents.last;
print("replication listener => ${ jsonDecode(docs.toJson())}");
});
// Listen to replicator change events.
_listenerToken = replicator.addChangeListener((ReplicatorChange event) {
if (event.status.error != null) {
print("Error: " + event.status.error);
}
print("change == "+event.status.activity.toString());
print("time == ${new DateTime.now().millisecondsSinceEpoch}");
});
// Start replication.
await replicator.start();
return "Database and Replicator Started";
}
Turns out, it was a server side mistake.
This solved the problem.