Debian Codegraph @

Xpjproject/pjsip-apps/src/py_pjsua/pjsua_app.py

raw symbols SCIP
1 #
2 # Sample and simple Python script to make and receive calls, and do
3 # presence and instant messaging/IM using PJSUA-API binding for Python.
4 #
5 # Copyright (C) 2003-2007 Benny Prijono <[email protected]>
6 #
7 import py_pjsua
8 import sys
9 import thread
10
11 #
12 # Configurations
13 #
14 THIS_FILE = "pjsua_app.py"
15 C_QUIT = 0
16 C_LOG_LEVEL = 4
17
18 # STUN config.
19 # Set C_STUN_HOST to the address:port of the STUN server to enable STUN
20 #
21 C_STUN_HOST = ""
22 #C_STUN_HOST = "192.168.0.2"
23 #C_STUN_HOST = "stun.iptel.org:3478"
24
25 # SIP port
26 C_SIP_PORT = 5060
27
28
29 # Globals
30 #
31 g_ua_cfg = None
32 g_acc_id = py_pjsua.PJSUA_INVALID_ID
33 g_current_call = py_pjsua.PJSUA_INVALID_ID
34 g_wav_files = []
35 g_wav_id = 0
36 g_wav_port = 0
37 g_rec_file = ""
38 g_rec_id = 0
39 g_rec_port = 0
40
41 # Utility: display PJ error and exit
42 #
43 def err_exit(title, rc):
44 py_pjsua.perror(THIS_FILE, title, rc)
45 py_pjsua.destroy()
46 exit(1)
47
48
49 # Logging function (also callback, called by pjsua-lib)
50 #
51 def log_cb(level, str, len):
52 if level <= C_LOG_LEVEL:
53 print str,
54
55 def write_log(level, str):
56 log_cb(level, str + "\n", 0)
57
58
59 # Utility to get call info
60 #
61 def call_name(call_id):
62 ci = py_pjsua.call_get_info(call_id)
63 return "[Call " + `call_id` + " " + ci.remote_info + "]"
64
65 # Callback when call state has changed.
66 #
67 def on_call_state(call_id, e):
68 global g_current_call
69 ci = py_pjsua.call_get_info(call_id)
70 write_log(3, call_name(call_id) + " state = " + `ci.state_text`)
71 if ci.state == py_pjsua.PJSIP_INV_STATE_DISCONNECTED:
72 g_current_call = py_pjsua.PJSUA_INVALID_ID
73
74 # Callback for incoming call
75 #
76 def on_incoming_call(acc_id, call_id, rdata):
77 global g_current_call
78
79 if g_current_call != py_pjsua.PJSUA_INVALID_ID:
80 # There's call in progress - answer Busy
81 py_pjsua.call_answer(call_id, 486, None, None)
82 return
83
84 g_current_call = call_id
85 ci = py_pjsua.call_get_info(call_id)
86 write_log(3, "*** Incoming call: " + call_name(call_id) + "***")
87 write_log(3, "*** Press a to answer or h to hangup ***")
88
89
90
91 # Callback when media state has changed (e.g. established or terminated)
92 #
93 def on_call_media_state(call_id):
94 ci = py_pjsua.call_get_info(call_id)
95 if ci.media_status == py_pjsua.PJSUA_CALL_MEDIA_ACTIVE:
96 py_pjsua.conf_connect(ci.conf_slot, 0)
97 py_pjsua.conf_connect(0, ci.conf_slot)
98 write_log(3, call_name(call_id) + ": media is active")
99 else:
100 write_log(3, call_name(call_id) + ": media is inactive")
101
102
103 # Callback when account registration state has changed
104 #
105 def on_reg_state(acc_id):
106 acc_info = py_pjsua.acc_get_info(acc_id)
107 if acc_info.has_registration != 0:
108 cmd = "registration"
109 else:
110 cmd = "unregistration"
111 if acc_info.status != 0 and acc_info.status != 200:
112 write_log(3, "Account " + cmd + " failed: rc=" + `acc_info.status` + " " + acc_info.status_text)
113 else:
114 write_log(3, "Account " + cmd + " success")
115
116
117 # Callback when buddy's presence state has changed
118 #
119 def on_buddy_state(buddy_id):
120 write_log(3, "On Buddy state called")
121 buddy_info = py_pjsua.buddy_get_info(buddy_id)
122 if buddy_info.status != 0 and buddy_info.status != 200:
123 write_log(3, "Status of " + `buddy_info.uri` + " is " + `buddy_info.status_text`)
124 else:
125 write_log(3, "Status : " + `buddy_info.status`)
126
127 # Callback on incoming pager (MESSAGE)
128 #
129 def on_pager(call_id, strfrom, strto, contact, mime_type, text):
130 write_log(3, "MESSAGE from " + `strfrom` + " : " + `text`)
131
132
133 # Callback on the delivery status of outgoing pager (MESSAGE)
134 #
135 def on_pager_status(call_id, strto, body, user_data, status, reason):
136 write_log(3, "MESSAGE to " + `strto` + " status " + `status` + " reason " + `reason`)
137
138
139 # Received typing indication
140 #
141 def on_typing(call_id, strfrom, to, contact, is_typing):
142 str_t = ""
143 if is_typing:
144 str_t = "is typing.."
145 else:
146 str_t = "has stopped typing"
147 write_log(3, "IM indication: " + strfrom + " " + str_t)
148
149 # Received the status of previous call transfer request
150 #
151 def on_call_transfer_status(call_id,status_code,status_text,final,p_cont):
152 strfinal = ""
153 if final == 1:
154 strfinal = "[final]"
155
156 write_log(3, "Call " + `call_id` + ": transfer status= " + `status_code` + " " + status_text+ " " + strfinal)
157
158 if status_code/100 == 2:
159 write_log(3, "Call " + `call_id` + " : call transferred successfully, disconnecting call")
160 status = py_pjsua.call_hangup(call_id, 410, None, None)
161 p_cont = 0
162
163 # Callback on incoming call transfer request
164 #
165 def on_call_transfer_request(call_id, dst, code):
166 write_log(3, "Call transfer request from " + `call_id` + " to " + dst + " with code " + `code`)
167
168 #
169 # Initialize pjsua.
170 #
171 def app_init():
172 global g_acc_id, g_ua_cfg
173
174 # Create pjsua before anything else
175 status = py_pjsua.create()
176 if status != 0:
177 err_exit("pjsua create() error", status)
178
179 # Create and initialize logging config
180 log_cfg = py_pjsua.logging_config_default()
181 log_cfg.level = C_LOG_LEVEL
182 log_cfg.cb = log_cb
183
184 # Create and initialize pjsua config
185 # Note: for this Python module, thread_cnt must be 0 since Python
186 # doesn't like to be called from alien thread (pjsua's thread
187 # in this case)
188 ua_cfg = py_pjsua.config_default()
189 ua_cfg.thread_cnt = 0
190 ua_cfg.user_agent = "PJSUA/Python 0.1"
191 ua_cfg.cb.on_incoming_call = on_incoming_call
192 ua_cfg.cb.on_call_media_state = on_call_media_state
193 ua_cfg.cb.on_reg_state = on_reg_state
194 ua_cfg.cb.on_call_state = on_call_state
195 ua_cfg.cb.on_buddy_state = on_buddy_state
196 ua_cfg.cb.on_pager = on_pager
197 ua_cfg.cb.on_pager_status = on_pager_status
198 ua_cfg.cb.on_typing = on_typing
199 ua_cfg.cb.on_call_transfer_status = on_call_transfer_status
200 ua_cfg.cb.on_call_transfer_request = on_call_transfer_request
201
202 # Configure STUN setting
203 if C_STUN_HOST != "":
204 ua_cfg.stun_host = C_STUN_HOST;
205
206 # Create and initialize media config
207 med_cfg = py_pjsua.media_config_default()
208 med_cfg.ec_tail_len = 0
209
210 #
211 # Initialize pjsua!!
212 #
213 status = py_pjsua.init(ua_cfg, log_cfg, med_cfg)
214 if status != 0:
215 err_exit("pjsua init() error", status)
216
217 # Configure UDP transport config
218 transport_cfg = py_pjsua.transport_config_default()
219 transport_cfg.port = C_SIP_PORT
220
221 # Create UDP transport
222 status, transport_id = \
223 py_pjsua.transport_create(py_pjsua.PJSIP_TRANSPORT_UDP, transport_cfg)
224 if status != 0:
225 err_exit("Error creating UDP transport", status)
226
227
228 # Create initial default account
229 status, acc_id = py_pjsua.acc_add_local(transport_id, 1)
230 if status != 0:
231 err_exit("Error creating account", status)
232
233 g_acc_id = acc_id
234 g_ua_cfg = ua_cfg
235
236 # Add SIP account interractively
237 #
238 def add_account():
239 global g_acc_id
240
241 acc_domain = ""
242 acc_username = ""
243 acc_passwd =""
244 confirm = ""
245
246 # Input account configs
247 print "Your SIP domain (e.g. myprovider.com): ",
248 acc_domain = sys.stdin.readline()
249 if acc_domain == "\n":
250 return
251 acc_domain = acc_domain.replace("\n", "")
252
253 print "Your username (e.g. alice): ",
254 acc_username = sys.stdin.readline()
255 if acc_username == "\n":
256 return
257 acc_username = acc_username.replace("\n", "")
258
259 print "Your password (e.g. secret): ",
260 acc_passwd = sys.stdin.readline()
261 if acc_passwd == "\n":
262 return
263 acc_passwd = acc_passwd.replace("\n", "")
264
265 # Configure account configuration
266 acc_cfg = py_pjsua.acc_config_default()
267 acc_cfg.id = "sip:" + acc_username + "@" + acc_domain
268 acc_cfg.reg_uri = "sip:" + acc_domain
269
270 cred_info = py_pjsua.Pjsip_Cred_Info()
271 cred_info.realm = "*"
272 cred_info.scheme = "digest"
273 cred_info.username = acc_username
274 cred_info.data_type = 0
275 cred_info.data = acc_passwd
276
277 acc_cfg.cred_info.append(1)
278 acc_cfg.cred_info[0] = cred_info
279
280 # Add new SIP account
281 status, acc_id = py_pjsua.acc_add(acc_cfg, 1)
282 if status != 0:
283 py_pjsua.perror(THIS_FILE, "Error adding SIP account", status)
284 else:
285 g_acc_id = acc_id
286 write_log(3, "Account " + acc_cfg.id + " added")
287
288 def add_player():
289 global g_wav_files
290 global g_wav_id
291 global g_wav_port
292
293 file_name = ""
294 status = -1
295 wav_id = 0
296
297 print "Enter the path of the file player(e.g. /tmp/audio.wav): ",
298 file_name = sys.stdin.readline()
299 if file_name == "\n":
300 return
301 file_name = file_name.replace("\n", "")
302 status, wav_id = py_pjsua.player_create(file_name, 0)
303 if status != 0:
304 py_pjsua.perror(THIS_FILE, "Error adding file player ", status)
305 else:
306 g_wav_files.append(file_name)
307 if g_wav_id == 0:
308 g_wav_id = wav_id
309 g_wav_port = py_pjsua.player_get_conf_port(wav_id)
310 write_log(3, "File player " + file_name + " added")
311
312 def add_recorder():
313 global g_rec_file
314 global g_rec_id
315 global g_rec_port
316
317 file_name = ""
318 status = -1
319 rec_id = 0
320
321 print "Enter the path of the file recorder(e.g. /tmp/audio.wav): ",
322 file_name = sys.stdin.readline()
323 if file_name == "\n":
324 return
325 file_name = file_name.replace("\n", "")
326 status, rec_id = py_pjsua.recorder_create(file_name, 0, None, 0, 0)
327 if status != 0:
328 py_pjsua.perror(THIS_FILE, "Error adding file recorder ", status)
329 else:
330 g_rec_file = file_name
331 g_rec_id = rec_id
332 g_rec_port = py_pjsua.recorder_get_conf_port(rec_id)
333 write_log(3, "File recorder " + file_name + " added")
334
335 def conf_list():
336 ports = None
337 print "Conference ports : "
338 ports = py_pjsua.enum_conf_ports()
339
340 for port in ports:
341 info = None
342 info = py_pjsua.conf_get_port_info(port)
343 txlist = ""
344 for listener in info.listeners:
345 txlist = txlist + "#" + `listener` + " "
346
347 print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist
348
349 def connect_port():
350 src_port = 0
351 dst_port = 0
352
353 print "Connect src port # (empty to cancel): "
354 src_port = sys.stdin.readline()
355 if src_port == "\n":
356 return
357 src_port = src_port.replace("\n", "")
358 src_port = int(src_port)
359 print "To dst port # (empty to cancel): "
360 dst_port = sys.stdin.readline()
361 if dst_port == "\n":
362 return
363 dst_port = dst_port.replace("\n", "")
364 dst_port = int(dst_port)
365 status = py_pjsua.conf_connect(src_port, dst_port)
366 if status != 0:
367 py_pjsua.perror(THIS_FILE, "Error connecting port ", status)
368 else:
369 write_log(3, "Port connected from " + `src_port` + " to " + `dst_port`)
370
371 def disconnect_port():
372 src_port = 0
373 dst_port = 0
374
375 print "Disconnect src port # (empty to cancel): "
376 src_port = sys.stdin.readline()
377 if src_port == "\n":
378 return
379 src_port = src_port.replace("\n", "")
380 src_port = int(src_port)
381 print "From dst port # (empty to cancel): "
382 dst_port = sys.stdin.readline()
383 if dst_port == "\n":
384 return
385 dst_port = dst_port.replace("\n", "")
386 dst_port = int(dst_port)
387 status = py_pjsua.conf_disconnect(src_port, dst_port)
388 if status != 0:
389 py_pjsua.perror(THIS_FILE, "Error disconnecting port ", status)
390 else:
391 write_log(3, "Port disconnected " + `src_port` + " from " + `dst_port`)
392
393 def dump_call_quality():
394 global g_current_call
395
396 buf = ""
397 if g_current_call != -1:
398 buf = py_pjsua.call_dump(g_current_call, 1, 1024, " ")
399 write_log(3, "\n" + buf)
400 else:
401 write_log(3, "No current call")
402
403 def xfer_call():
404 global g_current_call
405
406 if g_current_call == -1:
407
408 write_log(3, "No current call")
409
410 else:
411 call = g_current_call
412 ci = py_pjsua.call_get_info(g_current_call)
413 print "Transferring current call ["+ `g_current_call` + "] " + ci.remote_info
414 print "Enter sip url : "
415 url = sys.stdin.readline()
416 if url == "\n":
417 return
418 url = url.replace("\n", "")
419 if call != g_current_call:
420 print "Call has been disconnected"
421 return
422 msg_data = py_pjsua.msg_data_init()
423 status = py_pjsua.call_xfer(g_current_call, url, msg_data);
424 if status != 0:
425 py_pjsua.perror(THIS_FILE, "Error transferring call ", status)
426 else:
427 write_log(3, "Call transferred to " + url)
428
429 def xfer_call_replaces():
430 if g_current_call == -1:
431 write_log(3, "No current call")
432 else:
433 call = g_current_call
434
435 ids = py_pjsua.enum_calls()
436 if len(ids) <= 1:
437 print "There are no other calls"
438 return
439
440 ci = py_pjsua.call_get_info(g_current_call)
441 print "Transfer call [" + `g_current_call` + "] " + ci.remote_info + " to one of the following:"
442 for i in range(0, len(ids)):
443 if ids[i] == call:
444 continue
445 call_info = py_pjsua.call_get_info(ids[i])
446 print `ids[i]` + " " + call_info.remote_info + " [" + call_info.state_text + "]"
447
448 print "Enter call number to be replaced : "
449 buf = sys.stdin.readline()
450 buf = buf.replace("\n","")
451 if buf == "":
452 return
453 dst_call = int(buf)
454
455 if call != g_current_call:
456 print "Call has been disconnected"
457 return
458
459 if dst_call == call:
460 print "Destination call number must not be the same as the call being transferred"
461 return
462
463 if dst_call >= py_pjsua.PJSUA_MAX_CALLS:
464 print "Invalid destination call number"
465 return
466
467 if py_pjsua.call_is_active(dst_call) == 0:
468 print "Invalid destination call number"
469 return
470
471 py_pjsua.call_xfer_replaces(call, dst_call, 0, None)
472
473 #
474 # Worker thread function.
475 # Python doesn't like it when it's called from an alien thread
476 # (pjsua's worker thread, in this case), so for Python we must
477 # disable worker thread in pjsua and poll pjsua from Python instead.
478 #
479 def worker_thread_main(arg):
480 global C_QUIT
481 thread_desc = 0;
482 status = py_pjsua.thread_register("python worker", thread_desc)
483 if status != 0:
484 py_pjsua.perror(THIS_FILE, "Error registering thread", status)
485 else:
486 while C_QUIT == 0:
487 py_pjsua.handle_events(50)
488 print "Worker thread quitting.."
489 C_QUIT = 2
490
491
492 # Start pjsua
493 #
494 def app_start():
495 # Done with initialization, start pjsua!!
496 #
497 status = py_pjsua.start()
498 if status != 0:
499 err_exit("Error starting pjsua!", status)
500
501 # Start worker thread
502 thr = thread.start_new(worker_thread_main, (0,))
503
504 print "PJSUA Started!!"
505
506
507 # Print account and buddy list
508 def print_acc_buddy_list():
509 global g_acc_id
510
511 acc_ids = py_pjsua.enum_accs()
512 print "Account list:"
513 for acc_id in acc_ids:
514 acc_info = py_pjsua.acc_get_info(acc_id)
515 if acc_info.has_registration == 0:
516 acc_status = acc_info.status_text
517 else:
518 acc_status = `acc_info.status` + "/" + acc_info.status_text + " (expires=" + `acc_info.expires` + ")"
519
520 if acc_id == g_acc_id:
521 print " *",
522 else:
523 print " ",
524
525 print "[" + `acc_id` + "] " + acc_info.acc_uri + ": " + acc_status
526 print " Presence status: ",
527 if acc_info.online_status != 0:
528 print "Online"
529 else:
530 print "Invisible"
531
532 if py_pjsua.get_buddy_count() > 0:
533 print ""
534 print "Buddy list:"
535 buddy_ids = py_pjsua.enum_buddies()
536 for buddy_id in buddy_ids:
537 bi = py_pjsua.buddy_get_info(buddy_id)
538 print " [" + `buddy_id` + "] " + bi.status_text + " " + bi.uri
539
540
541 # Print application menu
542 #
543 def print_menu():
544 print ""
545 print ">>>"
546 print_acc_buddy_list()
547 print """
548 +============================================================================+
549 | Call Commands : | Buddy, IM & Presence: | Account: |
550 | | | |
551 | m Make call | +b Add buddy | +a Add account |
552 | a Answer current call | -b Delete buddy | -a Delete accnt |
553 | h Hangup current call | | |
554 | H Hold call | i Send instant message | rr register |
555 | v re-inVite (release Hold) | s Subscribe presence | ru Unregister |
556 | # Send DTMF string | u Unsubscribe presence | |
557 | dq Dump curr. call quality | t ToGgle Online status | |
558 | +--------------------------+------------------+
559 | x Xfer call | Media Commands: | Status: |
560 | X Xfer with Replaces | | |
561 | | cl List ports | d Dump status |
562 | | cc Connect port | dd Dump detail |
563 | | cd Disconnect port | |
564 | | +p Add file player | |
565 |------------------------------+ +r Add file recorder | |
566 | q Quit application | | |
567 +============================================================================+"""
568 print "You have " + `py_pjsua.call_get_count()` + " active call(s)"
569 print ">>>",
570
571 # Menu
572 #
573 def app_menu():
574 global g_acc_id
575 global g_current_call
576
577 quit = 0
578 while quit == 0:
579 print_menu()
580 choice = sys.stdin.readline()
581
582 if choice[0] == "q":
583 quit = 1
584
585 elif choice[0] == "i":
586 # Sending IM
587 print "Send IM to SIP URL: ",
588 url = sys.stdin.readline()
589 if url == "\n":
590 continue
591
592 # Send typing indication
593 py_pjsua.im_typing(g_acc_id, url, 1, None)
594
595 print "The content: ",
596 message = sys.stdin.readline()
597 if message == "\n":
598 py_pjsua.im_typing(g_acc_id, url, 0, None)
599 continue
600
601 # Send the IM!
602 py_pjsua.im_send(g_acc_id, url, None, message, None, 0)
603
604 elif choice[0] == "m":
605 # Make call
606 print "Using account ", g_acc_id
607 print "Make call to SIP URL: ",
608 url = sys.stdin.readline()
609 url = url.replace("\n", "")
610 if url == "":
611 continue
612
613 # Initiate the call!
614 status, call_id = py_pjsua.call_make_call(g_acc_id, url, 0, 0, None)
615
616 if status != 0:
617 py_pjsua.perror(THIS_FILE, "Error making call", status)
618 else:
619 g_current_call = call_id
620
621 elif choice[0] == "+" and choice[1] == "b":
622 # Add new buddy
623 bc = py_pjsua.Buddy_Config()
624 print "Buddy URL: ",
625 bc.uri = sys.stdin.readline()
626 if bc.uri == "\n":
627 continue
628
629 bc.uri = bc.uri.replace("\n", "")
630 bc.subscribe = 1
631 status, buddy_id = py_pjsua.buddy_add(bc)
632 if status != 0:
633 py_pjsua.perror(THIS_FILE, "Error adding buddy", status)
634 elif choice[0] == "-" and choice[1] == "b":
635 print "Enter buddy ID to delete : "
636 buf = sys.stdin.readline()
637 buf = buf.replace("\n","")
638 if buf == "":
639 continue
640 i = int(buf)
641 if py_pjsua.buddy_is_valid(i) == 0:
642 print "Invalid buddy id " + `i`
643 else:
644 py_pjsua.buddy_del(i)
645 print "Buddy " + `i` + " deleted"
646 elif choice[0] == "+" and choice[1] == "a":
647 # Add account
648 add_account()
649 elif choice[0] == "-" and choice[1] == "a":
650 print "Enter account ID to delete : "
651 buf = sys.stdin.readline()
652 buf = buf.replace("\n","")
653 if buf == "":
654 continue
655 i = int(buf)
656
657 if py_pjsua.acc_is_valid(i) == 0:
658 print "Invalid account id " + `i`
659 else:
660 py_pjsua.acc_del(i)
661 print "Account " + `i` + " deleted"
662
663 elif choice[0] == "+" and choice[1] == "p":
664 add_player()
665 elif choice[0] == "+" and choice[1] == "r":
666 add_recorder()
667 elif choice[0] == "c" and choice[1] == "l":
668 conf_list()
669 elif choice[0] == "c" and choice[1] == "c":
670 connect_port()
671 elif choice[0] == "c" and choice[1] == "d":
672 disconnect_port()
673 elif choice[0] == "d" and choice[1] == "q":
674 dump_call_quality()
675 elif choice[0] == "x":
676 xfer_call()
677 elif choice[0] == "X":
678 xfer_call_replaces()
679 elif choice[0] == "h":
680 if g_current_call != py_pjsua.PJSUA_INVALID_ID:
681 py_pjsua.call_hangup(g_current_call, 603, None, None)
682 else:
683 print "No current call"
684 elif choice[0] == "H":
685 if g_current_call != py_pjsua.PJSUA_INVALID_ID:
686 py_pjsua.call_set_hold(g_current_call, None)
687
688 else:
689 print "No current call"
690 elif choice[0] == "v":
691 if g_current_call != py_pjsua.PJSUA_INVALID_ID:
692
693 py_pjsua.call_reinvite(g_current_call, 1, None);
694
695 else:
696 print "No current call"
697 elif choice[0] == "#":
698 if g_current_call == py_pjsua.PJSUA_INVALID_ID:
699 print "No current call"
700 elif py_pjsua.call_has_media(g_current_call) == 0:
701 print "Media is not established yet!"
702 else:
703 call = g_current_call
704 print "DTMF strings to send (0-9*#A-B)"
705 buf = sys.stdin.readline()
706 buf = buf.replace("\n", "")
707 if buf == "":
708 continue
709 if call != g_current_call:
710 print "Call has been disconnected"
711 continue
712 status = py_pjsua.call_dial_dtmf(g_current_call, buf)
713 if status != 0:
714 py_pjsua.perror(THIS_FILE, "Unable to send DTMF", status);
715 else:
716 print "DTMF digits enqueued for transmission"
717 elif choice[0] == "s":
718 print "Subscribe presence of (buddy id) : "
719 buf = sys.stdin.readline()
720 buf = buf.replace("\n","")
721 if buf == "":
722 continue
723 i = int(buf)
724 py_pjsua.buddy_subscribe_pres(i, 1)
725 elif choice[0] == "u":
726 print "Unsubscribe presence of (buddy id) : "
727 buf = sys.stdin.readline()
728 buf = buf.replace("\n","")
729 if buf == "":
730 continue
731 i = int(buf)
732 py_pjsua.buddy_subscribe_pres(i, 0)
733 elif choice[0] == "t":
734 acc_info = py_pjsua.acc_get_info(g_acc_id)
735 if acc_info.online_status == 0:
736 acc_info.online_status = 1
737 else:
738 acc_info.online_status = 0
739 py_pjsua.acc_set_online_status(g_acc_id, acc_info.online_status)
740 st = ""
741 if acc_info.online_status == 0:
742 st = "offline"
743 else:
744 st = "online"
745 print "Setting " + acc_info.acc_uri + " online status to " + st
746 elif choice[0] == "r":
747 if choice[1] == "r":
748 py_pjsua.acc_set_registration(g_acc_id, 1)
749 elif choice[1] == "u":
750 py_pjsua.acc_set_registration(g_acc_id, 0)
751 elif choice[0] == "d":
752 py_pjsua.dump(choice[1] == "d")
753 elif choice[0] == "a":
754 if g_current_call != py_pjsua.PJSUA_INVALID_ID:
755
756 py_pjsua.call_answer(g_current_call, 200, None, None)
757 else:
758 print "No current call"
759
760
761 #
762 # main
763 #
764 app_init()
765 app_start()
766 app_menu()
767
768 #
769 # Done, quitting..
770 #
771 print "PJSUA shutting down.."
772 C_QUIT = 1
773 # Give the worker thread chance to quit itself
774 while C_QUIT != 2:
775 py_pjsua.handle_events(50)
776
777 print "PJSUA destroying.."
778 py_pjsua.destroy()
779