Skip to content

Commit 6c58850

Browse files
authored
Merge pull request #32 from SarojMaharjan/master
Solution for issue #19
2 parents 7fc11fa + 6e6c8ea commit 6c58850

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

.idea/markdown-navigator/profiles_settings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.util.Log;
44

55
import java.util.ArrayList;
6-
import java.util.Arrays;
76
import java.util.Collections;
87
import java.util.HashMap;
98
import java.util.HashSet;
@@ -157,7 +156,7 @@ public Observable<StompMessage> topic(String destinationPath, List<StompHeader>
157156
if (subscribersSet == null) {
158157
subscribersSet = new HashSet<>();
159158
mSubscribers.put(destinationPath, subscribersSet);
160-
subscribePath(destinationPath, headerList);
159+
subscribePath(destinationPath, headerList).subscribe();
161160
}
162161
subscribersSet.add(subscriber);
163162

@@ -169,16 +168,16 @@ public Observable<StompMessage> topic(String destinationPath, List<StompHeader>
169168
set.remove(subscriber);
170169
if (set.size() < 1) {
171170
mSubscribers.remove(dest);
172-
unsubscribePath(dest);
171+
unsubscribePath(dest).subscribe();
173172
}
174173
}
175174
}
176175
}
177176
});
178177
}
179178

180-
private void subscribePath(String destinationPath, List<StompHeader> headerList) {
181-
if (destinationPath == null) return;
179+
private Observable<Void> subscribePath(String destinationPath, List<StompHeader> headerList) {
180+
if (destinationPath == null) return Observable.empty();
182181
String topicId = UUID.randomUUID().toString();
183182

184183
if (mTopics == null) mTopics = new HashMap<>();
@@ -188,16 +187,16 @@ private void subscribePath(String destinationPath, List<StompHeader> headerList)
188187
headers.add(new StompHeader(StompHeader.DESTINATION, destinationPath));
189188
headers.add(new StompHeader(StompHeader.ACK, DEFAULT_ACK));
190189
if (headerList != null) headers.addAll(headerList);
191-
send(new StompMessage(StompCommand.SUBSCRIBE,
190+
return send(new StompMessage(StompCommand.SUBSCRIBE,
192191
headers, null));
193192
}
194193

195194

196-
private void unsubscribePath(String dest) {
195+
private Observable<Void> unsubscribePath(String dest) {
197196
String topicId = mTopics.get(dest);
198197
Log.d(TAG, "Unsubscribe path: " + dest + " id: " + topicId);
199198

200-
send(new StompMessage(StompCommand.UNSUBSCRIBE,
199+
return send(new StompMessage(StompCommand.UNSUBSCRIBE,
201200
Collections.singletonList(new StompHeader(StompHeader.ID, topicId)), null));
202201
}
203202

0 commit comments

Comments
 (0)