Changes between Initial Version and Version 1 of pjsip-doc/intro_pjsua2

Dec 4, 2013 1:44:12 AM (9 years ago)



  • pjsip-doc/intro_pjsua2

    v1 v1  
     3PJSUA2-High Level API 
     5The PJSUA2 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. 
     7PJSUA2 Main Classes 
     9Here are the main classes of the PJSUA2. 
     12This is the main class of PJSUA2. You need to instantiate one and exactly one of this class, and from the instance you can then initialize and start the library. 
     16An account specifies the identity of the person (or endpoint) on one side of SIP conversation. At least one account instance needs to be created before anything else, and from the account instance you can start making/receiving calls as well as adding buddies. 
     20This class represents a media element which is capable to either produce media or takes media. 
     24This class is used to manipulate calls, such as to answer the call, hangup the call, put the call on hold, transfer the call, etc. 
     28This class represents a remote buddy (a person, or a SIP endpoint). You can subscribe to presence status of a buddy to know whether the buddy is online/offline/etc., and you can send and receive instant messages to/from the buddy. 
     30General Concepts 
     32Class Usage Patterns 
     34With the methods of the main classes above, you will be able to invoke various operations to the object quite easily. But how can we get events/notifications from these classes? Each of the main classes above (except Media) will get their events in the callback methods. So to handle these events, just derive a class from the corresponding class (​Endpoint, Call, Account, or Buddy) and implement/override the relevant method (depending on which event you want to handle). More will be explained in later sections. 
     36Objects Persistence 
     38PJSUA2 includes PersistentObject class to provide functionality to read/write data from/to a document (string or file). The data can be simple data types such as boolean, number, string, and string arrays, or a user defined object. Currently the implementation supports reading and writing from/to JSON document, but the framework allows application to extend the API to support other document formats. 
     40As such, classes which inherit from PersistentObject, such as EpConfig (endpoint configuration), AccountConfig (account configuration), and BuddyConfig (buddy configuration) can be loaded/saved from/to a file. Here’s an example to save a config to a file:: 
     42    EpConfig epCfg; 
     43    JsonDocument jDoc; 
     44    epCfg.uaConfig.maxCalls = 61; 
     45    epCfg.uaConfig.userAgent = "Just JSON Test"; 
     46    jDoc.writeObject(epCfg); 
     47    jDoc.saveFile(“jsontest.js”); 
     49To load from the file:: 
     51    EpConfig epCfg; 
     52    JsonDocument jDoc; 
     53    jDoc.loadFile(“jsontest.js”); 
     54    jDoc.readObject(epCfg); 
     56Error Handling 
     58We use exceptions as means to report error, as this would make the program flows more naturally. Operations which yield error will raise ​Error exception. If you prefer to display the error in more structured manner, the ​Error class has several members to explain the error, such as the operation name that raised the error, the error code, and the error message itself. 
     60Asynchronous Operations 
     62If you have developed applications with PJSIP, you'll know about this already. In PJSIP, all operations that involve sending and receiving SIP messages are asynchronous, meaning that the function that invokes the operation will complete immediately, and you will be given the completion status as callbacks. 
     64Take a look for example the ​makeCall() method of the Call class. This function is used to initiate outgoing call to a destination. When this function returns successfully, it does not mean that the call has been established, but rather it means that the call has been initiated successfully. You will be given the report of the call progress and/or completion in the ​onCallState() callback method of ​Call class. 
     68For 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.