Ignore:
Timestamp:
Feb 3, 2007 5:23:22 PM (17 years ago)
Author:
bennylp
Message:

Added various PJSIP constants to Python module and bugfix in call_hangup()

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# 
    18import py_pjsua 
    29import sys 
     
    3037        return "[Call " + `call_id` + " " + ci.remote_info + "]" 
    3138 
    32 # Handler when invite state has changed. 
     39# Callback when call state has changed. 
    3340# 
    3441def on_call_state(call_id, e):   
     
    3643        ci = py_pjsua.call_get_info(call_id) 
    3744        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: 
    3946                g_current_call = py_pjsua.PJSUA_INVALID_ID 
    4047 
    41 # Handler for incoming call 
     48# Callback for incoming call 
    4249# 
    4350def on_incoming_call(acc_id, call_id, rdata): 
    4451        global g_current_call 
    4552        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) 
    4755                return 
     56 
    4857        g_current_call = call_id 
    4958        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  ***"); 
    5261 
    5362         
    54 # Handler when media state has changed (e.g. established or terminated) 
     63# Callback when media state has changed (e.g. established or terminated) 
    5564# 
    5665def on_call_media_state(call_id): 
    5766        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: 
    5968                py_pjsua.conf_connect(ci.conf_slot, 0) 
    6069                py_pjsua.conf_connect(0, ci.conf_slot) 
     
    6473 
    6574 
    66 # Handler when account registration state has changed 
     75# Callback when account registration state has changed 
    6776# 
    6877def on_reg_state(acc_id): 
     
    7483 
    7584 
     85# Callback when buddy's presence state has changed 
     86# 
    7687def on_buddy_state(buddy_id): 
    7788        write_log(3, "On Buddy state called") 
     
    8192        else: 
    8293                write_log(3, "Status : " + `buddy_info.status`) 
    83                  
     94 
     95# Callback on incoming pager (MESSAGE) 
     96#                
    8497def on_pager(call_id, strfrom, strto, contact, mime_type, text): 
    8598        write_log(3, "MESSAGE from " + `strfrom` + " : " + `text`) 
    86          
     99 
     100 
     101# Callback on the delivery status of outgoing pager (MESSAGE) 
     102#        
    87103def on_pager_status(call_id, strto, body, user_data, status, reason): 
    88104        write_log(3, "MESSAGE to " + `strto` + " status " + `status` + " reason " + `reason`) 
     105 
    89106 
    90107# Utility: display PJ error and exit 
     
    163180 
    164181        # 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) 
    166184        if status != 0: 
    167185                py_pjsua.destroy() 
     
    269287 +b   Add buddy 
    270288  m   Make call 
     289  a   Answer current call (if any) 
    271290  h   Hangup current call (if any) 
    272291  i   Send instant message 
     
    305324 
    306325                        # 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) 
    308327 
    309328                elif choice[0] == "m": 
     
    343362                elif choice[0] == "h": 
    344363                        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) 
    346371                        else: 
    347372                                print "No current call" 
Note: See TracChangeset for help on using the changeset viewer.