| 110 | .. code-block:: java |
| 111 | |
| 112 | import org.pjsip.pjsua2.*; |
| 113 | |
| 114 | class MyAccount extends Account { |
| 115 | @Override |
| 116 | public void onRegState(OnRegStateParam prm) { |
| 117 | System.out.println("*** On registration state: " + prm.getCode() + prm.getReason()); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | public class test { |
| 122 | static { |
| 123 | System.loadLibrary("pjsua2"); |
| 124 | System.out.println("Library loaded"); |
| 125 | } |
| 126 | |
| 127 | public static void main(String argv[]) { |
| 128 | try { |
| 129 | // Create endpoint |
| 130 | Endpoint ep = new Endpoint(); |
| 131 | ep.libCreate(); |
| 132 | // Initialize endpoint |
| 133 | EpConfig epConfig = new EpConfig(); |
| 134 | ep.libInit( epConfig ); |
| 135 | // Create SIP transport. Error handling sample is shown |
| 136 | TransportConfig sipTpConfig = new TransportConfig(); |
| 137 | sipTpConfig.setPort(5060); |
| 138 | ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_UDP, sipTpConfig); |
| 139 | // Start the library |
| 140 | ep.libStart(); |
| 141 | |
| 142 | AccountConfig acfg = new AccountConfig(); |
| 143 | acfg.setIdUri("sip:test@pjsip.org"); |
| 144 | acfg.getRegConfig().setRegistrarUri("sip:pjsip.org"); |
| 145 | AuthCredInfo cred = new AuthCredInfo("digest", "*", "test", 0, "secret"); |
| 146 | acfg.getSipConfig().getAuthCreds().add( cred ); |
| 147 | // Create the account |
| 148 | MyAccount acc = new MyAccount(); |
| 149 | acc.create(acfg); |
| 150 | // Here we don't have anything else to do.. |
| 151 | Thread.sleep(10000); |
| 152 | /* Explicitly delete the account. |
| 153 | * This is to avoid GC to delete the endpoint first before deleting |
| 154 | * the account. |
| 155 | */ |
| 156 | acc.delete(); |
| 157 | |
| 158 | // Explicitly destroy and delete endpoint |
| 159 | ep.libDestroy(); |
| 160 | ep.delete(); |
| 161 | |
| 162 | } catch (Exception e) { |
| 163 | System.out.println(e); |
| 164 | return; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |