Changes between Initial Version and Version 1 of Python_SIP/Settings


Ignore:
Timestamp:
Jul 22, 2008 10:40:52 PM (16 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Python_SIP/Settings

    v1 v1  
     1= Startup and Shutdown = 
     2 
     3[[TracNav(Python_SIP/TOC)]] 
     4 
     5== The Lib Class == 
     6 
     7The [http://www.pjsip.org/python/pjsua.htm#Lib Lib class] is a singleton class, and application MUST create one and at most one of this class instance before it can do anything else. This class is the core class of pjsua module, and it provides the following functions: 
     8 * pjsua initialization and shutting down 
     9 * customization of core pjsua settings, such as core SIP settings, media settings, and logging settings 
     10 * media manipulations 
     11 
     12This chapter will describe some of the functions above. The media API will be explained in later chapters. 
     13 
     14== Initialization == 
     15 
     16=== Instantiate the Library === 
     17 
     18Before anything else, you must instantiate the Lib class: 
     19 
     20 {{{ 
     21#!python 
     22import pjsua 
     23 
     24lib = Lib() 
     25 }}} 
     26 
     27Once the library is instantiated, you can retrieve the Lib instance using Lib.instance() static method. 
     28 
     29 
     30=== Initialize the Library === 
     31 
     32Initialize the library by calling its {{{init()}}} method: 
     33 
     34 {{{ 
     35#!python 
     36try: 
     37    lib.init() 
     38except pjsua.Error, err: 
     39    print 'Initialization error:', err 
     40 }}} 
     41 
     42The snippet above initializes the library with the default settings. The {{{init()}}} method will raise exception if error occurs, so we need to trap the exception using try/except clause as above. 
     43 
     44The {{{init()}}} method takes three optional arguments to specify various core settings: 
     45 - [http://www.pjsip.org/python/pjsua.htm#UAConfig UAConfig], to specify core SIP user agent settings 
     46 - [http://www.pjsip.org/python/pjsua.htm#MediaConfig MediaConfig], to specify various media settings, including ICE and TURN. 
     47 - [http://www.pjsip.org/python/pjsua.htm#LogConfig LogConfig], to customize logging settings. 
     48 
     49To customize the settings, you would do something like this: 
     50 
     51 {{{ 
     52#!python 
     53try: 
     54    my_ua_cfg = pjsua.UAConfig() 
     55    my_ua_cfg.stun_host = "stun.pjsip.org" 
     56    my_media_cfg = pjsua.MediaConfig() 
     57    my_media_cfg.enable_ice = True 
     58 
     59    lib.init(ua_cfg=my_ua_cfg, media_cfg=my_media_cfg) 
     60 
     61except pjsua.Error, err: 
     62    print 'Initialization error:', err 
     63 }}} 
     64 
     65 
     66=== Create One or More Transports === 
     67 
     68Application needs to create one or more [http://www.pjsip.org/python/pjsua.htm#Transport Transport] objects before it can send or receive SIP messages: 
     69 
     70 {{{ 
     71#!python 
     72 
     73try: 
     74    udp = lib.create_transport(pj.TransportType.UDP) 
     75 
     76except pj.Error, e: 
     77    print "Error creating transport:", e 
     78 }}} 
     79 
     80The {{{create_transport()}}} method takes an optional [http://www.pjsip.org/python/pjsua.htm#TransportConfig TransportConfig] object to customize the transport settings like bound address and listening port number. Without this, by default the transport will be bound to "0.0.0.0" and any available port. 
     81 
     82 
     83=== Starting the Library === 
     84 
     85Now we're ready to start the library. We need to start the library to finalize the initialization phase, e.g. to complete the initial STUN address resolution, initialize/start the sound device, etc. To start the library: 
     86 
     87 {{{ 
     88#!python 
     89try: 
     90    lib.start() 
     91except pj.Error, e: 
     92    print "Error starting pjsua:", e 
     93 }}} 
     94 
     95 
     96== Shutting Down the Library == 
     97 
     98Once the application exits, the library needs to be shutdown so that resources can be released back to the operating system. This is done like this: 
     99 
     100 {{{ 
     101#!python 
     102lib.destroy() 
     103lib = None 
     104 }}} 
     105 
     106 
     107[[TracNav(Python_SIP/TOC)]] 
     108