Changes between Version 1 and Version 2 of Python_SIP/Accounts


Ignore:
Timestamp:
Jul 22, 2008 11:37:09 PM (16 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Python_SIP/Accounts

    v1 v2  
    33[[TracNav(Python_SIP/TOC)]] 
    44 
    5 Accounts provide identity (or identities) of the user who is currently using the application. In SIP terms, the identity is used as the From header in outgoing requests. 
     5[http://www.pjsip.org/python/pjsua.htm#Account Accounts] provide identity (or identities) of the user who is currently using the application. An account has one SIP Uniform Resource Identifier (URI) associated with it. In SIP terms, the identity is used as the From header in outgoing requests. 
    66 
    77Account may or may not have client registration associated with it. An account is also associated with route set and some authentication credentials, which are used when sending SIP request messages using the account. An account also has presence online status, which will be reported to remote peer when they subscribe to the account's presence, or which is published to a presence server if presence publication is enabled for the account. 
     
    1212 
    1313 
     14== Creating Userless Accounts == 
     15 
     16A ''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 
     18So 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 
     20In 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 
     22Here's a snippet: 
     23 
     24 {{{ 
     25#!python 
     26 
     27acc_cb = MyAccountCallback() 
     28acc = lib.create_account_for_transport(udp, cb=acc_cb) 
     29 }}} 
     30 
     31The account callback will be explained later. Basically it is used to capture events emitted by the account, such as incoming call events. 
     32 
     33Once the account is created, you can use the instance as a normal account. More will be explained later. 
     34 
     35Accounts 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 
     39For 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 
     41At 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 
     46try: 
     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 
     53except pjsua.Error, err: 
     54    print 'Error creating account:', err 
     55 }}} 
     56 
     57Again the account callback will be explained later. 
     58 
     59The 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 
     61Typically 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 
     66try: 
     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 
     76except pjsua.Error, err: 
     77    print 'Error creating account:', err 
     78 }}} 
     79 
     80Or 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 
     90There 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 
     96Please see [http://www.pjsip.org/python/pjsua.htm#AccountConfig AccountConfig] reference documentation for more info. 
     97 
     98 
    1499[[TracNav(Python_SIP/TOC)]]