Skip to content

Instantly share code, notes, and snippets.

@AnirudhLoya
Last active August 29, 2015 14:03
Show Gist options
  • Save AnirudhLoya/4614bc46d924f6c2dd3a to your computer and use it in GitHub Desktop.
Save AnirudhLoya/4614bc46d924f6c2dd3a to your computer and use it in GitHub Desktop.
import com.pusher.client.Pusher;
import com.pusher.client.PusherOptions;
import com.pusher.client.channel.PrivateChannelEventListener;
import com.pusher.client.util.HttpAuthorizer;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final Pusher p;
// HttpAuthorizer authorizer = new HttpAuthorizer("http://aded5ec13dfc04048ed0:[email protected]/apps/77220");
HttpAuthorizer authorizer = new HttpAuthorizer("https://sp-stage.herokuapp.com/api/v1/pusher/auth?handle=anirudhloya&token=KsUs-N3M6BN9WGFZ4cPW");
PusherOptions options = new PusherOptions().setAuthorizer(authorizer);
options.setCluster("cu");
// p = new Pusher("aded5ec13dfc04048ed0",options);
p = new Pusher("068b3ebc6412b172feea",options);
p.connect();
// comment this
// p.connect(new ConnectionEventListener() {
//
// @Override
// public void onError(String arg0, String arg1, Exception arg2) {
// // TODO Auto-generated method stub
//
// System.out.print(" "+arg0+" "+arg1+" "+arg2);
//
// }
//
// @Override
// public void onConnectionStateChange(ConnectionStateChange arg0) {
// // TODO Auto-generated method stub
//
// System.out.print("socketId" +p.getConnection().getSocketId());
// String soket =p.getConnection().getSocketId();
// if(soket!=null){
// // postValues(soket,"private-user_28356");
// }
//
// }
// },ConnectionState.ALL);
//
//
// Channel ch =p.subscribe("test_channel");
// ch.bind("my_event", new SubscriptionEventListener() {
//
// @Override
// public void onEvent(String arg0, String arg1, String arg2) {
// // TODO Auto-generated method stub
// System.out.println("event "+arg0+" "+arg1+" "+arg2);
// }
// });
// line 27-60
p.subscribePrivate("private-user_28356",new PrivateChannelEventListener() {
@Override
public void onEvent(String arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
System.out.println("event "+arg0+" "+arg1+" "+arg2);
}
@Override
public void onSubscriptionSucceeded(String arg0) {
// TODO Auto-generated method stub
System.out.println("socketId "+p.getConnection().getSocketId());
}
@Override
public void onAuthenticationFailure(String arg0, Exception arg1) {
// TODO Auto-generated method stub
System.out.println("auth fail "+arg0+" "+arg1);
}
},"boards_changed");
p.disconnect();
System.out.println("connecct");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment