~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.2.1/pjsip-apps/src/python/samples/simplecall.py

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Mark Purcell
  • Date: 2014-10-18 15:08:50 UTC
  • mfrom: (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20141018150850-2exfk34ckb15pcwi
Tags: 1.4.1-0.1
[ Francois Marier ]
* Non-maintainer upload
* New upstream release (closes: #759576, #741130)
  - debian/rules +PJPROJECT_VERSION := 2.2.1
  - add upstream patch to fix broken TLS support
  - add patch to fix pjproject regression

[ Mark Purcell ]
* Build-Depends:
  - sflphone-daemon + libavformat-dev, libavcodec-dev, libswscale-dev,
  libavdevice-dev, libavutil-dev
  - sflphone-gnome + libclutter-gtk-1.0-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: simplecall.py 2171 2008-07-24 09:01:33Z bennylp $
 
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
#
 
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.
 
12
#
 
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.
 
17
#
 
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 
 
21
#
 
22
import sys
 
23
import pjsua as pj
 
24
 
 
25
# Logging callback
 
26
def log_cb(level, str, len):
 
27
    print str,
 
28
 
 
29
# Callback to receive events from Call
 
30
class MyCallCallback(pj.CallCallback):
 
31
    def __init__(self, call=None):
 
32
        pj.CallCallback.__init__(self, call)
 
33
 
 
34
    # Notification when call state has changed
 
35
    def on_state(self):
 
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 + ")"
 
39
        
 
40
    # Notification when call's media state has changed.
 
41
    def on_media_state(self):
 
42
        global lib
 
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!"
 
49
 
 
50
 
 
51
# Check command line argument
 
52
if len(sys.argv) != 2:
 
53
    print "Usage: simplecall.py <dst-URI>"
 
54
    sys.exit(1)
 
55
 
 
56
try:
 
57
    # Create library instance
 
58
    lib = pj.Lib()
 
59
 
 
60
    # Init library with default config
 
61
    lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
 
62
 
 
63
    # Create UDP transport which listens to any available port
 
64
    transport = lib.create_transport(pj.TransportType.UDP)
 
65
    
 
66
    # Start the library
 
67
    lib.start()
 
68
 
 
69
    # Create local/user-less account
 
70
    acc = lib.create_account_for_transport(transport)
 
71
 
 
72
    # Make call
 
73
    call = acc.make_call(sys.argv[1], MyCallCallback())
 
74
 
 
75
    # Wait for ENTER before quitting
 
76
    print "Press <ENTER> to quit"
 
77
    input = sys.stdin.readline().rstrip("\r\n")
 
78
 
 
79
    # We're done, shutdown the library
 
80
    lib.destroy()
 
81
    lib = None
 
82
 
 
83
except pj.Error, e:
 
84
    print "Exception: " + str(e)
 
85
    lib.destroy()
 
86
    lib = None
 
87
    sys.exit(1)
 
88