4 | 4 | ****************************** |
5 | 5 | 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. |
| 74 | |
| 75 | Using in C++ Application |
| 76 | ======================== |
| 77 | As 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 | |
| 79 | Here 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 | |
| 145 | Using in Python Application |
| 146 | =========================== |
| 147 | |
| 148 | |
| 149 | |
| 150 | Using in Java Application |
| 151 | ========================= |
| 152 | |
| 153 | |
| 154 | |
| 155 | |