Changes between Version 2 and Version 3 of pjsip-doc/intro_pjsua2


Ignore:
Timestamp:
Dec 4, 2013 3:48:57 AM (10 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/intro_pjsua2

    v2 v3  
    44****************************** 
    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. 
     6 
     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. 
     8 
    69 
    710PJSUA2 Main Classes 
     
    6972For platforms that require polling, the PJSUA2 module provides its own worker thread to poll PJSIP, so it is not necessary to instantiate own your polling thread. Having said that the application should be prepared to have the callbacks called by different thread than the main thread. The PJSUA2 module should be thread safe. 
    7073 
     74 
     75Using in C++ Application 
     76======================== 
     77As mentioned in previous chapter, A C++ application can use *pjsua2* natively, while at the same time still has access to the lower level objects and the ability to extend the libraries if it needs to. Using the API will be exactly the same as the API reference that is written in this book. 
     78 
     79Here is a sample complete C++ application to give you some idea about the API. The snippet below initializes the library and creates an account that registers to our pjsip.org SIP server. 
     80 
     81.. code-block:: c++ 
     82     
     83  #include <pjsua2.hpp> 
     84  #include <iostream> 
     85   
     86  using namespace pj; 
     87   
     88  // Subclass to extend the Account and get notifications etc. 
     89  class MyAccount : public Account { 
     90  public: 
     91      virtual void onRegState(OnRegStateParam &prm) { 
     92          AccountInfo ai = getInfo(); 
     93          std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:") 
     94                    << " code=" << prm.code << std::endl; 
     95      } 
     96  }; 
     97 
     98  int main() 
     99  { 
     100      Endpoint ep; 
     101       
     102      ep.libCreate(); 
     103       
     104      // Initialize endpoint 
     105      EpConfig ep_cfg; 
     106      ep_cfg.uaConfig.userAgent = "pjsua2-hello"; 
     107      ep.libInit( ep_cfg ); 
     108       
     109      // Create SIP transport. Error handling sample is shown 
     110      TransportConfig tcfg; 
     111      tcfg.port = 5060; 
     112      try { 
     113          ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg); 
     114      } catch (Error &err) { 
     115          std::cout << err.info() << std::endl; 
     116          return 1; 
     117      } 
     118       
     119      // Start the library (worker threads etc) 
     120      ep.libStart(); 
     121      std::cout << "*** PJSUA2 STARTED ***" << std::endl; 
     122       
     123      // Configure an AccountConfig 
     124      AccountConfig acfg; 
     125      acfg.idUri = "sip:test@pjsip.org"; 
     126      acfg.regConfig.registrarUri = "sip:pjsip.org"; 
     127      AuthCredInfo cred("digest", "*", "test", 0, "secret"); 
     128      acfg.sipConfig.authCreds.push_back( cred ); 
     129       
     130      // Create the account 
     131      MyAccount *acc = new MyAccount; 
     132      acc->create(acfg); 
     133       
     134      // Here we don't have anything else to do.. 
     135      pj_thread_sleep(10000); 
     136       
     137      // Delete the account. This will unregister from server 
     138      delete acc; 
     139       
     140      // This will implicitly shutdown the library 
     141      return 0; 
     142  } 
     143 
     144 
     145Using in Python Application 
     146=========================== 
     147 
     148 
     149 
     150Using in Java Application 
     151========================= 
     152 
     153 
     154 
     155 
    71156}}}