First update on buddy API
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@851 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
52612ddb0a
commit
dc308700f8
|
@ -98,6 +98,11 @@ SOURCE=..\src\py_pjsua\pjsua.py
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\src\py_pjsua\pjsua_app.py
|
||||
# PROP Exclude_From_Build 1
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\src\py_pjsua\py_pjsua.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
@ -7,9 +7,9 @@ print "py status " + `status`
|
|||
#
|
||||
# Create configuration objects
|
||||
#
|
||||
ua_cfg = py_pjsua.Config()
|
||||
log_cfg = py_pjsua.Logging_Config()
|
||||
media_cfg = py_pjsua.Media_Config()
|
||||
ua_cfg = py_pjsua.config_default()
|
||||
log_cfg = py_pjsua.logging_config_default()
|
||||
media_cfg = py_pjsua.media_config_default()
|
||||
|
||||
#
|
||||
# Logging callback.
|
||||
|
@ -18,13 +18,6 @@ def logging_cb1(level, str, len):
|
|||
print str,
|
||||
|
||||
|
||||
#
|
||||
# Initialize configs with default values.
|
||||
#
|
||||
py_pjsua.config_default(ua_cfg)
|
||||
py_pjsua.logging_config_default(log_cfg)
|
||||
py_pjsua.media_config_default(media_cfg)
|
||||
|
||||
#
|
||||
# Configure logging
|
||||
#
|
||||
|
@ -46,8 +39,8 @@ if status != 0:
|
|||
exit(1)
|
||||
|
||||
|
||||
message = py_pjsua.Msg_Data()
|
||||
py_pjsua.msg_data_init(message)
|
||||
message = py_pjsua.msg_data_init()
|
||||
|
||||
print "identitas object message data :" + `message`
|
||||
|
||||
sipaddr = 'sip:167.205.34.99'
|
||||
|
@ -75,30 +68,29 @@ print "py status after 3 second of blocking wait :" + `status`
|
|||
#
|
||||
|
||||
# lib transport
|
||||
stunc = py_pjsua.STUN_Config();
|
||||
py_pjsua.stun_config_default(stunc);
|
||||
stunc = py_pjsua.stun_config_default();
|
||||
|
||||
|
||||
tc = py_pjsua.transport_config_default();
|
||||
|
||||
tc = py_pjsua.Transport_Config();
|
||||
py_pjsua.transport_config_default(tc);
|
||||
|
||||
py_pjsua.normalize_stun_config(stunc);
|
||||
|
||||
id = py_pjsua.Transport_ID();
|
||||
status = py_pjsua.transport_create(1, tc, id);
|
||||
|
||||
status, id = py_pjsua.transport_create(1, tc);
|
||||
print "py transport create status " + `status`
|
||||
|
||||
t_id = id.transport_id;
|
||||
ti = py_pjsua.Transport_Info();
|
||||
status = py_pjsua.transport_get_info(t_id,ti)
|
||||
ti = py_pjsua.transport_get_info(id)
|
||||
print "py transport get info status " + `status`
|
||||
|
||||
status = py_pjsua.transport_set_enable(t_id,1)
|
||||
status = py_pjsua.transport_set_enable(id,1)
|
||||
print "py transport set enable status " + `status`
|
||||
if status != 0 :
|
||||
py_pjsua.perror("py_pjsua","set enable",status)
|
||||
|
||||
|
||||
status = py_pjsua.transport_close(t_id,1)
|
||||
status = py_pjsua.transport_close(id,1)
|
||||
print "py transport close status " + `status`
|
||||
if status != 0 :
|
||||
py_pjsua.perror("py_pjsua","close",status)
|
||||
|
@ -107,22 +99,44 @@ if status != 0 :
|
|||
|
||||
# lib account
|
||||
|
||||
accfg = py_pjsua.Acc_Config()
|
||||
py_pjsua.acc_config_default(accfg)
|
||||
accid = py_pjsua.Acc_ID()
|
||||
status = py_pjsua.acc_add(accfg, 1, accid)
|
||||
accfg = py_pjsua.acc_config_default()
|
||||
status, accid = py_pjsua.acc_add(accfg, 1)
|
||||
print "py acc add status " + `status`
|
||||
if status != 0 :
|
||||
py_pjsua.perror("py_pjsua","add acc",status)
|
||||
count = py_pjsua.acc_get_count()
|
||||
print "acc count " + `count`
|
||||
|
||||
accid.acc_id = py_pjsua.acc_get_default()
|
||||
accid = py_pjsua.acc_get_default()
|
||||
|
||||
print "acc id default " + `accid.acc_id`
|
||||
print "acc id default " + `accid`
|
||||
|
||||
# end of lib account
|
||||
|
||||
#lib buddy
|
||||
|
||||
bcfg = py_pjsua.Buddy_Config()
|
||||
status, id = py_pjsua.buddy_add(bcfg)
|
||||
print "py buddy add status " + `status` + " id " + `id`
|
||||
bool = py_pjsua.buddy_is_valid(id)
|
||||
print "py buddy is valid " + `bool`
|
||||
count = py_pjsua.get_buddy_count()
|
||||
print "buddy count " + `count`
|
||||
binfo = py_pjsua.buddy_get_info(id)
|
||||
ids = py_pjsua.enum_buddies(3)
|
||||
status = py_pjsua.buddy_del(id)
|
||||
print "py buddy del status " + `status`
|
||||
status = py_pjsua.buddy_subscribe_pres(id, 1)
|
||||
print "py buddy subscribe pres status " + `status`
|
||||
py_pjsua.pres_dump(1)
|
||||
status = py_pjsua.im_send(accid, "fahris@divusi.com", "", "hallo", message, 0)
|
||||
print "py im send status " + `status`
|
||||
status = py_pjsua.im_typing(accid, "fahris@divusi.com", 1, message)
|
||||
print "py im typing status " + `status`
|
||||
#print "binfo " + `binfo`
|
||||
|
||||
#end of lib buddy
|
||||
|
||||
py_pjsua.perror("saya","hallo",70006)
|
||||
|
||||
status = py_pjsua.destroy()
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
import py_pjsua
|
||||
import sys
|
||||
import thread
|
||||
|
||||
#
|
||||
# Configurations
|
||||
#
|
||||
APP = "pjsua_app.py"
|
||||
C_QUIT = 0
|
||||
C_LOG_LEVEL = 3
|
||||
|
||||
C_SIP_PORT = 5060
|
||||
C_STUN_SRV = ""
|
||||
C_STUN_PORT = 3478
|
||||
|
||||
C_ACC_REGISTRAR = ""
|
||||
#C_ACC_REGISTRAR = "sip:iptel.org"
|
||||
C_ACC_ID = "sip:bulukucing1@iptel.org"
|
||||
C_ACC_REALM = "iptel.org"
|
||||
C_ACC_USERNAME = "bulukucing1"
|
||||
C_ACC_PASSWORD = "netura"
|
||||
|
||||
# Display PJ error and exit
|
||||
def err_exit(title, rc):
|
||||
py_pjsua.perror(APP, title, rc)
|
||||
exit(1)
|
||||
|
||||
# Logging callback
|
||||
def log_cb(level, str, len):
|
||||
if level >= C_LOG_LEVEL:
|
||||
print str,
|
||||
|
||||
# Initialize pjsua
|
||||
def app_init():
|
||||
# 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
|
||||
ua_cfg = py_pjsua.config_default()
|
||||
ua_cfg.thread_cnt = 0
|
||||
ua_cfg.user_agent = "PJSUA/Python 0.1"
|
||||
|
||||
# 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
|
||||
# Note: transport_id is supposed to be integer
|
||||
status, transport_id = py_pjsua.transport_create(1, transport_cfg)
|
||||
if status != 0:
|
||||
py_pjsua.destroy()
|
||||
err_exit("Error creating UDP transport", status)
|
||||
|
||||
|
||||
# Configure account configuration
|
||||
acc_cfg = py_pjsua.acc_config_default()
|
||||
acc_cfg.id = C_ACC_ID
|
||||
acc_cfg.reg_uri = C_ACC_REGISTRAR
|
||||
acc_cfg.cred_count = 1
|
||||
acc_cfg.cred_info[0].realm = C_ACC_REALM
|
||||
acc_cfg.cred_info[0].scheme = "digest"
|
||||
acc_cfg.cred_info[0].username = C_ACC_USERNAME
|
||||
acc_cfg.cred_info[0].data_type = 0
|
||||
acc_cfg.cred_info[0].data = C_ACC_PASSWORD
|
||||
|
||||
# Add new SIP account
|
||||
# Note: acc_id is supposed to be integer
|
||||
status, acc_id = py_pjsua.acc_add(acc_cfg, 1)
|
||||
if status != 0:
|
||||
py_pjsua.destroy()
|
||||
err_exit("Error adding SIP account", status)
|
||||
|
||||
|
||||
# Worker thread function
|
||||
def worker_thread_main(arg):
|
||||
thread_desc = 0;
|
||||
status = py_pjsua.thread_register("worker thread", thread_desc)
|
||||
if status != 0:
|
||||
py_pjsua.perror(APP, "Error registering thread", status)
|
||||
else:
|
||||
while C_QUIT == 0:
|
||||
py_pjsua.handle_events(50)
|
||||
|
||||
# Start pjsua
|
||||
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!!"
|
||||
|
||||
|
||||
# Print application menu
|
||||
def print_menu():
|
||||
print "Menu:"
|
||||
print " q Quit application"
|
||||
print " s Add buddy"
|
||||
print "Choice: ",
|
||||
|
||||
|
||||
# Menu
|
||||
def app_menu():
|
||||
quit = 0
|
||||
while quit == 0:
|
||||
print_menu()
|
||||
choice = sys.stdin.readline()
|
||||
if choice[0] == "q":
|
||||
quit = 1
|
||||
elif choice[0] == "s":
|
||||
bc = py_pjsua.Buddy_Config()
|
||||
print "Buddy URI: ",
|
||||
bc.uri = sys.stdin.readline()
|
||||
if bc.uri == "":
|
||||
continue
|
||||
|
||||
bc.subscribe = 1
|
||||
status = py_pjsua.buddy_add(bc)
|
||||
if status != 0:
|
||||
py_pjsua.perror(APP, "Error adding buddy", status)
|
||||
|
||||
|
||||
#
|
||||
# main
|
||||
#
|
||||
app_init()
|
||||
app_start()
|
||||
app_menu()
|
||||
|
||||
#
|
||||
# Done, quitting..
|
||||
#
|
||||
print "PJSUA shutting down.."
|
||||
C_QUIT = 1
|
||||
py_pjsua.destroy()
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue