49 | | == Introduction == |
50 | | |
51 | | The pjsua module only contains few classes so it should be straightforward to use. |
52 | | |
53 | | == Error Handling == |
54 | | |
55 | | By convention, we use exceptions as means to report error. Operations which yields error will raise [http://www.pjsip.org/python/pjsua.htm#Error pjsua.Error] exception. |
| 49 | === Concepts === #concepts |
| 50 | |
| 51 | ==== Asynchronous Operations ==== |
| 52 | |
| 53 | If you have developed applications with PJSIP you'll know about this already, but this concept probably needs to be explained a little bit here to new PJSIP users. |
| 54 | |
| 55 | In PJSIP, all operations that involve sending and receiving SIP messages are asynchronous, meaning that the function that invokes the operation will complete immediately, and you will be given the completion status as callbacks. Take a look for example the {{{make_call()}}} method of the [http://www.pjsip.org/python/pjsua.htm#Account Account] class. This function is used to initiate outgoing call to a destination. When this function returns successfully, it does not mean that the call has been established, but rather that the call has been '''initiated''' successfully. You will be given the report of the call completion (such as ''Ringing'' or ''Connected''/''Confirmed''' events) in the {{{on_state()}}} callback of [http://www.pjsip.org/python/pjsua.htm#CallCallback CallCallback] class. |
| 56 | |
| 57 | |
| 58 | ==== Basic Usage Pattern ==== |
| 59 | |
| 60 | Ah, talking about callbacks. |
| 61 | |
| 62 | |
| 63 | |
| 64 | ==== Error Handling ==== |
| 65 | |
| 66 | By convention, we use exceptions as means to report error, as this would make the program flows more naturally. Operations which yield error will raise [http://www.pjsip.org/python/pjsua.htm#Error pjsua.Error] exception. Here is a sample: |
| 67 | |
| 68 | {{{ |
| 69 | #!python |
| 70 | import pjsua |
| 71 | |
| 72 | try: |
| 73 | call = acc.make_call('sip:buddy@example.org') |
| 74 | except pjsua.Error, err: |
| 75 | print 'Exception has occured:', err |
| 76 | except: |
| 77 | print 'Ouch..' |
| 78 | }}} |
| 79 | |
| 80 | The sample above will print the full error information to stdout. If you prefer to display the error in more structured manner, the [http://www.pjsip.org/python/pjsua.htm#Error pjsua.Error] class has several members to explain the error, such as the object name that raised the error, the operation name, and the error message itself. |
| 81 | |
| 82 | |