104 | | |
| 104 | The equivalence of the C++ sample code above in Python is as follows: |
| 105 | |
| 106 | .. code-block:: python |
| 107 | |
| 108 | # Subclass to extend the Account and get notifications etc. |
| 109 | class Account(pj.Account): |
| 110 | def onRegState(self, prm): |
| 111 | print "***OnRegState: " + prm.reason |
| 112 | |
| 113 | # pjsua2 test function |
| 114 | def pjsua2_test(): |
| 115 | # Create and initialize the library |
| 116 | ep_cfg = pj.EpConfig() |
| 117 | ep = pj.Endpoint() |
| 118 | ep.libCreate() |
| 119 | ep.libInit(ep_cfg) |
| 120 | |
| 121 | # Create SIP transport. Error handling sample is shown |
| 122 | sipTpConfig = pj.TransportConfig(); |
| 123 | sipTpConfig.port = 5060; |
| 124 | ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig); |
| 125 | # Start the library |
| 126 | ep.libStart(); |
| 127 | |
| 128 | acfg = pj.AccountConfig(); |
| 129 | acfg.idUri = "sip:test@pjsip.org"; |
| 130 | acfg.regConfig.registrarUri = "sip:pjsip.org"; |
| 131 | cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest"); |
| 132 | acfg.sipConfig.authCreds.append( cred ); |
| 133 | # Create the account |
| 134 | acc = Account(); |
| 135 | acc.create(acfg); |
| 136 | # Here we don't have anything else to do.. |
| 137 | time.sleep(10); |
| 138 | |
| 139 | # Destroy the library |
| 140 | ep.libDestroy() |
| 141 | |
| 142 | # |
| 143 | # main() |
| 144 | # |
| 145 | if __name__ == "__main__": |
| 146 | pjsua2_test() |