Debian Codegraph @

Xpjproject/pjsip-apps/src/python/samples/simplecall.py

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