| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import sys |
| 22 |
import pjsua as pj |
| 23 |
import threading |
| 24 |
|
| 25 |
|
| 26 |
def log_cb(level, str, len): |
| 27 |
print str, |
| 28 |
|
| 29 |
class MyAccountCallback(pj.AccountCallback): |
| 30 |
sem = None |
| 31 |
|
| 32 |
def __init__(self, account): |
| 33 |
pj.AccountCallback.__init__(self, account) |
| 34 |
|
| 35 |
def wait(self): |
| 36 |
self.sem = threading.Semaphore(0) |
| 37 |
self.sem.acquire() |
| 38 |
|
| 39 |
def on_reg_state(self): |
| 40 |
if self.sem: |
| 41 |
if self.account.info().reg_status >= 200: |
| 42 |
self.sem.release() |
| 43 |
|
| 44 |
lib = pj.Lib() |
| 45 |
|
| 46 |
try: |
| 47 |
lib.init(log_cfg = pj.LogConfig(level=4, callback=log_cb)) |
| 48 |
lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5080)) |
| 49 |
lib.start() |
| 50 |
|
| 51 |
acc = lib.create_account(pj.AccountConfig("pjsip.org", "bennylp", "***")) |
| 52 |
|
| 53 |
acc_cb = MyAccountCallback(acc) |
| 54 |
acc.set_callback(acc_cb) |
| 55 |
acc_cb.wait() |
| 56 |
|
| 57 |
print "\n" |
| 58 |
print "Registration complete, status=", acc.info().reg_status, \ |
| 59 |
"(" + acc.info().reg_reason + ")" |
| 60 |
print "\nPress ENTER to quit" |
| 61 |
sys.stdin.readline() |
| 62 |
|
| 63 |
lib.destroy() |
| 64 |
lib = None |
| 65 |
|
| 66 |
except pj.Error, e: |
| 67 |
print "Exception: " + str(e) |
| 68 |
lib.destroy() |
| 69 |
|