Commit 3827fdf0 authored by Leonardo Aramaki's avatar Leonardo Aramaki

A change of network type will now show a snackbar when a failure occur which...

A change of network type will now show a snackbar when a failure occur which will trigger a websocket reconnection flow
parent 1a4e5808
...@@ -61,11 +61,7 @@ public class DDPClient { ...@@ -61,11 +61,7 @@ public class DDPClient {
return impl.getOnCloseCallback(); return impl.getOnCloseCallback();
} }
public Task<RxWebSocketCallback.Failure> getOnFailureCallback() { public void close() {
return impl.getOnFailureCallback(); impl.close(1000, "closed by DDPClient#close()");
}
public void close(int code, String reason) {
impl.close(code, reason);
} }
} }
...@@ -59,7 +59,7 @@ public class DDPClientImpl { ...@@ -59,7 +59,7 @@ public class DDPClientImpl {
public void connect(final TaskCompletionSource<DDPClientCallback.Connect> task, final String url, public void connect(final TaskCompletionSource<DDPClientCallback.Connect> task, final String url,
String session) { String session) {
try { try {
flowable = websocket.connect(url).autoConnect(); flowable = websocket.connect(url).autoConnect(2);
CompositeDisposable disposables = new CompositeDisposable(); CompositeDisposable disposables = new CompositeDisposable();
disposables.add( disposables.add(
...@@ -125,7 +125,6 @@ public class DDPClientImpl { ...@@ -125,7 +125,6 @@ public class DDPClientImpl {
flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message) flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message)
.map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString) .map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString)
.map(DDPClientImpl::toJson) .map(DDPClientImpl::toJson)
.timeout(4, TimeUnit.SECONDS)
.subscribe( .subscribe(
response -> { response -> {
String msg = extractMsg(response); String msg = extractMsg(response);
...@@ -370,29 +369,14 @@ public class DDPClientImpl { ...@@ -370,29 +369,14 @@ public class DDPClientImpl {
}); });
} }
public Task<RxWebSocketCallback.Failure> getOnFailureCallback() {
TaskCompletionSource<RxWebSocketCallback.Failure> task = new TaskCompletionSource<>();
flowable.filter(callback -> callback instanceof RxWebSocketCallback.Failure)
.cast(RxWebSocketCallback.Failure.class)
.subscribe(
task::setResult,
err -> setTaskError(task, err)
);
return task.getTask().onSuccessTask(_task -> {
unsubscribeBaseListeners();
return _task;
});
}
private boolean sendMessage(String msg, @Nullable JSONBuilder json) { private boolean sendMessage(String msg, @Nullable JSONBuilder json) {
try { try {
JSONObject origJson = new JSONObject().put("msg", msg); JSONObject origJson = new JSONObject().put("msg", msg);
String msg2 = (json == null ? origJson : json.create(origJson)).toString(); String msg2 = (json == null ? origJson : json.create(origJson)).toString();
return websocket.sendText(msg2); websocket.sendText(msg2);
} catch (Exception e) { } catch (Exception e) {
RCLog.e(e); RCLog.e(e);
return false;
} }
return true; // ignore exception here. return true; // ignore exception here.
} }
......
package chat.rocket.android_ddp.rx; package chat.rocket.android_ddp.rx;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
...@@ -18,8 +17,13 @@ import okhttp3.WebSocket; ...@@ -18,8 +17,13 @@ import okhttp3.WebSocket;
import okhttp3.WebSocketListener; import okhttp3.WebSocketListener;
public class RxWebSocket { public class RxWebSocket {
public static final int REASON_CLOSED_BY_USER = 101;
public static final int REASON_NETWORK_ERROR = 102;
public static final int REASON_SERVER_ERROR = 103;
public static final int REASON_UNKNOWN = 104;
private OkHttpClient httpClient; private OkHttpClient httpClient;
private WebSocket webSocket; private WebSocket webSocket;
private boolean hadErrorsBefore;
public RxWebSocket(OkHttpClient client) { public RxWebSocket(OkHttpClient client) {
httpClient = client; httpClient = client;
...@@ -33,6 +37,7 @@ public class RxWebSocket { ...@@ -33,6 +37,7 @@ public class RxWebSocket {
.newWebSocket(request, new WebSocketListener() { .newWebSocket(request, new WebSocketListener() {
@Override @Override
public void onOpen(WebSocket webSocket, Response response) { public void onOpen(WebSocket webSocket, Response response) {
hadErrorsBefore = false;
RxWebSocket.this.webSocket = webSocket; RxWebSocket.this.webSocket = webSocket;
emitter.onNext(new RxWebSocketCallback.Open(RxWebSocket.this.webSocket, response)); emitter.onNext(new RxWebSocketCallback.Open(RxWebSocket.this.webSocket, response));
} }
...@@ -40,10 +45,10 @@ public class RxWebSocket { ...@@ -40,10 +45,10 @@ public class RxWebSocket {
@Override @Override
public void onFailure(WebSocket webSocket, Throwable err, Response response) { public void onFailure(WebSocket webSocket, Throwable err, Response response) {
try { try {
if (err instanceof UnknownHostException) { if (!hadErrorsBefore) {
emitter.onError(err); hadErrorsBefore = true;
} else { emitter.onNext(new RxWebSocketCallback.Close(webSocket, REASON_NETWORK_ERROR, err.getMessage()));
emitter.onNext(new RxWebSocketCallback.Failure(webSocket, err, response)); emitter.onComplete();
} }
} catch (OnErrorNotImplementedException ex) { } catch (OnErrorNotImplementedException ex) {
RCLog.w(ex, "OnErrorNotImplementedException ignored"); RCLog.w(ex, "OnErrorNotImplementedException ignored");
...@@ -71,7 +76,7 @@ public class RxWebSocket { ...@@ -71,7 +76,7 @@ public class RxWebSocket {
} }
}), }),
BackpressureStrategy.BUFFER BackpressureStrategy.BUFFER
).delay(2000, TimeUnit.MILLISECONDS).publish(); ).delay(4, TimeUnit.SECONDS).publish();
} }
public boolean sendText(String message) throws IOException { public boolean sendText(String message) throws IOException {
......
...@@ -16,11 +16,11 @@ import chat.rocket.android.fragment.chatroom.HomeFragment; ...@@ -16,11 +16,11 @@ import chat.rocket.android.fragment.chatroom.HomeFragment;
import chat.rocket.android.fragment.chatroom.RoomFragment; import chat.rocket.android.fragment.chatroom.RoomFragment;
import chat.rocket.android.fragment.sidebar.SidebarMainFragment; import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import chat.rocket.android.helper.KeyboardHelper; import chat.rocket.android.helper.KeyboardHelper;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.core.interactors.CanCreateRoomInteractor; import chat.rocket.core.interactors.CanCreateRoomInteractor;
import chat.rocket.core.interactors.RoomInteractor; import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.persistence.realm.repositories.RealmRoomRepository; import chat.rocket.persistence.realm.repositories.RealmRoomRepository;
import chat.rocket.persistence.realm.repositories.RealmSessionRepository; import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository; import chat.rocket.persistence.realm.repositories.RealmUserRepository;
...@@ -34,6 +34,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -34,6 +34,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
private StatusTicker statusTicker; private StatusTicker statusTicker;
private MainContract.Presenter presenter; private MainContract.Presenter presenter;
private RoomFragment roomFragment;
@Override @Override
protected int getLayoutContainerForFragment() { protected int getLayoutContainerForFragment() {
...@@ -179,7 +180,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -179,7 +180,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
public void showRoom(String hostname, String roomId) { public void showRoom(String hostname, String roomId) {
showFragment(RoomFragment.create(hostname, roomId)); roomFragment = RoomFragment.create(hostname, roomId);
showFragment(roomFragment);
closeSidebarIfNeeded(); closeSidebarIfNeeded();
KeyboardHelper.hideSoftKeyboard(this); KeyboardHelper.hideSoftKeyboard(this);
} }
...@@ -222,6 +224,9 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -222,6 +224,9 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
public void showConnectionOk() { public void showConnectionOk() {
statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null); statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null);
if (roomFragment != null) {
roomFragment.refreshRoom();
}
} }
//TODO: consider this class to define in layouthelper for more complicated operation. //TODO: consider this class to define in layouthelper for more complicated operation.
......
...@@ -20,7 +20,6 @@ import hu.akarnokd.rxjava.interop.RxJavaInterop; ...@@ -20,7 +20,6 @@ import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
public class MainPresenter extends BasePresenter<MainContract.View> public class MainPresenter extends BasePresenter<MainContract.View>
implements MainContract.Presenter { implements MainContract.Presenter {
...@@ -65,6 +64,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -65,6 +64,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
openRoom(); openRoom();
subscribeToNetworkChanges();
subscribeToUnreadCount(); subscribeToUnreadCount();
subscribeToSession(); subscribeToSession();
setUserOnline(); setUserOnline();
...@@ -98,10 +98,8 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -98,10 +98,8 @@ public class MainPresenter extends BasePresenter<MainContract.View>
@Override @Override
public void onRetryLogin() { public void onRetryLogin() {
final Disposable subscription = sessionInteractor.retryLogin() view.showConnecting();
.subscribe(); connectivityManagerApi.keepAliveServer();
addSubscription(subscription);
} }
private void openRoom() { private void openRoom() {
...@@ -161,19 +159,18 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -161,19 +159,18 @@ public class MainPresenter extends BasePresenter<MainContract.View>
); );
addSubscription(subscription); addSubscription(subscription);
}
// Update to RxJava 2 (issue: https://github.com/RocketChat/Rocket.Chat.Android/issues/355) private void subscribeToNetworkChanges() {
addSubscription( Disposable disposable = RxJavaInterop.toV2Flowable(connectivityManagerApi.getServerConnectivityAsObservable())
RxJavaInterop.toV2Observable(connectivityManagerApi.getServerConnectivityAsObservable()) .filter(connectivity -> connectivity.state == ServerConnectivity.STATE_DISCONNECTED)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(serverConnectivity -> { .subscribe(
if (serverConnectivity.state == ServerConnectivity.STATE_CONNECTING) { a -> view.showConnectionError(),
view.showConnecting(); Logger::report
}
},
Logger::report)
); );
addSubscription(disposable);
} }
private void setUserOnline() { private void setUserOnline() {
......
package chat.rocket.android.api; package chat.rocket.android.api;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import io.reactivex.Flowable;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import java.util.UUID; import java.util.UUID;
import bolts.Task; import bolts.Task;
import chat.rocket.android.helper.OkHttpHelper; import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
...@@ -13,6 +14,7 @@ import chat.rocket.android.log.RCLog; ...@@ -13,6 +14,7 @@ import chat.rocket.android.log.RCLog;
import chat.rocket.android_ddp.DDPClient; import chat.rocket.android_ddp.DDPClient;
import chat.rocket.android_ddp.DDPClientCallback; import chat.rocket.android_ddp.DDPClientCallback;
import chat.rocket.android_ddp.DDPSubscription; import chat.rocket.android_ddp.DDPSubscription;
import io.reactivex.Flowable;
/** /**
* DDP client wrapper. * DDP client wrapper.
...@@ -45,8 +47,8 @@ public class DDPClientWrapper { ...@@ -45,8 +47,8 @@ public class DDPClientWrapper {
/** /**
* close connection. * close connection.
*/ */
public void close(int code, String reason) { public void close() {
ddpClient.close(code, reason); ddpClient.close();
} }
/** /**
......
...@@ -49,5 +49,7 @@ public interface RoomContract { ...@@ -49,5 +49,7 @@ public interface RoomContract {
void onUnreadCount(); void onUnreadCount();
void onMarkAsRead(); void onMarkAsRead();
void refreshRoom();
} }
} }
...@@ -21,6 +21,14 @@ import android.support.v7.widget.LinearLayoutManager; ...@@ -21,6 +21,14 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.fernandocejas.arrow.optional.Optional;
import com.jakewharton.rxbinding2.support.v4.widget.RxDrawerLayout;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
...@@ -70,15 +78,10 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository; ...@@ -70,15 +78,10 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository; import chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository; import chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository; import chat.rocket.persistence.realm.repositories.RealmUserRepository;
import com.fernandocejas.arrow.optional.Optional;
import com.jakewharton.rxbinding2.support.v4.widget.RxDrawerLayout;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import permissions.dispatcher.NeedsPermission; import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.RuntimePermissions; import permissions.dispatcher.RuntimePermissions;
...@@ -599,4 +602,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -599,4 +602,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
edittingMessage = message; edittingMessage = message;
messageFormManager.setEditMessage(message.getMessage()); messageFormManager.setEditMessage(message.getMessage());
} }
public void refreshRoom() {
presenter.loadMessages();
}
} }
\ No newline at end of file
...@@ -55,7 +55,11 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -55,7 +55,11 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override @Override
public void bindView(@NonNull RoomContract.View view) { public void bindView(@NonNull RoomContract.View view) {
super.bindView(view); super.bindView(view);
refreshRoom();
}
@Override
public void refreshRoom() {
getRoomRoles(); getRoomRoles();
getRoomInfo(); getRoomInfo();
getRoomHistoryStateInfo(); getRoomHistoryStateInfo();
......
...@@ -32,14 +32,11 @@ import chat.rocket.android.service.observer.NewMessageObserver; ...@@ -32,14 +32,11 @@ import chat.rocket.android.service.observer.NewMessageObserver;
import chat.rocket.android.service.observer.PushSettingsObserver; import chat.rocket.android.service.observer.PushSettingsObserver;
import chat.rocket.android.service.observer.SessionObserver; import chat.rocket.android.service.observer.SessionObserver;
import chat.rocket.android.service.observer.TokenLoginObserver; import chat.rocket.android.service.observer.TokenLoginObserver;
import chat.rocket.android_ddp.DDPClientImpl;
import chat.rocket.core.models.ServerInfo; import chat.rocket.core.models.ServerInfo;
import chat.rocket.persistence.realm.RealmHelper; import chat.rocket.persistence.realm.RealmHelper;
import chat.rocket.persistence.realm.RealmStore; import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.internal.RealmSession; import chat.rocket.persistence.realm.models.internal.RealmSession;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import rx.Single; import rx.Single;
...@@ -68,7 +65,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -68,7 +65,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
private final RealmHelper realmHelper; private final RealmHelper realmHelper;
private final ConnectivityManagerInternal connectivityManager; private final ConnectivityManagerInternal connectivityManager;
private final ArrayList<Registrable> listeners = new ArrayList<>(); private final ArrayList<Registrable> listeners = new ArrayList<>();
private DDPClientWrapper ddpClient; private static DDPClientWrapper ddpClient;
private boolean listenersRegistered; private boolean listenersRegistered;
private RocketChatCache rocketChatCache; private RocketChatCache rocketChatCache;
private DDPClientRef ddpClientRef = new DDPClientRef() { private DDPClientRef ddpClientRef = new DDPClientRef() {
...@@ -157,7 +154,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -157,7 +154,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
return Single.fromEmitter(emitter -> { return Single.fromEmitter(emitter -> {
new Handler(getLooper()).post(() -> { new Handler(getLooper()).post(() -> {
RCLog.d("thread %s: terminated()", Thread.currentThread().getId()); RCLog.d("thread %s: terminated()", Thread.currentThread().getId());
unregisterListeners(); unregisterListenersAndClose();
connectivityManager.notifyConnectionLost(hostname, connectivityManager.notifyConnectionLost(hostname,
ConnectivityManagerInternal.REASON_CLOSED_BY_USER); ConnectivityManagerInternal.REASON_CLOSED_BY_USER);
RocketChatWebSocketThread.super.quit(); RocketChatWebSocketThread.super.quit();
...@@ -206,9 +203,9 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -206,9 +203,9 @@ public class RocketChatWebSocketThread extends HandlerThread {
public void run() { public void run() {
ddpClient.ping().continueWith(task -> { ddpClient.ping().continueWith(task -> {
if (task.isFaulted()) { if (task.isFaulted()) {
RCLog.e(task.getError()); Exception error = task.getError();
RCLog.e(error);
emitter.onSuccess(false); emitter.onSuccess(false);
ddpClient.close(DDPClientImpl.CLOSED_NOT_ALIVE, "Ping timeout");
} else { } else {
keepAliveTimer.update(); keepAliveTimer.update();
emitter.onSuccess(true); emitter.onSuccess(true);
...@@ -248,24 +245,10 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -248,24 +245,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
// handling WebSocket#onClose() callback. // handling WebSocket#onClose() callback.
task.getResult().client.getOnCloseCallback().onSuccess(_task -> { task.getResult().client.getOnCloseCallback().onSuccess(_task -> {
if (listenersRegistered) { ddpClient.close();
terminate();
}
return null;
});
task.getResult().client.getOnFailureCallback().onSuccess(_task -> {
ddpClient = null; ddpClient = null;
CompositeDisposable disposables = new CompositeDisposable(); connectivityManager.notifyConnectionLost(hostname,
connectivityManager.notifyConnecting(hostname); ConnectivityManagerInternal.REASON_NETWORK_ERROR);
disposables.add(
RxJavaInterop.toV2Single(connect().retry())
.observeOn(AndroidSchedulers.from(getLooper()))
.subscribe(
rocketChatWebSocketThread -> forceRegisteringListeners(),
err -> logErrorAndDispose(err, disposables)
)
);
return null; return null;
}); });
...@@ -331,7 +314,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -331,7 +314,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
return new MethodCallHelper(realmHelper, ddpClientRef).getPermissions(); return new MethodCallHelper(realmHelper, ddpClientRef).getPermissions();
} }
//@DebugLog @DebugLog
private void registerListeners() { private void registerListeners() {
if (!Thread.currentThread().getName().equals("RC_thread_" + hostname)) { if (!Thread.currentThread().getName().equals("RC_thread_" + hostname)) {
// execute in Looper. // execute in Looper.
...@@ -340,7 +323,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -340,7 +323,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
} }
if (listenersRegistered) { if (listenersRegistered) {
return; unregisterListeners();
} }
listenersRegistered = true; listenersRegistered = true;
...@@ -355,12 +338,12 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -355,12 +338,12 @@ public class RocketChatWebSocketThread extends HandlerThread {
registrable.register(); registrable.register();
listeners.add(registrable); listeners.add(registrable);
} }
// Register for room stream messages
String roomId = rocketChatCache.getSelectedRoomId(); String roomId = rocketChatCache.getSelectedRoomId();
if (roomId != null) { if (roomId != null) {
StreamRoomMessage streamRoomMessage = new StreamRoomMessage( StreamRoomMessage streamRoomMessage = new StreamRoomMessage(
appContext, hostname, realmHelper, ddpClientRef, roomId); appContext, hostname, realmHelper, ddpClientRef, roomId
);
streamRoomMessage.register(); streamRoomMessage.register();
listeners.add(streamRoomMessage); listeners.add(streamRoomMessage);
} }
...@@ -370,6 +353,15 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -370,6 +353,15 @@ public class RocketChatWebSocketThread extends HandlerThread {
} }
} }
@DebugLog
private void unregisterListenersAndClose() {
unregisterListeners();
if (ddpClient != null) {
ddpClient.close();
ddpClient = null;
}
}
@DebugLog @DebugLog
private void unregisterListeners() { private void unregisterListeners() {
Iterator<Registrable> iterator = listeners.iterator(); Iterator<Registrable> iterator = listeners.iterator();
...@@ -379,9 +371,5 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -379,9 +371,5 @@ public class RocketChatWebSocketThread extends HandlerThread {
iterator.remove(); iterator.remove();
} }
listenersRegistered = false; listenersRegistered = false;
if (ddpClient != null) {
ddpClient.close(DDPClientImpl.CLOSED_NORMALLY, "Closed by client");
ddpClient = null;
}
} }
} }
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