SelectMono-for-Linux Presence API Reference for Realtime Apps

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 Mono for Linux SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    showUUIDListboolYesIf set to false API won't returns uuids.

    Default is true.
    includeUserStateboolYesIf set to to true, API response will contain state also.

    Default is false.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel for which to return active uuids.
    showUUIDListboolYesIf set to false API won't returns uuids.

    Default is true.
    includeUserStateboolYesIf set to to true, API response will contain state also.

    Default is false.
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
pubnub.HereNow <string>(
    "my_channel",
    DisplayReturnMessage,
    DisplayErrorMessage
);
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(channel, false, true, userCallback, errorCallback);
    {
    	"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<string>(channel, userCallback, errorCallback);
    {
        "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(channel, false, false, userCallback, errorCallback);
    {
        "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.GlobalHereNow<string>(
        true, true,
        DisplayReturnMessage,
        DisplayErrorMessage
    );
    {
        "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 GlobalHereNow function in your application.
To call Global Here Now you can use the following method(s) in the Mono for Linux SDK:
  1. ParameterTypeRequiredDescription
    showUUIDListboolYesIf set to false API won't returns uuids. Default is true.
    includeUserStateboolYesIf set to to true, API response will contain state also. Default is false.
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    showUUIDListboolYesIf set to false API won't returns uuids. Default is true.
    includeUserStateboolYesIf set to to true, API response will contain state also. Default is false.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
pubnub.GlobalHereNow<string>(
    true, true,
    DisplayReturnMessage,
    DisplayErrorMessage
);

{
	"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 Mono for Linux SDK:
  1. ParameterTypeRequiredDescription
    uuidStringYesSpecifies uuid for which current subscribed channels info is required
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    uuidCallbackYesSpecifies uuid for which current subscribed channels info is required
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
You simply need to define the uuid and the callback function to be used to send the data to as in the example below.
pubnub.WhereNow<string>(
    "my_uuid",
    DisplayReturnMessage,
    DisplayErrorMessage
);
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
    channelStringYesSpecifies channel name to set state for.
    channelGroupStringYesSpecifies channelGroup to set state for.
    uuidstringYesUUID
    jsonUserStatestringYesJSON serialized state to set.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to set state for.
    channelGroupStringYesSpecifies channelGroup to set state for.
    jsonUserStatestringYesJSON serialized state to set.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to set state for.
    jsonUserStateStringYesJSON serialized state to set.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThiscallback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to set state for.
    channelGroupStringYesSpecifies channelGroup to set state for.
    uuidstringYesUUID
    keyValuePairKeyValuePair<string, object>YesKey value pair to be set as state.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  5. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to set state for.
    channelGroupStringYesSpecifies channelGroup to set state for.
    keyValuePairKeyValuePair<string, object>YesKey value pair to be set as state.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  6. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to set state for.
    keyValuePairKeyValuePair<string, object>YesKey value pair to be set as state.
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to get state for.
    channelGroupStringYesSpecifies channelGroup to get state for.
    uuidStringYesUUID
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientErrorYesThis callback is called on an error event.
KeyValuePair<string, object> jsonUserState = new KeyValuePair<string, object> ("Key", "Value");
pubnub.SetUserState<string>("my_channel","jbonham", jsonUserState, userCallback, errorCallback);
pubnub.GetUserState<string>("my_channel", "my_uuid", DisplayReturnMessage, DisplayErrorMessage);

// NOTE: DisplayReturnMessage and DisplayErrorMessage are callback methods
The state API returns a JSON object containing key value pairs.

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