Commit b5b67f3f authored by Yusuke Iwaki's avatar Yusuke Iwaki

FIX #84 call unsubscribe on subscription done if needed.

parent 5b35e0f4
......@@ -57,13 +57,16 @@ public class DDPClientWraper {
* Subscribe with DDP client.
*/
public Task<DDPSubscription.Ready> subscribe(final String name, JSONArray param) {
return ddpClient.sub(UUID.randomUUID().toString(), name, param);
final String subscriptionId = UUID.randomUUID().toString();
RCLog.d("sub:[%s]> %s(%s)", subscriptionId, name, param);
return ddpClient.sub(subscriptionId, name, param);
}
/**
* Unsubscribe with DDP client.
*/
public Task<DDPSubscription.NoSub> unsubscribe(final String subscriptionId) {
RCLog.d("unsub:[%s]>", subscriptionId);
return ddpClient.unsub(subscriptionId);
}
......
......@@ -21,6 +21,7 @@ public abstract class AbstractDDPDocEventSubscriber implements Registerable {
protected final String hostname;
protected final RealmHelper realmHelper;
protected final DDPClientWraper ddpClient;
private boolean isUnsubscribed;
private String subscriptionId;
private Subscription rxSubscription;
......@@ -53,6 +54,7 @@ public abstract class AbstractDDPDocEventSubscriber implements Registerable {
protected void onUnregister() {}
@Override public final void register() {
isUnsubscribed = false;
JSONArray params = null;
try {
params = getSubscriptionParams();
......@@ -61,7 +63,11 @@ public abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
ddpClient.subscribe(getSubscriptionName(), params).onSuccess(task -> {
subscriptionId = task.getResult().id;
if (isUnsubscribed) {
ddpClient.unsubscribe(task.getResult().id).continueWith(new LogcatIfError());
} else {
subscriptionId = task.getResult().id;
}
return null;
}).continueWith(task -> {
if (task.isFaulted()) {
......@@ -165,6 +171,7 @@ public abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
@Override public final void unregister() {
isUnsubscribed = true;
onUnregister();
if (rxSubscription != null) {
rxSubscription.unsubscribe();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment