- Timestamp:
- Jul 21, 2008 6:20:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/python/samples/presence.py
r2120 r2163 9 9 10 10 LOG_LEVEL = 3 11 pending_pres = None 12 pending_uri = None 11 13 12 14 def log_cb(level, str, len): 13 15 print str, 14 16 17 class MyAccountCallback(pj.AccountCallback): 18 def __init__(self, account=None): 19 pj.AccountCallback.__init__(self, account) 20 21 def on_incoming_subscribe(self, buddy, from_uri, contact_uri, pres): 22 global pending_pres, pending_uri 23 # Allow buddy to subscribe to our presence 24 if buddy: 25 return (200, None) 26 print 'Incoming SUBSCRIBE request from', from_uri 27 print 'Press "A" to accept and add, "R" to reject the request' 28 pending_pres = pres 29 pending_uri = from_uri 30 return (202, None) 31 32 15 33 class MyBuddyCallback(pj.BuddyCallback): 16 def __init__(self, buddy ):34 def __init__(self, buddy=None): 17 35 pj.BuddyCallback.__init__(self, buddy) 18 36 … … 55 73 56 74 # Create local account 57 acc = lib.create_account_for_transport(transport) 58 75 acc = lib.create_account_for_transport(transport, cb=MyAccountCallback()) 76 acc.set_basic_status(True) 77 59 78 my_sip_uri = "sip:" + transport.info().host + \ 60 79 ":" + str(transport.info().port) … … 65 84 while True: 66 85 print "My SIP URI is", my_sip_uri 67 print "Menu: a=add buddy, t=toggle online status, i=send IM, q=quit" 86 print "Menu: a=add buddy, d=delete buddy, t=toggle", \ 87 " online status, i=send IM, q=quit" 68 88 69 89 input = sys.stdin.readline().rstrip("\r\n") … … 75 95 continue 76 96 77 buddy = acc.add_buddy(input) 78 cb = MyBuddyCallback(buddy) 79 buddy.set_callback(cb) 80 97 buddy = acc.add_buddy(input, cb=MyBuddyCallback()) 81 98 buddy.subscribe() 82 99 … … 98 115 99 116 buddy.send_pager(input) 100 117 118 elif input == "d": 119 if buddy: 120 buddy.delete() 121 buddy = None 122 else: 123 print 'No buddy was added' 124 125 elif input == "A": 126 if pending_pres: 127 acc.pres_notify(pending_pres, pj.SubscriptionState.ACTIVE) 128 buddy = acc.add_buddy(pending_uri, cb=MyBuddyCallback()) 129 buddy.subscribe() 130 pending_pres = None 131 pending_uri = None 132 else: 133 print "No pending request" 134 135 elif input == "R": 136 if pending_pres: 137 acc.pres_notify(pending_pres, pj.SubscriptionState.TERMINATED, 138 "rejected") 139 pending_pres = None 140 pending_uri = None 141 else: 142 print "No pending request" 143 101 144 elif input == "q": 102 145 break 103 146 104 147 # Shutdown the library 148 acc.delete() 149 acc = None 150 if pending_pres: 151 acc.pres_notify(pending_pres, pj.SubscriptionState.TERMINATED, 152 "rejected") 153 transport = None 105 154 lib.destroy() 106 155 lib = None
Note: See TracChangeset
for help on using the changeset viewer.