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. |
| 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, as the recent addition of C# binding has shown. |
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. |
| 126 | Building Java, Python, and C# SWIG Modules |
| 127 | =========================================== |
| 128 | The 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. |
| 330 | |
| 331 | Using in C# Application |
| 332 | ========================= |
| 333 | The 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 | } |