Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnlcox/java-pusher-client
A Java Pusher client library (http://www.pusherapp.com)
https://github.com/johnlcox/java-pusher-client
Last synced: 4 days ago
JSON representation
A Java Pusher client library (http://www.pusherapp.com)
- Host: GitHub
- URL: https://github.com/johnlcox/java-pusher-client
- Owner: johnlcox
- Created: 2012-12-18T03:08:17.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-01-07T15:47:48.000Z (almost 12 years ago)
- Last Synced: 2024-11-05T21:18:11.563Z (about 2 months ago)
- Language: Java
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# java-pusher-client, a Java / Android Pusher Client
[Pusher] (http://www.pusherapp.com) is a push notification service that uses [WebSockets] (http://en.wikipedia.org/wiki/WebSocket) for relaying messages back and forth between clients. This allows real time messaging between a diverse range of applications running on Web browsers, Android devices and now any other place you use Java.
## Examples
### Creating a Pusher Event Listener
PusherListener eventListener = new PusherListener() {
Channel channel;
@Override
public void onConnect(String socketId) {
System.out.println("Pusher connected. Socket Id is: " + socketId);
channel = pusher.subscribe(PUSHER_CHANNEL);
System.out.println("Subscribed to channel: " + channel);
channel.send("client-test", new JSONObject());
channel.bind("price-updated", new ChannelListener() {
@Override
public void onMessage(String message) {
System.out.println("Received bound channel message: " + message);
}
});
}
@Override
public void onMessage(String message) {
System.out.println("Received message from Pusher: " + message);
}
@Override
public void onDisconnect() {
System.out.println("Pusher disconnected.");
}
};
### Connecting to Pusher
Pusher pusher = new Pusher(YOUR_API_KEY);
pusher.setPusherListener(eventListener);
pusher.connect();
### Subscribing to Channels
// Public Channel
channel = pusher.subscribe(PUSHER_CHANNEL);
// Private Channel
channel = pusher.subscribe(PUSHER_CHANNEL, AUTH_TOKEN);
// Presence Channel
channel = pusher.subscribe(PUSHER_CHANNEL, AUTH_TOKEN, USER_ID);
### Triggering Channel Events
channel.send("trigger-event", new JSONObject());
### Binding to Channel Events
channel.bind("price-updated", new ChannelListener() {
@Override
public void onMessage(String message) {
System.out.println("Received bound channel message: " + message);
}
});
## Credits
java-pusher-client uses the [weberknecht] (https://github.com/rbaier/weberknecht) Java WebSockets library by Roderick Baier.
java-pusher-client is largely based on the [JavaPusherClient] (https://github.com/jmschultz/JavaPusherClient) library by Justin Schultz. Project and packages renamed for mavenization.