imToken v2.14.1版本的 MD5 值为:83050b2c91219b46832c8336279e7878
以下内容为反编译后的 PresenceChannelExampleApp.java 源代码,内容仅作参考
package com.pusher.client.example;
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.pusher.client.channel.PresenceChannel;
import com.pusher.client.channel.PresenceChannelEventListener;
import com.pusher.client.channel.PusherEvent;
import com.pusher.client.channel.SubscriptionEventListener;
import com.pusher.client.channel.User;
import com.pusher.client.connection.ConnectionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.ConnectionStateChange;
import com.pusher.client.util.HttpAuthorizer;
import java.util.Set;
import org.koin.core.instance.InstanceFactory;
public class PresenceChannelExampleApp {
private String authorizationEndpoint = "http://localhost:3030/pusher/auth";
private final PresenceChannel channel;
private String channelName;
private String channelsKey;
private String cluster;
private String eventName;
public static void main(String[] strArr) {
new PresenceChannelExampleApp(strArr);
}
private PresenceChannelExampleApp(String[] strArr) {
this.channelsKey = "FILL_ME_IN";
this.channelName = "my-channel";
this.eventName = "my-event";
this.cluster = "eu";
int length = strArr.length;
if (length != 1) {
if (length != 2) {
if (length != 3) {
if (length == 4) {
this.cluster = strArr[3];
}
Pusher pusher = new Pusher(this.channelsKey, new PusherOptions().setUseTLS(true).setCluster(this.cluster).setAuthorizer(new HttpAuthorizer("http://localhost:3030/pusher/auth")));
pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
System.out.println(String.format("Connection state changed from [%s] to [%s]", connectionStateChange.getPreviousState(), connectionStateChange.getCurrentState()));
}
@Override
public void onError(String str, String str2, Exception exc) {
System.out.println(String.format("An error was received with message [%s], code [%s], exception [%s]", str, str2, exc));
}
}, new ConnectionState[0]);
this.channel = pusher.subscribePresence(this.channelName, new PresenceChannelEventListener() {
@Override
public void onError(String str, Exception exc) {
SubscriptionEventListener.CC.$default$onError(this, str, exc);
}
@Override
public void onSubscriptionSucceeded(String str) {
System.out.println(String.format("Subscription to channel [%s] succeeded", str));
}
@Override
public void onEvent(PusherEvent pusherEvent) {
System.out.println(String.format("Received event [%s]", pusherEvent.toString()));
}
@Override
public void onAuthenticationFailure(String str, Exception exc) {
System.out.println(String.format("Authentication failure due to [%s], exception was [%s]", str, exc));
}
@Override
public void onUsersInformationReceived(String str, Set<User> set) {
System.out.println("Received user information");
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
@Override
public void userSubscribed(String str, User user) {
System.out.println(String.format("A new user has joined channel [%s]: %s", str, user.toString()));
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
@Override
public void userUnsubscribed(String str, User user) {
System.out.println(String.format("A user has left channel [%s]: %s", str, user));
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
}, this.eventName);
while (true) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
}
}
this.eventName = strArr[2];
}
this.channelName = strArr[1];
}
this.channelsKey = strArr[0];
Pusher pusher2 = new Pusher(this.channelsKey, new PusherOptions().setUseTLS(true).setCluster(this.cluster).setAuthorizer(new HttpAuthorizer("http://localhost:3030/pusher/auth")));
pusher2.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
System.out.println(String.format("Connection state changed from [%s] to [%s]", connectionStateChange.getPreviousState(), connectionStateChange.getCurrentState()));
}
@Override
public void onError(String str, String str2, Exception exc) {
System.out.println(String.format("An error was received with message [%s], code [%s], exception [%s]", str, str2, exc));
}
}, new ConnectionState[0]);
this.channel = pusher2.subscribePresence(this.channelName, new PresenceChannelEventListener() {
@Override
public void onError(String str, Exception exc) {
SubscriptionEventListener.CC.$default$onError(this, str, exc);
}
@Override
public void onSubscriptionSucceeded(String str) {
System.out.println(String.format("Subscription to channel [%s] succeeded", str));
}
@Override
public void onEvent(PusherEvent pusherEvent) {
System.out.println(String.format("Received event [%s]", pusherEvent.toString()));
}
@Override
public void onAuthenticationFailure(String str, Exception exc) {
System.out.println(String.format("Authentication failure due to [%s], exception was [%s]", str, exc));
}
@Override
public void onUsersInformationReceived(String str, Set<User> set) {
System.out.println("Received user information");
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
@Override
public void userSubscribed(String str, User user) {
System.out.println(String.format("A new user has joined channel [%s]: %s", str, user.toString()));
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
@Override
public void userUnsubscribed(String str, User user) {
System.out.println(String.format("A user has left channel [%s]: %s", str, user));
PresenceChannelExampleApp.this.printCurrentlySubscribedUsers();
}
}, this.eventName);
while (true) {
Thread.sleep(1000L);
}
}
public void printCurrentlySubscribedUsers() {
StringBuilder sb = new StringBuilder("Users now subscribed to the channel:");
for (User user : this.channel.getUsers()) {
sb.append(InstanceFactory.ERROR_SEPARATOR);
sb.append(user.toString());
if (user.equals(this.channel.getMe())) {
sb.append(" (me)");
}
}
System.out.println(sb.toString());
}
}