Skip to content

chabokpush/chabok-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Chabok Push for Java

Blow some breath to your app with Chabok realtime messaging and receive push notifications cross any platform with zero code. Know your users's better, push them content based on their location or track their presence/location withoud headache.

Usage

Create chabok account and use chabok credential keys in setting page of sandbox or production panel to init method.

Initialize

import com.chabokpush.*;

ChabokClient chabok = new ChabokClient(  
        APP_ID,  //Sandbox or Production environment APP_ID
        API_KEY, //Sandbox or Production environment API_KEY
        USERNAME,//Sandbox or Production environment USERNAME
        PASSWORD //Sandbox or Production environment PASSWORD
);

Environment

To change chabok enviroment (Sandbox or Production) use setDevelopment method.

chabok.setDevelopment(true);

Callback

chabok.setCallback(new ChabokCallback(){  
	@Override  
	public void onConnectError(Throwable cause) {  
		System.err.println("ConnectError " + cause);  
	}  
  
	@Override  
	public void onConnect() {  
		System.out.println("Connected to chabok");  
	}  
  
	@Override  
	public void onDisconnect(Throwable cause) {  
		System.out.println("Disconnected " + cause);  
	}  
  
	@Override  
	public void onMessage(PushMessage message) {  
		System.out.println("Got message: " + message.toJson());  
	}
	
	@Override  
	public void onEvent(EventMessage eventMessage) {  
		System.out.println("Got event: " + eventMessage);  
	}  
});

Connect

For connecting to the chabok use connect method

chabok.connect("NODE_ID");

Publish

Publish message

PushMessage message = new PushMessage();  
message.setUser("*");  //Require, For public channel use *
message.setChannel("CHANNEL_NAME");  //Optional, Channel name.
message.setBody("Hello world..."); //Require.
  
chabok.publish(message, new Callback() {  
    @Override  
  public void onSuccess(Object value) {  
        System.out.println("Published successfully");  
  }  
  
    @Override  
  public void onFailure(Throwable value) {  
		System.err.println("Fail to publish message");  
  }  
});

Publish event

JSONObject data = new JSONObject();  

//Custom data
data.put("tripId", 123456);  
data.put("lat",54.2222);  
data.put("lng", 32.222);  
  
chabok.publishEvent("shareTrip", data, new Callback() {  
    @Override  
	public void onSuccess(Object value) {  
        System.out.println("Published event successfully");  
	}  
  
    @Override  
	public void onFailure(Throwable value) {  
        System.err.println("Fail to publish event");  
	}  
});

Channel

Subscribe

chabok.subscribe("private/default", new Callback() {  
    @Override  
	public void onSuccess(Object value) {  
		System.out.println("Subscribe on default channel");  
	}  
  
    @Override  
	public void onFailure(Throwable value) {  
        System.err.println("Couldn't subscribe on channel");  
	}  
});

Unsubscribe

chabok.unsubscribe("private/default", new Callback() {  
    @Override  
	public void onSuccess(Object value) {  
        System.out.println("Unsubscribe to default channel");  
	}  
  
    @Override  
	public void onFailure(Throwable value) {  
        System.err.println("Couldn't unsubscribe on channel");  
	}  
});

Event

Subscribe on event

chabok.subscribeEvent("shareTrip", new Callback() {  
    @Override  
	public void onSuccess(Object value) {  
        System.out.println("Subscribe on shareTrip event");  
	}  
  
    @Override  
	public void onFailure(Throwable value) {  
        System.err.println("Couldn't subscribe on shareTrip event");  
	}  
});

Unsubscribe to event

chabok.unsubscribeEvent("shareTrip", new Callback() {  
    @Override  
	public void onSuccess(Object value) {  
        System.out.println("Unsubscribe to shareTrip event");  
	}  
  
    @Override  
	public void onFailure(Throwable value) {  
        System.err.println("Couldn't unsubscribe on event");  
	}  
});

Support

Please visit Issues.

About

Chabok Push server side SDK for Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published