def app_start(): # Done with initialization, start pjsua!! # status = py_pjsua.start() if status != 0: py_pjsua.destroy() err_exit("Error starting pjsua!", status) # Start worker thread thr = thread.start_new(worker_thread_main, (0,)) print "PJSUA Started!!"
def app_init(): global g_acc_id, g_ua_cfg # Create pjsua before anything else status = py_pjsua.create() if status != 0: err_exit("pjsua create() error", status) # Create and initialize logging config log_cfg = py_pjsua.logging_config_default() log_cfg.level = C_LOG_LEVEL log_cfg.cb = log_cb # Create and initialize pjsua config # Note: for this Python module, thread_cnt must be 0 since Python # doesn't like to be called from alien thread (pjsua's thread # in this case) ua_cfg = py_pjsua.config_default() ua_cfg.thread_cnt = 0 ua_cfg.user_agent = "PJSUA/Python 0.1" ua_cfg.cb.on_incoming_call = on_incoming_call ua_cfg.cb.on_call_media_state = on_call_media_state ua_cfg.cb.on_reg_state = on_reg_state ua_cfg.cb.on_call_state = on_call_state ua_cfg.cb.on_buddy_state = on_buddy_state ua_cfg.cb.on_pager = on_pager ua_cfg.cb.on_pager_status = on_pager_status ua_cfg.cb.on_typing = on_typing ua_cfg.cb.on_call_transfer_status = on_call_transfer_status ua_cfg.cb.on_call_transfer_request = on_call_transfer_request # Create and initialize media config med_cfg = py_pjsua.media_config_default() med_cfg.ec_tail_len = 0 # # Initialize pjsua!! # status = py_pjsua.init(ua_cfg, log_cfg, med_cfg) if status != 0: err_exit("pjsua init() error", status) # Configure STUN config stun_cfg = py_pjsua.stun_config_default() stun_cfg.stun_srv1 = C_STUN_SRV stun_cfg.stun_srv2 = C_STUN_SRV stun_cfg.stun_port1 = C_STUN_PORT stun_cfg.stun_port2 = C_STUN_PORT # Configure UDP transport config transport_cfg = py_pjsua.transport_config_default() transport_cfg.port = C_SIP_PORT transport_cfg.stun_config = stun_cfg if C_STUN_SRV != "": transport_cfg.use_stun = 1 # Create UDP transport status, transport_id = \ py_pjsua.transport_create(py_pjsua.PJSIP_TRANSPORT_UDP, transport_cfg) if status != 0: py_pjsua.destroy() err_exit("Error creating UDP transport", status) # Create initial default account status, acc_id = py_pjsua.acc_add_local(transport_id, 1) if status != 0: py_pjsua.destroy() err_exit("Error creating account", status) g_acc_id = acc_id g_ua_cfg = ua_cfg
py_pjsua.acc_set_registration(g_acc_id, 0) elif choice[0] == "d": py_pjsua.dump(choice[1] == "d") elif choice[0] == "a": if g_current_call != py_pjsua.PJSUA_INVALID_ID: py_pjsua.call_answer(g_current_call, 200, None, None) else: print "No current call" # # main # app_init() app_start() app_menu() # # Done, quitting.. # print "PJSUA shutting down.." C_QUIT = 1 # Give the worker thread chance to quit itself while C_QUIT != 2: py_pjsua.handle_events(50) print "PJSUA destroying.." py_pjsua.destroy()
def err_exit(title, rc): py_pjsua.perror(THIS_FILE, title, rc) py_pjsua.destroy() exit(1)
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 `
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`