Changes between Version 23 and Version 24 of pjsip-doc/intro_pjsua2


Ignore:
Timestamp:
Jul 31, 2018 8:40:30 AM (10 months ago)
Author:
ming
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/intro_pjsua2

    v23 v24  
    55PJSUA2 is an object-oriented abstraction above ​PJSUA API. It provides high level API for constructing ​Session Initiation Protocol (SIP) multimedia user agent applications (a.k.a Voice over IP/VoIP softphones). It wraps together the signaling, media, and NAT traversal functionality into easy to use call control API, account management, buddy list management, presence, and instant messaging, along with multimedia features such as local conferencing, file streaming, local playback, and voice recording, and powerful NAT traversal techniques utilizing ​STUN, ​TURN, and ​ICE. 
    66 
    7 PJSUA2 is implemented on top of PJSUA-LIB API. The SIP and media features and object modelling follows what PJSUA-LIB provides (for example, we still have accounts, call, buddy, and so on), but the API to access them is different. These features will be described later in this chapter. PJSUA2 is a C++ library, which you can find under ``pjsip`` directory in the PJSIP distribution. The C++ library can be used by native C++ applications directly. But PJSUA2 is not just a C++ library. From the beginning, it has been designed to be accessible from high level non-native languages such as Java and Python. This is achieved by SWIG binding. And thanks to SWIG, binding to other languages can be added relatively easily in the future. 
     7PJSUA2 is implemented on top of PJSUA-LIB API. The SIP and media features and object modelling follows what PJSUA-LIB provides (for example, we still have accounts, call, buddy, and so on), but the API to access them is different. These features will be described later in this chapter. PJSUA2 is a C++ library, which you can find under ``pjsip`` directory in the PJSIP distribution. The C++ library can be used by native C++ applications directly. But PJSUA2 is not just a C++ library. From the beginning, it has been designed to be accessible from high level non-native languages such as Java and Python. This is achieved by SWIG binding. And thanks to SWIG, binding to other languages can be added relatively easily in the future, as the recent addition of C# binding has shown. 
    88 
    99PJSUA2 API declaration can be found in ``pjsip/include/pjsua2`` while the source codes are located in ``pjsip/src/pjsua2``. It will be automatically built when you compile PJSIP. 
     
    124124  sudo make install 
    125125 
    126 Building Python and Java SWIG Modules 
    127 ====================================== 
    128 The SWIG modules for Python and Java are built by invoking ``make`` and ``make install`` manually from ``pjsip-apps/src/swig`` directory. The ``make install`` will install the Python SWIG module to user's ``site-packages`` directory. 
     126Building Java, Python, and C# SWIG Modules 
     127=========================================== 
     128The SWIG modules for Java, Python, and C# are built by invoking ``make`` and ``make install`` manually from ``pjsip-apps/src/swig`` directory. The ``make install`` will install the Python SWIG module to user's ``site-packages`` directory. 
    129129 
    130130Requirements 
     
    135135#. ``Python``, version 3 or above (or at least 2.7 if you use Python2) is recommended (our Python sample app ``pygui`` requires version 2.7 or above, however the ``pjsua2`` Python binding should be able to run on older versions). 
    136136   For **Linux/UNIX**, you will also need ``Python development package`` (called ``python3-devel`` (or ``python-devel`` for Python2) (e.g. on Fedora) or ``python3-dev`` (or ``python2.7-dev`` for Python2) (e.g. on Ubuntu)). For **Windows**, you will need MinGW and ``Python SDK`` such as `ActivePython-2.7.5`_ from `ActiveState`_. 
     137#. ``swig-csharp`` component. 
    137138 
    138139.. _`ActivePython-2.7.5`: http://www.activestate.com/activepython/downloads 
     
    327328    } 
    328329  } 
     330 
     331Using in C# Application 
     332========================= 
     333The equivalence of the C++ sample code above in C# is as follows: 
     334 
     335.. code-block:: csharp 
     336 
     337  using System; 
     338  using pjsua2xamarin.pjsua2; 
     339 
     340  // Subclass to extend the Account and get notifications etc. 
     341  public class MyAccount : Account { 
     342    override public void onRegState(OnRegStateParam prm) { 
     343        Console.WriteLine("*** On registration state: " + prm.code + prm.reason); 
     344    } 
     345  } 
     346 
     347  public class test { 
     348    public void main() { 
     349        try { 
     350            // Create endpoint 
     351            Endpoint ep = new Endpoint(); 
     352            ep.libCreate(); 
     353            // Initialize endpoint 
     354            EpConfig epConfig = new EpConfig(); 
     355            ep.libInit( epConfig ); 
     356            // Create SIP transport. Error handling sample is shown 
     357            TransportConfig sipTpConfig = new TransportConfig(); 
     358            sipTpConfig.port = 5060; 
     359            ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_UDP, sipTpConfig); 
     360            // Start the library 
     361            ep.libStart(); 
     362 
     363            AccountConfig acfg = new AccountConfig(); 
     364            acfg.idUri = "sip:test@pjsip.org"; 
     365            acfg.regConfig.registrarUri = "sip:pjsip.org"; 
     366            AuthCredInfo cred = new AuthCredInfo("digest", "*", "test", 0, "secret"); 
     367            acfg.sipConfig.authCreds.Add( cred ); 
     368            // Create the account 
     369            MyAccount acc = new MyAccount(); 
     370            acc.create(acfg); 
     371 
     372            // Here we don't have anything else to do.. 
     373 
     374            /* Explicitly delete the account. 
     375             * This is to avoid GC to delete the endpoint first before deleting 
     376             * the account. 
     377             */ 
     378            acc.Dispose(); 
     379             
     380            // Explicitly destroy and delete endpoint 
     381            ep.libDestroy(); 
     382            ep.Dispose(); 
     383             
     384        } catch (Exception e) { 
     385            Console.WriteLine("Exception: " + e.Message); 
     386            return; 
     387        } 
     388    } 
     389  } 
    329390}}}