Changeset 928 for pjproject/trunk
- Timestamp:
- Feb 3, 2007 5:23:22 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/py_pjsua
- Files:
-
- 2 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" -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r926 r928 1 1 /* $Id$ */ 2 2 /* 3 * Copyright (C) 2003-200 6Benny Prijono <benny@prijono.org>3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 7511 7511 return NULL; 7512 7512 } 7513 if (sr != Py_None)7513 if (sr == Py_None) 7514 7514 { 7515 7515 reason = NULL; … … 8360 8360 { 8361 8361 PyObject* m = NULL; 8362 #define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name) 8362 8363 8363 8364 … … 8588 8589 /* END OF LIB CALL */ 8589 8590 8590 #ifdef PJSUA_INVALID_ID 8591 8591 8592 /* 8592 * Constant to identify invalid ID for all sorts of IDs.8593 * Add various constants. 8593 8594 */ 8594 PyModule_AddIntConstant(m, "PJSUA_INVALID_ID", PJSUA_INVALID_ID); 8595 #endif 8596 8597 #ifdef PJSUA_ACC_MAX_PROXIES 8598 /* 8599 * Maximum proxies in account. 8600 */ 8601 PyModule_AddIntConstant( 8602 m, "PJSUA_ACC_MAX_PROXIES ", PJSUA_ACC_MAX_PROXIES 8603 ); 8604 #endif 8605 8606 #ifdef PJSUA_MAX_ACC 8607 /* 8608 * Maximum account. 8609 */ 8610 PyModule_AddIntConstant( 8611 m, "PJSUA_MAX_ACC", PJSUA_MAX_ACC 8612 ); 8613 #endif 8614 8615 #ifdef PJSUA_REG_INTERVAL 8616 /* 8617 * Default registration interval.. 8618 */ 8619 PyModule_AddIntConstant( 8620 m, "PJSUA_REG_INTERVAL", PJSUA_REG_INTERVAL 8621 ); 8622 #endif 8623 8624 #ifdef PJSUA_PUBLISH_EXPIRATION 8625 /* 8626 * Default PUBLISH expiration 8627 */ 8628 PyModule_AddIntConstant( 8629 m, "PJSUA_PUBLISH_EXPIRATION", PJSUA_PUBLISH_EXPIRATION 8630 ); 8631 #endif 8632 8633 #ifdef PJSUA_DEFAULT_ACC_PRIORITY 8634 /* 8635 * Default account priority. 8636 */ 8637 PyModule_AddIntConstant( 8638 m, "PJSUA_DEFAULT_ACC_PRIORITY", PJSUA_DEFAULT_ACC_PRIORITY 8639 ); 8640 #endif 8641 8642 #ifdef PJSUA_MAX_BUDDIES 8643 /* 8644 * Default account priority. 8645 */ 8646 PyModule_AddIntConstant( 8647 m, "PJSUA_MAX_BUDDIES", PJSUA_MAX_BUDDIES 8648 ); 8649 #endif 8650 8651 #ifdef PJSUA_MAX_CONF_PORTS 8652 8653 /* 8654 * Max ports in the conference bridge. 8655 */ 8656 PyModule_AddIntConstant( 8657 m, "PJSUA_MAX_CONF_PORTS", PJSUA_MAX_CONF_PORTS 8658 ); 8659 8660 #endif 8661 8662 #ifdef PJSUA_DEFAULT_CLOCK_RATE 8663 8664 PyModule_AddIntConstant( 8665 m, "PJSUA_DEFAULT_CLOCK_RATE", PJSUA_DEFAULT_CLOCK_RATE 8666 ); 8667 8668 #endif 8669 8670 #ifdef PJSUA_DEFAULT_CODEC_QUALITY 8671 8672 PyModule_AddIntConstant( 8673 m, "PJSUA_DEFAULT_CODEC_QUALITY", PJSUA_DEFAULT_CODEC_QUALITY 8674 ); 8675 8676 #endif 8677 8678 #ifdef PJSUA_DEFAULT_ILBC_MODE 8679 8680 PyModule_AddIntConstant( 8681 m, "PJSUA_DEFAULT_ILBC_MODE", PJSUA_DEFAULT_ILBC_MODE 8682 ); 8683 8684 #endif 8685 8686 #ifdef PJSUA_DEFAULT_EC_TAIL_LEN 8687 8688 PyModule_AddIntConstant( 8689 m, "PJSUA_DEFAULT_EC_TAIL_LEN", PJSUA_DEFAULT_EC_TAIL_LEN 8690 ); 8691 8692 #endif 8693 8694 #ifdef PJSUA_MAX_CALLS 8695 8696 PyModule_AddIntConstant( 8697 m, "PJSUA_MAX_CALLS", PJSUA_MAX_CALLS 8698 ); 8699 8700 #endif 8701 8702 #ifdef PJSUA_XFER_NO_REQUIRE_REPLACES 8703 8704 PyModule_AddIntConstant( 8705 m, "PJSUA_XFER_NO_REQUIRE_REPLACES", PJSUA_XFER_NO_REQUIRE_REPLACES 8706 ); 8707 #endif 8708 8709 } 8595 8596 /* Call states */ 8597 ADD_CONSTANT(m, PJSIP_INV_STATE_NULL); 8598 ADD_CONSTANT(m, PJSIP_INV_STATE_CALLING); 8599 ADD_CONSTANT(m, PJSIP_INV_STATE_INCOMING); 8600 ADD_CONSTANT(m, PJSIP_INV_STATE_EARLY); 8601 ADD_CONSTANT(m, PJSIP_INV_STATE_CONNECTING); 8602 ADD_CONSTANT(m, PJSIP_INV_STATE_CONFIRMED); 8603 ADD_CONSTANT(m, PJSIP_INV_STATE_DISCONNECTED); 8604 8605 /* Call media status (enum pjsua_call_media_status) */ 8606 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_NONE); 8607 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_ACTIVE); 8608 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_LOCAL_HOLD); 8609 ADD_CONSTANT(m, PJSUA_CALL_MEDIA_REMOTE_HOLD); 8610 8611 /* Buddy status */ 8612 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_UNKNOWN); 8613 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_ONLINE); 8614 ADD_CONSTANT(m, PJSUA_BUDDY_STATUS_OFFLINE); 8615 8616 /* PJSIP transport types (enum pjsip_transport_type_e) */ 8617 ADD_CONSTANT(m, PJSIP_TRANSPORT_UNSPECIFIED); 8618 ADD_CONSTANT(m, PJSIP_TRANSPORT_UDP); 8619 ADD_CONSTANT(m, PJSIP_TRANSPORT_TCP); 8620 ADD_CONSTANT(m, PJSIP_TRANSPORT_TLS); 8621 ADD_CONSTANT(m, PJSIP_TRANSPORT_SCTP); 8622 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP); 8623 ADD_CONSTANT(m, PJSIP_TRANSPORT_LOOP_DGRAM); 8624 8625 8626 /* Invalid IDs */ 8627 ADD_CONSTANT(m, PJSUA_INVALID_ID); 8628 8629 8630 /* Various compile time constants */ 8631 ADD_CONSTANT(m, PJSUA_ACC_MAX_PROXIES); 8632 ADD_CONSTANT(m, PJSUA_MAX_ACC); 8633 ADD_CONSTANT(m, PJSUA_REG_INTERVAL); 8634 ADD_CONSTANT(m, PJSUA_PUBLISH_EXPIRATION); 8635 ADD_CONSTANT(m, PJSUA_DEFAULT_ACC_PRIORITY); 8636 ADD_CONSTANT(m, PJSUA_MAX_BUDDIES); 8637 ADD_CONSTANT(m, PJSUA_MAX_CONF_PORTS); 8638 ADD_CONSTANT(m, PJSUA_DEFAULT_CLOCK_RATE); 8639 ADD_CONSTANT(m, PJSUA_DEFAULT_CODEC_QUALITY); 8640 ADD_CONSTANT(m, PJSUA_DEFAULT_ILBC_MODE); 8641 ADD_CONSTANT(m, PJSUA_DEFAULT_EC_TAIL_LEN); 8642 ADD_CONSTANT(m, PJSUA_MAX_CALLS); 8643 ADD_CONSTANT(m, PJSUA_XFER_NO_REQUIRE_REPLACES); 8644 8645 8646 #undef ADD_CONSTANT 8647 }
Note: See TracChangeset
for help on using the changeset viewer.