Changeset 928 for pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
- Timestamp:
- Feb 3, 2007 5:23:22 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
r926 r928 1 # $Id$ 2 # 3 # Sample and simple Python script to make and receive calls, and do 4 # presence and instant messaging/IM using PJSUA-API binding for Python. 5 # 6 # Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 7 # 1 8 import py_pjsua 2 9 import sys … … 30 37 return "[Call " + `call_id` + " " + ci.remote_info + "]" 31 38 32 # Handler when invitestate has changed.39 # Callback when call state has changed. 33 40 # 34 41 def on_call_state(call_id, e): … … 36 43 ci = py_pjsua.call_get_info(call_id) 37 44 write_log(3, call_name(call_id) + " state = " + `ci.state_text`) 38 if ci.state == 6:45 if ci.state == py_pjsua.PJSIP_INV_STATE_DISCONNECTED: 39 46 g_current_call = py_pjsua.PJSUA_INVALID_ID 40 47 41 # Handlerfor incoming call48 # Callback for incoming call 42 49 # 43 50 def on_incoming_call(acc_id, call_id, rdata): 44 51 global g_current_call 45 52 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 46 py_pjsua.call_answer(call_id, 486, "", None) 53 # There's call in progress - answer Busy 54 py_pjsua.call_answer(call_id, 486, None, None) 47 55 return 56 48 57 g_current_call = call_id 49 58 ci = py_pjsua.call_get_info(call_id) 50 write_log(3, " Incoming call: " + call_name(call_id))51 py_pjsua.call_answer(call_id, 200, "", None)59 write_log(3, "*** Incoming call: " + call_name(call_id) + "***") 60 write_log(3, "*** Press a to answer or h to hangup ***"); 52 61 53 62 54 # Handlerwhen media state has changed (e.g. established or terminated)63 # Callback when media state has changed (e.g. established or terminated) 55 64 # 56 65 def on_call_media_state(call_id): 57 66 ci = py_pjsua.call_get_info(call_id) 58 if ci.media_status == 1:67 if ci.media_status == py_pjsua.PJSUA_CALL_MEDIA_ACTIVE: 59 68 py_pjsua.conf_connect(ci.conf_slot, 0) 60 69 py_pjsua.conf_connect(0, ci.conf_slot) … … 64 73 65 74 66 # Handlerwhen account registration state has changed75 # Callback when account registration state has changed 67 76 # 68 77 def on_reg_state(acc_id): … … 74 83 75 84 85 # Callback when buddy's presence state has changed 86 # 76 87 def on_buddy_state(buddy_id): 77 88 write_log(3, "On Buddy state called") … … 81 92 else: 82 93 write_log(3, "Status : " + `buddy_info.status`) 83 94 95 # Callback on incoming pager (MESSAGE) 96 # 84 97 def on_pager(call_id, strfrom, strto, contact, mime_type, text): 85 98 write_log(3, "MESSAGE from " + `strfrom` + " : " + `text`) 86 99 100 101 # Callback on the delivery status of outgoing pager (MESSAGE) 102 # 87 103 def on_pager_status(call_id, strto, body, user_data, status, reason): 88 104 write_log(3, "MESSAGE to " + `strto` + " status " + `status` + " reason " + `reason`) 105 89 106 90 107 # Utility: display PJ error and exit … … 163 180 164 181 # Create UDP transport 165 status, transport_id = py_pjsua.transport_create(1, transport_cfg) 182 status, transport_id = \ 183 py_pjsua.transport_create(py_pjsua.PJSIP_TRANSPORT_UDP, transport_cfg) 166 184 if status != 0: 167 185 py_pjsua.destroy() … … 269 287 +b Add buddy 270 288 m Make call 289 a Answer current call (if any) 271 290 h Hangup current call (if any) 272 291 i Send instant message … … 305 324 306 325 # Send the IM! 307 py_pjsua.im_send(g_acc_id, url, "", message, None, 0)326 py_pjsua.im_send(g_acc_id, url, None, message, None, 0) 308 327 309 328 elif choice[0] == "m": … … 343 362 elif choice[0] == "h": 344 363 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 345 py_pjsua.call_hangup(g_current_call, 603, "", None) 364 py_pjsua.call_hangup(g_current_call, 603, None, None) 365 else: 366 print "No current call" 367 368 elif choice[0] == "a": 369 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 370 py_pjsua.call_answer(g_current_call, 200, None, None) 346 371 else: 347 372 print "No current call"
Note: See TracChangeset
for help on using the changeset viewer.