Skip to content

Commit

Permalink
Fix fast disconnect/reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
NaikSoftware committed Aug 3, 2018
1 parent 4428c5d commit 51aaec4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ abstract class AbstractConnectionProvider implements ConnectionProvider {
@NonNull
@Override
public Observable<String> messages() {
Log.d(TAG, "messages()");
return mMessagesStream.startWith(initSocket().toObservable());
}

Expand All @@ -52,7 +51,6 @@ public Completable disconnect() {
}

private Completable initSocket() {
Log.d(TAG, "innitSocket");
return Completable
.fromAction(this::createWebSocketConnection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void rawDisconnect() {

@Override
void createWebSocketConnection() {
Log.d(TAG, "createWebSocketConnection");
Request.Builder requestBuilder = new Request.Builder()
.url(mUri);

Expand All @@ -56,7 +55,6 @@ void createWebSocketConnection() {
new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, @NonNull Response response) {
Log.d(TAG, "onOpen");
LifecycleEvent openEvent = new LifecycleEvent(LifecycleEvent.Type.OPENED);

TreeMap<String, String> headersAsMap = headersAsMap(response);
Expand All @@ -80,29 +78,27 @@ public void onMessage(WebSocket webSocket, @NonNull ByteString bytes) {

@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
Log.d(TAG, "onClosed (nullify socket)");
if (webSocket != openedSocked) return;
openedSocked = null;
emitLifecycleEvent(new LifecycleEvent(LifecycleEvent.Type.CLOSED));
}

@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
if (webSocket != openedSocked) return;
// in OkHttp, a Failure is equivalent to a JWS-Error *and* a JWS-Close
Log.d(TAG, "onFailure (nullify socket)");
emitLifecycleEvent(new LifecycleEvent(LifecycleEvent.Type.ERROR, new Exception(t)));
openedSocked = null;
emitLifecycleEvent(new LifecycleEvent(LifecycleEvent.Type.CLOSED));
}

@Override
public void onClosing(final WebSocket webSocket, final int code, final String reason) {
Log.d(TAG, "onClosing");
webSocket.close(code, reason);
}
}

);
Log.d(TAG, "Socket inited " + openedSocked);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void connect(@Nullable List<StompHeader> _headers) {
.subscribe(lifecycleEvent -> {
switch (lifecycleEvent.getType()) {
case OPENED:
Log.d(TAG, "Socket connected, send connect command to stomp");
List<StompHeader> headers = new ArrayList<>();
headers.add(new StompHeader(StompHeader.VERSION, SUPPORTED_VERSIONS));
headers.add(new StompHeader(StompHeader.HEART_BEAT, "0," + heartbeat));
Expand All @@ -136,7 +135,6 @@ public void connect(@Nullable List<StompHeader> _headers) {
}
});

Log.d(TAG, "Subscribe to messages for create connection");
isConnecting = true;
mMessagesDisposable = mConnectionProvider.messages()
.map(StompMessage::from)
Expand Down

0 comments on commit 51aaec4

Please sign in to comment.