Changes between Version 1 and Version 2 of pjsip-doc/presence


Ignore:
Timestamp:
Dec 4, 2013 5:54:11 AM (11 years ago)
Author:
ming
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/presence

    v1 v2  
    55================ 
    66This class represents a remote buddy (a person, or a SIP endpoint). 
    7 To use the Buddy class, application DOES NOT need to subclass it unless application wants to get the notifications on buddy state change. 
    87 
    9 Subscribe to Buddy's Presence Status 
    10 --------------------------------------------------------- 
    11 To subscribe to buddy's presence status, you need to add a buddy object, install callback to handle buddy's event, and start subscribing to buddy's presence status. The snippet below shows a sample code to achieve these:: 
     8Subclassing the Buddy class 
     9---------------------------- 
     10To use the Buddy class, normally application SHOULD create its own subclass, such as:: 
    1211 
    13   class MyBuddyCallback(pjsua.BuddyCallback): 
    14     def __init__(self, buddy=None): 
    15         pjsua.BuddyCallback.__init__(self, buddy) 
     12    class MyBuddy : public Buddy 
     13    { 
     14    public: 
     15        MyBuddy() {} 
     16        ~MyBuddy() {} 
    1617 
    17     def on_state(self): 
    18         print "Buddy", self.buddy.info().uri, "is", 
    19         print self.buddy.info().online_text 
     18        virtual void onBuddyState(); 
     19    }; 
    2020 
    21   try: 
    22     uri = '"Alice" <sip:alice@example.com>' 
    23     buddy = acc.add_buddy(uri, cb=MyBuddyCallback()) 
    24     buddy.subscribe() 
     21In its subclass, application can implement the buddy callback to get the notifications on buddy state change. 
    2522 
    26   except pjsua.Error, err: 
    27     print 'Error adding buddy:', err 
     23Subscribing to Buddy's Presence Status 
     24--------------------------------------- 
     25To 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:: 
    2826 
    29 For more information please see ​Buddy class and ​BuddyCallback class reference documentation. 
     27    BuddyConfig cfg; 
     28    cfg.uri = "sip:alice@example.com"; 
     29    MyBuddy buddy; 
     30    try { 
     31        buddy.create(*acc, cfg); 
     32        buddy.subscribePresence(true); 
     33    } catch(Error& err) { 
     34    } 
     35 
     36Then you can get the buddy's presence state change inside the onBuddyState() callback:: 
     37 
     38    void MyBuddy::onBuddyState() 
     39    { 
     40        BuddyInfo bi = getInfo(); 
     41        cout << "Buddy " << bi.uri << " is " << bi.presStatus.statusText << endl; 
     42    } 
     43 
     44For more information, please see ​Buddy class reference documentation. 
    3045 
    3146Responding to Presence Subscription Request 
    32  
     47------------------------------------------- 
    3348By 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. 
    3449 
    35 This can be done by implementing the ​on_incoming_subscribe() method of the ​AccountCallback class. 
     50This can be done by overriding the ​onIncomingSubscribe() method of the ​Account class. 
    3651 
    3752Changing Account's Presence Status 
     53---------------------------------- 
     54To 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:: 
    3855 
    39 The ​Account class provides two methods to change account's presence status: 
     56    try { 
     57        PresenceStatus ps; 
     58        ps.status = PJSUA_BUDDY_STATUS_ONLINE; 
     59        // Optional, set the activity and some note 
     60        ps.activity = PJRPID_ACTIVITY_BUSY; 
     61        ps.note = "On the phone"; 
     62        acc->setOnlineStatus(ps); 
     63    } 
    4064 
    41 ​set_basic_status() can be used to set basic account's presence status (i.e. available or not available). 
    42 ​set_presence_status() can be used to set both the basic presence status and some extended information (e.g. busy, away, on the phone, etc.). 
    4365When 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. 
    4466