| 14 | == Creating Userless Accounts == |
| 15 | |
| 16 | A ''user-less'' account is an account without user ID (duh!). It identifies a particular SIP endpoint rather than a particular user. Some other SIP softphones may call this peer-to-peer mode, which means that we are calling another computer via its address rather than calling a particular user ID. |
| 17 | |
| 18 | So for example, we might identify ourself as ''"sip:192.168.0.15"'' (a user-less account) rather than ''"sip:user@pjsip.org"'' (an account). |
| 19 | |
| 20 | In pjsua, a user-less account may be created for each particular transport instance. Creating user-less account is very simple, all we need is the transport instance which is returned by {{{lib.create_transport()}}} method as explained in previous chapter. |
| 21 | |
| 22 | Here's a snippet: |
| 23 | |
| 24 | {{{ |
| 25 | #!python |
| 26 | |
| 27 | acc_cb = MyAccountCallback() |
| 28 | acc = lib.create_account_for_transport(udp, cb=acc_cb) |
| 29 | }}} |
| 30 | |
| 31 | The account callback will be explained later. Basically it is used to capture events emitted by the account, such as incoming call events. |
| 32 | |
| 33 | Once the account is created, you can use the instance as a normal account. More will be explained later. |
| 34 | |
| 35 | Accounts created this way will have its URI derived from the transport address. For example, if the transport address is "192.168.0.15:5080", then the account's URI for UDP transport will be "sip:192.168.0.15:5080", or "sip:192.168.0.15:5080;transport=tcp" for TCP transport. |
| 36 | |
| 37 | == Creating Account == |
| 38 | |
| 39 | For the "normal" account, we need to configure [http://www.pjsip.org/python/pjsua.htm#AccountConfig AccountConfig] and call {{{lib.create_account()}}} to create the account. |
| 40 | |
| 41 | At the very minimum, pjsua only requires the account's ID, which is an URI to identify the account (or in SIP terms, it's called Address of Record/AOR). Here's a snippet: |
| 42 | |
| 43 | {{{ |
| 44 | #!python |
| 45 | |
| 46 | try: |
| 47 | acc_cfg = pjsua.AccountConfig() |
| 48 | acc_cfg.id = "sip:user@pjsip.org" |
| 49 | |
| 50 | acc_cb = MyAccountCallback() |
| 51 | acc = lib.create_account(acc_cfg, cb=acc_cb) |
| 52 | |
| 53 | except pjsua.Error, err: |
| 54 | print 'Error creating account:', err |
| 55 | }}} |
| 56 | |
| 57 | Again the account callback will be explained later. |
| 58 | |
| 59 | The account created above doesn't do anything except to provide identity in the {{{From:}}} header for outgoing requests. The account will not register to SIP server or anything. |
| 60 | |
| 61 | Typically you will want the account to authenticate and register to your SIP server so that you can receive incoming calls. To do that you will need to configure some more settings in your [http://www.pjsip.org/python/pjsua.htm#AccountConfig AccountConfig], something like this: |
| 62 | |
| 63 | {{{ |
| 64 | #!python |
| 65 | |
| 66 | try: |
| 67 | acc_cfg = pjsua.AccountConfig() |
| 68 | acc_cfg.id = "sip:someuser@pjsip.org" |
| 69 | acc_cfg.reg_uri = "sip:pjsip.org" |
| 70 | acc_cfg.proxy = [ "sip:pjsip.org;lr" ] |
| 71 | acc_cfg.auth_cred = [ AuthCred("*", "someuser", "secretpass") ] |
| 72 | |
| 73 | acc_cb = MyAccountCallback() |
| 74 | acc = lib.create_account(acc_cfg, cb=acc_cb) |
| 75 | |
| 76 | except pjsua.Error, err: |
| 77 | print 'Error creating account:', err |
| 78 | }}} |
| 79 | |
| 80 | Or alternatively, for typical account settings like above, you can build the account config like this: |
| 81 | |
| 82 | {{{ |
| 83 | #!python |
| 84 | acc_cfg = pjsua.AccountConfig("pjsip.org", "someuser", "secretpass") |
| 85 | }}} |
| 86 | |
| 87 | |
| 88 | == More on Account Settings == |
| 89 | |
| 90 | There are many more settings that can be specified in [http://www.pjsip.org/python/pjsua.htm#AccountConfig AccountConfig], like: |
| 91 | * whether reliable provisional response (SIP 100rel) is required |
| 92 | * whether presence publication (PUBLISH) is enabled |
| 93 | * Secure RTP (SRTP) related settings |
| 94 | * etc. |
| 95 | |
| 96 | Please see [http://www.pjsip.org/python/pjsua.htm#AccountConfig AccountConfig] reference documentation for more info. |
| 97 | |
| 98 | |