3 # SIP account and registration sample. In this sample, the program
4 # will block to wait until registration is complete
6 # Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 def log_cb(level, str, len):
29 # Callback to receive events from Call
30 class MyCallCallback(pj.CallCallback):
31 def __init__(self, call=None):
32 pj.CallCallback.__init__(self, call)
34 # Notification when call state has changed
36 print "Call is ", self.call.info().state_text,
37 print "last code =", self.call.info().last_code,
38 print "(" + self.call.info().last_reason + ")"
40 # Notification when call's media state has changed.
41 def on_media_state(self):
43 if self.call.info().media_state == pj.MediaState.ACTIVE:
44 # Connect the call to sound device
45 call_slot = self.call.info().conf_slot
46 lib.conf_connect(call_slot, 0)
47 lib.conf_connect(0, call_slot)
48 print "Hello world, I can talk!"
51 # Check command line argument
52 if len(sys.argv) != 2:
53 print "Usage: simplecall.py <dst-URI>"
57 # Create library instance
60 # Init library with default config
61 lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
63 # Create UDP transport which listens to any available port
64 transport = lib.create_transport(pj.TransportType.UDP)
69 # Create local/user-less account
70 acc = lib.create_account_for_transport(transport)
73 call = acc.make_call(sys.argv[1], MyCallCallback())
75 # Wait for ENTER before quitting
76 print "Press <ENTER> to quit"
77 input = sys.stdin.readline().rstrip("\r\n")
79 # We're done, shutdown the library
84 print "Exception: " + str(e)