SelectBlackBerry Presence API Reference for Realtime Apps

 

This SDK has been deprecated.

If you have questions about the PubNub for BlackBerry SDK, please contact us at support@pubnub.com.

Presence enables you to track the online and offline status of users and devices in real time, as well as store custom state information. Presence provides authoritative information on:

  • When a user has joined or left a channel
  • Who, and how many, users are subscribed to a particular channel
  • Which channel(s) an individual user is subscribed to
  • Associated state information for these users

Learn more about our Presence feature here.


Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
You can obtain information about the current state of a channel including a list of unique user-ids currently subscribed to the channel and the total occupancy count of the channel by calling the here_now() function in your application.
To call Here Now you can use the following method(s) in the BlackBerry SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
  2. ParameterTypeRequiredDescription
    statebooleanYesIf set to to true, API response will contain state also. Default is false.
    disable_uuidsbooleanYesIf set to true API won’t returns uuids. Default is false.
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
  3. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    statebooleanYesIf set to to true, API response will contain state also. Default is false.
    disable_uuidsbooleanYesIf set to true API won’t returns uuids. Default is false.
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
Callback callback = new Callback() {
    public void successCallback(String channel, Object response) {
        System.out.println(response.toString());
    }
    public void errorCallback(String channel, PubnubError error) {
        System.out.println(error.toString());
    }
};
pubnub.hereNow("my_channel", callback);
The here_now() function returns a list of uuid s currently subscribed to the channel.
  • uuids:["String","String", ... ,"String"] - List of UUIDs currently subscribed to the channel.
  • occupancy: Number - Total current occupancy of the channel.

{
	occupancy : 4,
	uuids : ['123123234t234f34fq3dq', '143r34f34t34fq34q34q3', '23f34d3f4rq34r34rq23q', 'w34tcw45t45tcw435tww3']
}
  1. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    pubnub.hereNow("my_channel", true, true, callback);
    {
    	"status" : 200,
    	"message" : "OK",
    	"service" : "Presence",
    	"uuids" : [
    		{
    			"uuid" : "myUUID0"
    		},
    		{
    			"state" : {
    				"abcd" : {
    					"age" : 15
    				}
    			},
    			"uuid" : "myUUID1"
    		},
    		{
    			"uuid" : "b9eb408c-bcec-4d34-b4c4-fabec057ad0d"
    		},
    		{
    			"state" : {
    				"abcd" : {
    					"age" : 15
    				}
    			},
    			"uuid" : "myUUID2"
    		},
    		{
    			"state" : {
    				"abcd" : {
    					"age" : 24
    				}
    			},
    			"uuid" : "myUUID9"
    		}
    	],
    	"occupancy" : 5
    }
  2. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    You can return only the occupancy information for a single channel by specifying the channel and setting UUIDs to false:
    pubnub.hereNow("my_channel", false, false, callback);
    {
        "status": 200,
        "message": "OK",
        "payload": {
            "channels": {
                "81d8d989-b95f-443c-a726-04fac323b331": { 
                    "uuids": [ "70fc1140-22b5-4abc-85b2-ff8c17b24d59" ], 
                    "occupancy": 1 
                },
                "81b7a746-d153-49e2-ab70-3037a75cec7e": { 
                    "uuids": [ "91363e7f-584b-49cc-822c-52c2c01e5928" ],
                    "occupancy": 1
                },
                "c068d15e-772a-4bcd-aa27-f920b7a4eaa8": { 
                    "uuids": [ "ccfac1dd-b3a5-4afd-9fd9-db11aeb65395" ],
                    "occupancy": 1
                }
            },
            "total_channels": 3,
            "total_occupancy": 3
        },
        "service": "Presence"
    }
  3. Requires Presence add-on XRequires that the Presence add-on is enabled with Global Here Now checked for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    You can return the list of UUIDs and occupancy for all channels by omitting the channel:
    pubnub.hereNow(false, true, callback);
    {
        "total_channels" : 2,
        "total_occupancy" : 3,
        "channels" : {
            "lobby" : {
                "occupancy" : 1,
                "uuids" : [
                    "dara01"
                ]
            },
            "game01" : {
                "occupancy" : 2,
                "uuids" : [
                    "jason01",
                    "jason02"
                ]
            }
        }
    }
  4. Requires Presence add-on XRequires that the Presence add-on is enabled with Global Here Now checked for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    You can return only the occupancy information (Global Here Now) by omitting the channel name
    pubnub.hereNow(true, true, new Callback() {
        @Override
        public void successCallback(String channel, Object message) {
            notifyUser("HERE NOW : " + message);
        }
    
        @Override
        public void errorCallback(String channel, PubnubError error) {
            notifyUser("HERE NOW : " + error);
        }
    });
    {
        "status": 200,
        "message": "OK",
        "payload": {
            "channels": {
                "81d8d989-b95f-443c-a726-04fac323b331": { 
                    "uuids": [ "70fc1140-22b5-4abc-85b2-ff8c17b24d59" ], 
                    "occupancy": 1 
                },
                "81b7a746-d153-49e2-ab70-3037a75cec7e": { 
                    "uuids": [ "91363e7f-584b-49cc-822c-52c2c01e5928" ],
                    "occupancy": 1
                },
                "c068d15e-772a-4bcd-aa27-f920b7a4eaa8": { 
                    "uuids": [ "ccfac1dd-b3a5-4afd-9fd9-db11aeb65395" ],
                    "occupancy": 1
                }
            },
            "total_channels": 3,
            "total_occupancy": 3
        },
        "service": "Presence"
    }
Return Occupancy for all channels by calling the hereNow function in your application.
To call Global Here Now you can use the following method(s) in the BlackBerry SDK:
  1. You can call Global Here Now by using the same method as Here Now
pubnub.hereNow(true, true, new Callback() {
    @Override
    public void successCallback(String channel, Object message) {
        notifyUser("HERE NOW : " + message);
    }

    @Override
    public void errorCallback(String channel, PubnubError error) {
        notifyUser("HERE NOW : " + error);
    }
});

{
	"status": 200,
	"message": "OK",
	"payload": {
		"channels": {
			"81d8d989-b95f-443c-a726-04fac323b331": {
				"uuids": [
					"70fc1140-22b5-4abc-85b2-ff8c17b24d59"
				],
				"occupancy": 1
			},
			"81b7a746-d153-49e2-ab70-3037a75cec7e": {
				"uuids": [
					"91363e7f-584b-49cc-822c-52c2c01e5928"
				],
				"occupancy": 1
			},
			"c068d15e-772a-4bcd-aa27-f920b7a4eaa8": {
				"uuids": [
					"ccfac1dd-b3a5-4afd-9fd9-db11aeb65395"
				],
				"occupancy": 1
			}
		},
		"total_channels": 3,
		"total_occupancy": 3
	},
	"service": "Presence"
}

Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
You can obtain information about the current list of channels to which a UUID is subscribed to by calling the whereNow() function in your application.
 
If the app is killed/crashes and restarted (or the page containing the PubNub instance is refreshed on the browser) within the heartbeat window no timeout event is generated.
To call whereNow() you can use the following method(s) in the BlackBerry SDK:
  1. ParameterTypeRequiredDescription
    uuidStringYesSpecifies uuid for which current subscribed channels info is required
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
  2. ParameterTypeRequiredDescription
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
You simply need to define the uuid and the callback function to be used to send the data to as in the example below.
Callback callback = new Callback() {
    public void successCallback(String channel, Object response) {
        System.out.println(response.toString());
    }
    public void errorCallback(String channel, PubnubError error) {
        System.out.println(error.toString());
    }
};
pubnub.whereNow("my_uuid", callback);
The whereNow() function returns a list of channels a uuid is subscribed to.
  • channels:["String","String", ... ,"String"] - List of channels a uuid is subscribed to.

{
	"channels": [
		"lobby",
		"game01",
		"chat"
	]
}

Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
The state API is used to set/get key/value pairs specific to a subscriber uuid.
State information is supplied as a JSON object of key/value pairs.
  1. ParameterTypeRequiredDescription
    channelStringYesChannel
    uuidStringYesUUID
    stateJSONObjectYesstate
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback
  1. ParameterTypeRequiredDescription
    channelStringYesChannel
    uuidStringYesUUID
    callbackCallbackYesAn object of Callback class which contains successCallback and errorCallback.
Callback callback = new Callback() {
  public void successCallback(String channel, Object response) {
    System.out.println(response.toString());
  }
  public void errorCallback(String channel, PubnubError error) {
	System.out.println(error.toString());
  }
};
JSONObject jso = new JSONObject();
jso.put("Key","Value");
pubnub.setState("my_channel", "jbonham", jso, callback);
Callback callback = new Callback() {
  public void successCallback(String channel, Object response) {
    System.out.println(response.toString());
  }
  public void errorCallback(String channel, PubnubError error) {
	System.out.println(error.toString());
  }
};

pubnub.getState("my_channel", "my_uuid", callback);
The state API returns a JSON object containing key value pairs.

{
	first   : "Robert",
	last    : "Plant",
	age     : 59,
	region  : "UK"
}
The state API is used to get or set key/value pairs specific to a subscriber uuid.
State information is supplied as a JSON object of key/value pairs.
To Set State you can use the following method(s) in the BlackBerry SDK
  1. ParameterTypeRequiredDescription
    group
    String
    Yes
    A single channel group to set state on
    uuid
    String
    Yes
    UUID to set state on.
    state
    JSONObject
    Yes
    A single level state JSON object
    callback
    Callback
    Yes
    An object of Callback class which contains successCallback and errorCallback
JSONObject jso = new JSONObject();
jso.put("Key", "Value");
pubnub.channelGroupSetState("my_group", "jbonham", jso, callback);
The state API returns a JSON object containing key value pairs.

{
	first   : "Robert",
	last    : "Plant",
	age     : 59,
	region  : "UK"
}