| 1 | = SIP Presence = |
| 2 | |
| 3 | [[TracNav(Python_SIP/TOC)]] |
| 4 | |
| 5 | |
| 6 | == Subscribing to Buddy's Presence Status == |
| 7 | |
| 8 | 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. |
| 9 | |
| 10 | {{{ |
| 11 | #!python |
| 12 | |
| 13 | class MyBuddyCallback(pjsua.BuddyCallback): |
| 14 | def __init__(self, buddy=None): |
| 15 | pjsua.BuddyCallback.__init__(self, buddy) |
| 16 | |
| 17 | def on_state(self): |
| 18 | print "Buddy", self.buddy.info().uri, "is", |
| 19 | print self.buddy.info().online_text |
| 20 | |
| 21 | try: |
| 22 | uri = '"Alice" <sip:alice@example.com>' |
| 23 | buddy = acc.add_buddy(uri, cb=MyBuddyCallback()) |
| 24 | buddy.subscribe() |
| 25 | |
| 26 | except pjsua.Error, err: |
| 27 | print 'Error adding buddy:', err |
| 28 | }}} |
| 29 | |
| 30 | |
| 31 | == Responding to Presence Subscription Request == |
| 32 | |
| 33 | |