com.pusher.client.channel.impl.PresenceChannelImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pusher-java-client Show documentation
Show all versions of pusher-java-client Show documentation
This is a Java client library for Pusher, targeted at core Java and Android.
package com.pusher.client.channel.impl;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.channel.ChannelEventListener;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.pusher.client.channel.SubscriptionEventListener;
import com.pusher.client.channel.User;
import com.pusher.client.connection.impl.InternalConnection;
import com.pusher.client.util.Factory;
public class PresenceChannelImpl extends PrivateChannelImpl implements PresenceChannel {
private static final String MEMBER_ADDED_EVENT = "pusher_internal:member_added";
private static final String MEMBER_REMOVED_EVENT = "pusher_internal:member_removed";
private static final Gson GSON = new Gson();
private final Map idToUserMap = Collections.synchronizedMap(new LinkedHashMap());
private String myUserID;
public PresenceChannelImpl(final InternalConnection connection, final String channelName,
final Authorizer authorizer, final Factory factory) {
super(connection, channelName, authorizer, factory);
}
/* PresenceChannel implementation */
@Override
public Set getUsers() {
return new LinkedHashSet(idToUserMap.values());
}
@Override
public User getMe() {
return idToUserMap.get(myUserID);
}
/* Base class overrides */
@Override
public void onMessage(final String event, final String message) {
super.onMessage(event, message);
if (event.equals(SUBSCRIPTION_SUCCESS_EVENT)) {
handleSubscriptionSuccessfulMessage(message);
}
else if (event.equals(MEMBER_ADDED_EVENT)) {
handleMemberAddedEvent(message);
}
else if (event.equals(MEMBER_REMOVED_EVENT)) {
handleMemberRemovedEvent(message);
}
}
@Override
@SuppressWarnings("rawtypes")
public String toSubscribeMessage() {
final String authResponse = getAuthResponse();
try {
final Map authResponseMap = GSON.fromJson(authResponse, Map.class);
final String authKey = (String)authResponseMap.get("auth");
final Object channelData = authResponseMap.get("channel_data");
storeMyUserId(channelData);
final Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy