Skip to content

Commit 51aaec4

Browse files
committed
Fix fast disconnect/reconnect
1 parent 4428c5d commit 51aaec4

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

lib/src/main/java/ua/naiksoftware/stomp/AbstractConnectionProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ abstract class AbstractConnectionProvider implements ConnectionProvider {
3131
@NonNull
3232
@Override
3333
public Observable<String> messages() {
34-
Log.d(TAG, "messages()");
3534
return mMessagesStream.startWith(initSocket().toObservable());
3635
}
3736

@@ -52,7 +51,6 @@ public Completable disconnect() {
5251
}
5352

5453
private Completable initSocket() {
55-
Log.d(TAG, "innitSocket");
5654
return Completable
5755
.fromAction(this::createWebSocketConnection);
5856
}

lib/src/main/java/ua/naiksoftware/stomp/OkHttpConnectionProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void rawDisconnect() {
4646

4747
@Override
4848
void createWebSocketConnection() {
49-
Log.d(TAG, "createWebSocketConnection");
5049
Request.Builder requestBuilder = new Request.Builder()
5150
.url(mUri);
5251

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

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

8179
@Override
8280
public void onClosed(WebSocket webSocket, int code, String reason) {
83-
Log.d(TAG, "onClosed (nullify socket)");
81+
if (webSocket != openedSocked) return;
8482
openedSocked = null;
8583
emitLifecycleEvent(new LifecycleEvent(LifecycleEvent.Type.CLOSED));
8684
}
8785

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

9795
@Override
9896
public void onClosing(final WebSocket webSocket, final int code, final String reason) {
99-
Log.d(TAG, "onClosing");
10097
webSocket.close(code, reason);
10198
}
10299
}
103100

104101
);
105-
Log.d(TAG, "Socket inited " + openedSocked);
106102
}
107103

108104
@Override

lib/src/main/java/ua/naiksoftware/stomp/client/StompClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public void connect(@Nullable List<StompHeader> _headers) {
113113
.subscribe(lifecycleEvent -> {
114114
switch (lifecycleEvent.getType()) {
115115
case OPENED:
116-
Log.d(TAG, "Socket connected, send connect command to stomp");
117116
List<StompHeader> headers = new ArrayList<>();
118117
headers.add(new StompHeader(StompHeader.VERSION, SUPPORTED_VERSIONS));
119118
headers.add(new StompHeader(StompHeader.HEART_BEAT, "0," + heartbeat));
@@ -136,7 +135,6 @@ public void connect(@Nullable List<StompHeader> _headers) {
136135
}
137136
});
138137

139-
Log.d(TAG, "Subscribe to messages for create connection");
140138
isConnecting = true;
141139
mMessagesDisposable = mConnectionProvider.messages()
142140
.map(StompMessage::from)

0 commit comments

Comments
 (0)