Version 2 (modified by ming, 11 years ago) (diff)


Buddy (Presence)

This class represents a remote buddy (a person, or a SIP endpoint).

Subclassing the Buddy class

To use the Buddy class, normally application SHOULD create its own subclass, such as:

class MyBuddy : public Buddy
    MyBuddy() {}
    ~MyBuddy() {}

    virtual void onBuddyState();

In its subclass, application can implement the buddy callback to get the notifications on buddy state change.

Subscribing to Buddy's Presence Status

To subscribe to buddy's presence status, you need to add a buddy object and subscribe to buddy's presence status. The snippet below shows a sample code to achieve these:

BuddyConfig cfg;
cfg.uri = "";
MyBuddy buddy;
try {
    buddy.create(*acc, cfg);
} catch(Error& err) {

Then you can get the buddy's presence state change inside the onBuddyState() callback:

void MyBuddy::onBuddyState()
    BuddyInfo bi = getInfo();
    cout << "Buddy " << bi.uri << " is " << bi.presStatus.statusText << endl;

For more information, please see ​Buddy class reference documentation.

Responding to Presence Subscription Request

By default, incoming presence subscription to an account will be accepted automatically. You will probably want to change this behavior, for example only to automatically accept subscription if it comes from one of the buddy in the buddy list, and for anything else prompt the user if he/she wants to accept the request.

This can be done by overriding the ​onIncomingSubscribe() method of the ​Account class.

Changing Account's Presence Status

To change account's presence status, you can use the function Account.setOnlineStatus() to set basic account's presence status (i.e. available or not available) and optionally, some extended information (e.g. busy, away, on the phone, etc), such as:

try {
    PresenceStatus ps;
    // Optional, set the activity and some note
    ps.activity = PJRPID_ACTIVITY_BUSY;
    ps.note = "On the phone";

When the presence status is changed, the account will publish the new status to all of its presence subscriber, either with PUBLISH request or SUBSCRIBE request, or both, depending on account configuration.