GithubHelp home page GithubHelp logo

javapusherclient's Introduction

JavaPusherClient, a Java / Android Pusher Client

Web Site: Public Static Droid Main

[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

JavaPusherClient uses the [weberknecht] (https://github.com/rbaier/weberknecht) Java WebSockets library by Roderick Baier.

javapusherclient's People

Contributors

murphjm avatar dwightgunning avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.