Skip to content

Commit 2f42899

Browse files
committed
Updated subscription count to be handled by renaming
1 parent 5b2f9e3 commit 2f42899

File tree

7 files changed

+8
-54
lines changed

7 files changed

+8
-54
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,16 @@ Channel channel = pusher.subscribe("my-channel", new ChannelEventListener() {
257257
// Other ChannelEventListener methods
258258
});
259259
```
260-
If you wish to be informed for subscription count events, pass an implementation of the `ChannelEventListener` interface:
260+
If you wish to be informed for subscription count events, use the `bind` function to listen to event type `pusher:subscription_count`:
261261

262262
```java
263-
Channel channel = pusher.subscribe("my-channel", new ChannelEventListener() {
263+
Channel channel = pusher.subscribe("my-channel");
264+
channel.bind("pusher:subscription_count", new SubscriptionEventListener() {
264265
@Override
265-
public void onSubscriptionCountChanged(String channelName, int count) {
266-
System.out.println("Members in channel: " + channelName + " are: " + count);
266+
public void onEvent(PusherEvent event) {
267+
System.out.println("Received event with data: " + event.toString());
268+
System.out.println("Subscription Count is: " + channel.getCount());
267269
}
268-
269-
// Other ChannelEventListener methods
270270
});
271271

272272
```

src/main/java/com/pusher/client/channel/ChannelEventListener.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,4 @@ public interface ChannelEventListener extends SubscriptionEventListener {
4040
* The name of the channel that was successfully subscribed.
4141
*/
4242
void onSubscriptionSucceeded(String channelName);
43-
44-
/**
45-
* <p>
46-
* Callback fired when a subscription success count
47-
* of a channel changes
48-
* </p>
49-
*
50-
*
51-
* @param channelName
52-
* The name of the channel for which the count changed.
53-
*
54-
* @param count
55-
* The latest count of subscribers on the channel.
56-
*/
57-
void onSubscriptionCountChanged(String channelName, int count);
5843
}

src/main/java/com/pusher/client/channel/impl/BaseChannel.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class BaseChannel implements InternalChannel {
1919
private static final String INTERNAL_EVENT_PREFIX = "pusher_internal:";
2020
protected static final String SUBSCRIPTION_SUCCESS_EVENT = "pusher_internal:subscription_succeeded";
2121
protected static final String SUBSCRIPTION_COUNT_EVENT = "pusher_internal:subscription_count";
22+
protected static final String PUBLIC_SUBSCRIPTION_COUNT_EVENT = "pusher:subscription_count";
2223
private Set<SubscriptionEventListener> globalListeners = new HashSet<SubscriptionEventListener>();
2324
private final Map<String, Set<SubscriptionEventListener>> eventNameToListenerMap = new HashMap<String, Set<SubscriptionEventListener>>();
2425
protected volatile ChannelState state = ChannelState.INITIAL;
@@ -194,17 +195,9 @@ private void validateArguments(final String eventName, final SubscriptionEventLi
194195
}
195196

196197
private void handleSubscriptionCountEvent(final String message) {
197-
String channelName = getName();
198198
final SubscriptionCountData subscriptionCountMessage = GSON.fromJson(message, SubscriptionCountData.class);
199199
subscriptionCount = subscriptionCountMessage.getCount();
200-
if (eventListener != null ) {
201-
factory.queueOnEventThread(new Runnable() {
202-
@Override
203-
public void run() {
204-
eventListener.onSubscriptionCountChanged(channelName, subscriptionCountMessage.getCount());
205-
}
206-
});
207-
}
200+
onMessage(PUBLIC_SUBSCRIPTION_COUNT_EVENT, message);
208201
}
209202

210203
protected Set<SubscriptionEventListener> getInterestedListeners(String event) {

src/main/java/com/pusher/client/example/ExampleApp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ public void onEvent(PusherEvent event) {
7878
System.out.println(String.format(
7979
"Received event [%s]", event.toString()));
8080
}
81-
82-
@Override
83-
public void onSubscriptionCountChanged(String channelName, int count) {
84-
System.out.println(String.format(
85-
"Count for channel [%s], changed to [%d]", channelName, count));
86-
}
8781
};
8882

8983
// subscribe to the channel and with the event listener for the event name

src/main/java/com/pusher/client/example/PresenceChannelExampleApp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ public void userUnsubscribed(String channelName, User user) {
115115
System.out.println(String.format("A user has left channel [%s]: %s", channelName, user));
116116
printCurrentlySubscribedUsers();
117117
}
118-
119-
@Override
120-
public void onSubscriptionCountChanged(String channelName, int count) {
121-
System.out.println(String.format(
122-
"Count for channel [%s], changed to [%d]", channelName, count));
123-
}
124118
};
125119

126120
// subscribe to the channel and with the event listener for the event name

src/main/java/com/pusher/client/example/PrivateChannelExampleApp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ public void onAuthenticationFailure(String message, Exception e) {
9494
System.out.println(String.format(
9595
"Authorization failure due to [%s], exception was [%s]", message, e));
9696
}
97-
98-
@Override
99-
public void onSubscriptionCountChanged(String channelName, int count) {
100-
System.out.println(String.format(
101-
"Count for channel [%s], changed to [%d]", channelName, count));
102-
}
10397
};
10498

10599
// subscribe to the channel and with the event listener for the event name

src/main/java/com/pusher/client/example/PrivateEncryptedChannelExampleApp.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ public void onDecryptionFailure(String event, String reason) {
106106
System.out.println(String.format(
107107
"An error was received decrypting message for event:[%s] - reason: [%s]", event, reason));
108108
}
109-
110-
@Override
111-
public void onSubscriptionCountChanged(String channelName, int count) {
112-
System.out.println(String.format(
113-
"Count for channel [%s], changed to [%d]", channelName, count));
114-
}
115109
};
116110

117111
// subscribe to the channel and with the event listener for the event name

0 commit comments

Comments
 (0)