| 1 | #include <pjsua2.hpp> |
| 2 | #include <iostream> |
| 3 | |
| 4 | using namespace pj; |
| 5 | |
| 6 | // Subclass to extend the Account and get notifications etc. |
| 7 | class MyAccount : public Account { |
| 8 | public: |
| 9 | virtual void onRegState(OnRegStateParam &prm) { |
| 10 | AccountInfo ai = getInfo(); |
| 11 | std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:") |
| 12 | << " code=" << prm.code << std::endl; |
| 13 | } |
| 14 | }; |
| 15 | |
| 16 | int main() |
| 17 | { |
| 18 | Endpoint ep; |
| 19 | |
| 20 | ep.libCreate(); |
| 21 | |
| 22 | // Initialize endpoint |
| 23 | EpConfig ep_cfg; |
| 24 | ep.libInit( ep_cfg ); |
| 25 | |
| 26 | // Create SIP transport. Error handling sample is shown |
| 27 | TransportConfig tcfg; |
| 28 | tcfg.port = 5060; |
| 29 | try { |
| 30 | ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg); |
| 31 | } catch (Error &err) { |
| 32 | std::cout << err.info() << std::endl; |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | // Start the library (worker threads etc) |
| 37 | ep.libStart(); |
| 38 | std::cout << "*** PJSUA2 STARTED ***" << std::endl; |
| 39 | |
| 40 | // Configure an AccountConfig |
| 41 | AccountConfig acfg; |
| 42 | acfg.idUri = "sip:[email protected]"; |
| 43 | acfg.regConfig.registrarUri = "sip:sip.pjsip.org"; |
| 44 | AuthCredInfo cred("digest", "*", "test", 0, "secret"); |
| 45 | acfg.sipConfig.authCreds.push_back( PJSUA2_MOVE(cred) ); |
| 46 | |
| 47 | // Create the account |
| 48 | MyAccount *acc = new MyAccount; |
| 49 | acc->create(acfg); |
| 50 | |
| 51 | // Here we don't have anything else to do.. |
| 52 | pj_thread_sleep(10000); |
| 53 | |
| 54 | // Delete the account. This will unregister from server |
| 55 | delete acc; |
| 56 | |
| 57 | // This will implicitly shutdown the library |
| 58 | return 0; |
| 59 | } |