summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-07-24 09:01:33 +0000
committerBenny Prijono <bennylp@teluu.com>2008-07-24 09:01:33 +0000
commit75d894607dcbf432e57ffd8f4ddde1ed13559547 (patch)
tree58ddba5dce0da1c2b885a6716f2f41d5ab69196b
parentd9a415a901eb8d9647100a8ca522cc19e454cd09 (diff)
Added simplecall.py sample
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2171 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip-apps/src/python/samples/call.py14
-rw-r--r--pjsip-apps/src/python/samples/presence.py14
-rw-r--r--pjsip-apps/src/python/samples/registration.py14
-rw-r--r--pjsip-apps/src/python/samples/simplecall.py88
4 files changed, 130 insertions, 0 deletions
diff --git a/pjsip-apps/src/python/samples/call.py b/pjsip-apps/src/python/samples/call.py
index ac053ad5..89cbb1c0 100644
--- a/pjsip-apps/src/python/samples/call.py
+++ b/pjsip-apps/src/python/samples/call.py
@@ -4,6 +4,20 @@
#
# Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
import sys
import pjsua as pj
diff --git a/pjsip-apps/src/python/samples/presence.py b/pjsip-apps/src/python/samples/presence.py
index 20c2e518..a9ee8dd1 100644
--- a/pjsip-apps/src/python/samples/presence.py
+++ b/pjsip-apps/src/python/samples/presence.py
@@ -4,6 +4,20 @@
#
# Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
import sys
import pjsua as pj
diff --git a/pjsip-apps/src/python/samples/registration.py b/pjsip-apps/src/python/samples/registration.py
index 973ea2f4..6c07e967 100644
--- a/pjsip-apps/src/python/samples/registration.py
+++ b/pjsip-apps/src/python/samples/registration.py
@@ -5,6 +5,20 @@
#
# Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
import sys
import pjsua as pj
import threading
diff --git a/pjsip-apps/src/python/samples/simplecall.py b/pjsip-apps/src/python/samples/simplecall.py
new file mode 100644
index 00000000..4b5cd71e
--- /dev/null
+++ b/pjsip-apps/src/python/samples/simplecall.py
@@ -0,0 +1,88 @@
+# $Id$
+#
+# SIP account and registration sample. In this sample, the program
+# will block to wait until registration is complete
+#
+# Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+import sys
+import pjsua as pj
+
+# Logging callback
+def log_cb(level, str, len):
+ print str,
+
+# Callback to receive events from Call
+class MyCallCallback(pj.CallCallback):
+ def __init__(self, call=None):
+ pj.CallCallback.__init__(self, call)
+
+ # Notification when call state has changed
+ def on_state(self):
+ print "Call is ", self.call.info().state_text,
+ print "last code =", self.call.info().last_code,
+ print "(" + self.call.info().last_reason + ")"
+
+ # Notification when call's media state has changed.
+ def on_media_state(self):
+ global lib
+ if self.call.info().media_state == pj.MediaState.ACTIVE:
+ # Connect the call to sound device
+ call_slot = self.call.info().conf_slot
+ lib.conf_connect(call_slot, 0)
+ lib.conf_connect(0, call_slot)
+ print "Hello world, I can talk!"
+
+
+# Check command line argument
+if len(sys.argv) != 2:
+ print "Usage: simplecall.py <dst-URI>"
+ sys.exit(1)
+
+try:
+ # Create library instance
+ lib = pj.Lib()
+
+ # Init library with default config
+ lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
+
+ # Create UDP transport which listens to any available port
+ transport = lib.create_transport(pj.TransportType.UDP)
+
+ # Start the library
+ lib.start()
+
+ # Create local/user-less account
+ acc = lib.create_account_for_transport(transport)
+
+ # Make call
+ call = acc.make_call(sys.argv[1], MyCallCallback())
+
+ # Wait for ENTER before quitting
+ print "Press <ENTER> to quit"
+ input = sys.stdin.readline().rstrip("\r\n")
+
+ # We're done, shutdown the library
+ lib.destroy()
+ lib = None
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ lib.destroy()
+ lib = None
+ sys.exit(1)
+