def xfer_call(): global g_current_call if g_current_call == -1: write_log(3, "No current call") else: call = g_current_call ci = py_pjsua.call_get_info(g_current_call) print "Transfering current call ["+ `g_current_call` + "] " + ci.remote_info print "Enter sip url : " url = sys.stdin.readline() if url == "\n": return url = url.replace("\n", "") if call != g_current_call: print "Call has been disconnected" return msg_data = py_pjsua.msg_data_init() status = py_pjsua.call_xfer(g_current_call, url, msg_data); if status != 0: py_pjsua.perror(THIS_FILE, "Error transfering call ", status) else: write_log(3, "Call transfered to " + url)
def on_call_media_state(call_id): ci = py_pjsua.call_get_info(call_id) if ci.media_status == py_pjsua.PJSUA_CALL_MEDIA_ACTIVE: py_pjsua.conf_connect(ci.conf_slot, 0) py_pjsua.conf_connect(0, ci.conf_slot) write_log(3, call_name(call_id) + ": media is active") else: write_log(3, call_name(call_id) + ": media is inactive")
def xfer_call_replaces(): if g_current_call == -1: write_log(3, "No current call") else: call = g_current_call ids = py_pjsua.enum_calls() if len(ids) <= 1: print "There are no other calls" return ci = py_pjsua.call_get_info(g_current_call) print "Transfer call [" + ` g_current_call ` + "] " + ci.remote_info + " to one of the following:" for i in range(0, len(ids)): if ids[i] == call: continue call_info = py_pjsua.call_get_info(ids[i]) print ` ids[ i] ` + " " + call_info.remote_info + " [" + call_info.state_text + "]" print "Enter call number to be replaced : " buf = sys.stdin.readline() buf = buf.replace("\n", "") if buf == "": return dst_call = int(buf) if call != g_current_call: print "Call has been disconnected" return if dst_call == call: print "Destination call number must not be the same as the call being transfered" return if dst_call >= py_pjsua.PJSUA_MAX_CALLS: print "Invalid destination call number" return if py_pjsua.call_is_active(dst_call) == 0: print "Invalid destination call number" return py_pjsua.call_xfer_replaces(call, dst_call, 0, None)
def xfer_call_replaces(): if g_current_call == -1: write_log(3, "No current call") else: call = g_current_call ids = py_pjsua.enum_calls() if len(ids) <= 1: print "There are no other calls" return ci = py_pjsua.call_get_info(g_current_call) print "Transfer call [" + `g_current_call` + "] " + ci.remote_info + " to one of the following:" for i in range(0, len(ids)): if ids[i] == call: continue call_info = py_pjsua.call_get_info(ids[i]) print `ids[i]` + " " + call_info.remote_info + " [" + call_info.state_text + "]" print "Enter call number to be replaced : " buf = sys.stdin.readline() buf = buf.replace("\n","") if buf == "": return dst_call = int(buf) if call != g_current_call: print "Call has been disconnected" return if dst_call == call: print "Destination call number must not be the same as the call being transfered" return if dst_call >= py_pjsua.PJSUA_MAX_CALLS: print "Invalid destination call number" return if py_pjsua.call_is_active(dst_call) == 0: print "Invalid destination call number" return py_pjsua.call_xfer_replaces(call, dst_call, 0, None)
def on_incoming_call(acc_id, call_id, rdata): global g_current_call if g_current_call != py_pjsua.PJSUA_INVALID_ID: # There's call in progress - answer Busy py_pjsua.call_answer(call_id, 486, None, None) return g_current_call = call_id ci = py_pjsua.call_get_info(call_id) write_log(3, "*** Incoming call: " + call_name(call_id) + "***") write_log(3, "*** Press a to answer or h to hangup ***")
def on_call_state(call_id, e): global g_current_call ci = py_pjsua.call_get_info(call_id) write_log(3, call_name(call_id) + " state = " + `ci.state_text`) if ci.state == py_pjsua.PJSIP_INV_STATE_DISCONNECTED: g_current_call = py_pjsua.PJSUA_INVALID_ID
def call_name(call_id): ci = py_pjsua.call_get_info(call_id) return "[Call " + `call_id` + " " + ci.remote_info + "]"
ids = py_pjsua.enum_calls() for id in ids: print "py enum calls id " + ` id ` msg_data = py_pjsua.Msg_Data() status, id = py_pjsua.call_make_call(-1, "sip:[email protected]", 0, 0, msg_data) print "py call make call " + ` status ` + " id " + ` id ` if status != 0: py_pjsua.perror("py_pjsua", "call make call", status) bool = py_pjsua.call_is_active(id) print "py call is active " + ` bool ` bool = py_pjsua.call_has_media(id) print "py call has media " + ` bool ` cp_id = py_pjsua.call_get_conf_port(id) print "py call get conf port " + ` cp_id ` info = py_pjsua.call_get_info(id) if info != None: print "py info id " + ` info.id ` status = py_pjsua.call_set_user_data(id, 0) print "py call set user data status " + ` status ` if status != 0: py_pjsua.perror("py_pjsua", "set user data", status) user_data = py_pjsua.call_get_user_data(id) print "py call get user data " + ` user_data ` #end of lib call py_pjsua.perror("saya", "hallo", 70006) status = py_pjsua.destroy() print "py status " + ` status `
print "py call get count " + `count` ids = py_pjsua.enum_calls() for id in ids: print "py enum calls id " + `id` msg_data = py_pjsua.Msg_Data() status, id = py_pjsua.call_make_call(-1, "sip:[email protected]", 0, 0, msg_data) print "py call make call " + `status` + " id " + `id` if status != 0 : py_pjsua.perror("py_pjsua","call make call",status) bool = py_pjsua.call_is_active(id) print "py call is active " + `bool` bool = py_pjsua.call_has_media(id) print "py call has media " + `bool` cp_id = py_pjsua.call_get_conf_port(id) print "py call get conf port " + `cp_id` info = py_pjsua.call_get_info(id) if info != None : print "py info id " + `info.id` status = py_pjsua.call_set_user_data(id, 0) print "py call set user data status " + `status` if status != 0 : py_pjsua.perror("py_pjsua","set user data",status) user_data = py_pjsua.call_get_user_data(id) print "py call get user data " + `user_data` #end of lib call py_pjsua.perror("saya","hallo",70006)