You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there! I found some incorrect behavior of presence channels after restore connection to channel.
Problem step-by-step:
Connect to presence channel two or more users
Go to in background - pusher disconnected
Other users quit from channel
Go to in foreground - pusher connected - we resubscribe to channel
On onUsersInformationReceived we got old data of users in channel
Notate: Swift SDK has workaround with subscribing on "pusher:subscription_succeeded" and process this event separate from flow logic. In Java SDK we don't have such trick...
In PresenceChannelImpl when channel successfully subscribed we got event SUBSCRIPTION_SUCCESS_EVENT = "pusher_internal:subscription_succeeded" with processing in internal channel body and after that call onUsersInformationReceived for self interface.
Problem in idToUserMap map witch need to clear in this case, because if i'm not wrong with SUBSCRIPTION_SUCCESS_EVENT we getting actual data about users in presence channel but in current realisation we lost users who quit from channel while i was unsubscibed.
Debug of this point shown that problem exist - channel got json with 1 user but idToUserMap not cleared and return wrong users data
...
Is it a crash report? Submit stack traces or anything that you think would help
#class PresenceChannelImpl
@SuppressWarnings({ "rawtypes", "unchecked" })
private void handleSubscriptionSuccessfulMessage(final String message) {
final ChannelEventListener listener = getEventListener();
// extract data from the JSON message
final PresenceData presenceData = extractPresenceDataFrom(message);
if (presenceData == null) {
if (listener != null) {
listener.onError(
"Subscription failed: Presence data not found",
null
);
}
return;
}
final List<String> ids = presenceData.ids;
final Map<String, Object> hash = presenceData.hash;
if (ids != null && !ids.isEmpty()) {
// build the collection of Users
for (final String id : ids) {
final String userData = hash.get(id) != null ? GSON.toJson(hash.get(id)) : null;
final User user = new User(id, userData);
idToUserMap.put(id, user); <--- Problem - is not empty. Suggestion: need clear before process users data
}
}
if (listener != null) {
final PresenceChannelEventListener presenceListener = (PresenceChannelEventListener)listener;
presenceListener.onUsersInformationReceived(getName(), getUsers());
}
}
...
Any improvements you suggest
In this case clear idToUserMap before process users data. I may be wrong, then tell me the correct scenario for working with this type of channels
...
CC @pusher/mobile
The text was updated successfully, but these errors were encountered:
I've not been able to replicate this - upon reconnection my app receives the correct presence information. Do you have a small replication app available?
Sorry, but i haven't. NDA etc... :( I can only share debug screen fro this situation
with this debug, it is already clear that one user comes in, and in the map there are two. I don’t see any code for clearing the map, so the result will not be correct. actual data = 1 user, and the channel will return 2
UPD: I checked that handleMemberAddedEvent didn't call in that case, so idToUserMap not modified by that method
What is the issue?
Hello there! I found some incorrect behavior of presence channels after restore connection to channel.
Problem step-by-step:
Notate: Swift SDK has workaround with subscribing on "pusher:subscription_succeeded" and process this event separate from flow logic. In Java SDK we don't have such trick...
In PresenceChannelImpl when channel successfully subscribed we got event SUBSCRIPTION_SUCCESS_EVENT = "pusher_internal:subscription_succeeded" with processing in internal channel body and after that call onUsersInformationReceived for self interface.
Problem in idToUserMap map witch need to clear in this case, because if i'm not wrong with SUBSCRIPTION_SUCCESS_EVENT we getting actual data about users in presence channel but in current realisation we lost users who quit from channel while i was unsubscibed.
Debug of this point shown that problem exist - channel got json with 1 user but idToUserMap not cleared and return wrong users data
...
Is it a crash report? Submit stack traces or anything that you think would help
...
Any improvements you suggest
In this case clear idToUserMap before process users data. I may be wrong, then tell me the correct scenario for working with this type of channels
...
CC @pusher/mobile
The text was updated successfully, but these errors were encountered: