blob: ab544cce0c2e171ecb7e4e4ee29d20889174d338 [file] [log] [blame]
Alexandre Lision67916dd2014-01-24 13:33:04 -05001
2
3Buddy (Presence)
4================
5This class represents a remote buddy (a person, or a SIP endpoint).
6To use the Buddy class, application DOES NOT need to subclass it unless application wants to get the notifications on buddy state change.
7
8Subscribe to Buddy's Presence Status
9---------------------------------------------------------
10To 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::
11
12 class MyBuddyCallback(pjsua.BuddyCallback):
13 def __init__(self, buddy=None):
14 pjsua.BuddyCallback.__init__(self, buddy)
15
16 def on_state(self):
17 print "Buddy", self.buddy.info().uri, "is",
18 print self.buddy.info().online_text
19
20 try:
21 uri = '"Alice" <sip:alice@example.com>'
22 buddy = acc.add_buddy(uri, cb=MyBuddyCallback())
23 buddy.subscribe()
24
25 except pjsua.Error, err:
26 print 'Error adding buddy:', err
27
28For more information please see Buddy class and BuddyCallback class reference documentation.
29
30Responding to Presence Subscription Request
31
32By 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.
33
34This can be done by implementing the on_incoming_subscribe() method of the AccountCallback class.
35
36Changing Account's Presence Status
37
38The ​Account class provides two methods to change account's presence status:
39
40set_basic_status() can be used to set basic account's presence status (i.e. available or not available).
41​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.).
42When 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.
43