blob: 16cae8b20c394308180739e755c7fbc0fc184736 [file] [log] [blame]
Benny Prijono9c461142008-07-10 22:41:20 +00001# $Id:$
2#
3# SIP account and registration sample. In this sample, the program
4# will block to wait until registration is complete
5#
6# Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
7#
8import sys
9import pjsua as pj
10import threading
11
12
13def log_cb(level, str, len):
14 print str,
15
16class MyAccountCallback(pj.AccountCallback):
17 sem = None
18
19 def __init__(self, account):
20 pj.AccountCallback.__init__(self, account)
21
22 def wait(self):
23 self.sem = threading.Semaphore(0)
24 self.sem.acquire()
25
26 def on_reg_state(self):
27 if self.sem:
28 if self.account.info().reg_status >= 200:
29 self.sem.release()
30
31lib = pj.Lib()
32
33try:
34 lib.init(log_cfg = pj.LogConfig(level=4, callback=log_cb))
35 lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5080))
36 lib.start()
37
38 acc = lib.create_account(pj.AccountConfig("pjsip.org", "bennylp", "***"))
39
40 acc_cb = MyAccountCallback(acc)
41 acc.set_callback(acc_cb)
42 acc_cb.wait()
43
44 print "\n"
45 print "Registration complete, status=", acc.info().reg_status, \
46 "(" + acc.info().reg_reason + ")"
47 print "\nPress ENTER to quit"
48 sys.stdin.readline()
49
50 lib.destroy()
51 lib = None
52
53except pj.Error, e:
54 print "Exception: " + str(e)
55 lib.destroy()
56