SipCoreApiDocumentation

Version 84 (Ruud Klaver, 07/21/2009 05:43 pm)

1 12 Adrian Georgescu
= SIP core API =
2 1 Adrian Georgescu
3 28 Adrian Georgescu
[[TOC(Sip*, depth=3)]]
4 5 Adrian Georgescu
5 1 Adrian Georgescu
== Introduction ==
6 1 Adrian Georgescu
7 13 Adrian Georgescu
This chapter describes the internal architecture and API of the SIP core of the {{{sipsimple}}} library.
8 71 Adrian Georgescu
{{{sipsimple}}} is a Python package, the core of which wraps the PJSIP C library, which handles SIP signaling and audio media for the SIP SIMPLE client.
9 1 Adrian Georgescu
10 1 Adrian Georgescu
SIP stands for 'Sessions Initiation Protocol', an IETF standard described by [http://tools.ietf.org/html/rfc3261 RFC 3261]. SIP is an application-layer control protocol that can establish,
11 1 Adrian Georgescu
modify and terminate multimedia sessions such as Internet telephony calls
12 1 Adrian Georgescu
(VoIP). Media can be added to (and removed from) an existing session.
13 1 Adrian Georgescu
14 1 Adrian Georgescu
SIP transparently supports name mapping and redirection services, which
15 1 Adrian Georgescu
supports personal mobility, users can maintain a single externally visible
16 1 Adrian Georgescu
address identifier, which can be in the form of a standard email address or
17 1 Adrian Georgescu
E.164 telephone number regardless of their physical network location.
18 1 Adrian Georgescu
19 1 Adrian Georgescu
SIP allows the endpoints to negotiate and combine any type of session they
20 1 Adrian Georgescu
mutually understand like video, instant messaging (IM), file transfer,
21 1 Adrian Georgescu
desktop sharing and provides a generic event notification system with
22 1 Adrian Georgescu
real-time publications and subscriptions about state changes that can be
23 1 Adrian Georgescu
used for asynchronous services like presence, message waiting indicator and
24 1 Adrian Georgescu
busy line appearance.
25 1 Adrian Georgescu
26 1 Adrian Georgescu
For a comprehensive overview of SIP related protocols and use cases visit http://www.tech-invite.com
27 1 Adrian Georgescu
28 30 Adrian Georgescu
== PJSIP library ==
29 1 Adrian Georgescu
30 1 Adrian Georgescu
{{{sipsimple}}} builds on PJSIP [http://www.pjsip.org], a set of static libraries, written in C, which provide SIP signaling and media capabilities.
31 1 Adrian Georgescu
PJSIP is considered to be the most mature and advanced open source SIP stack available.
32 1 Adrian Georgescu
The following diagram, taken from the PJSIP documentation, illustrates the library stack of PJSIP:
33 1 Adrian Georgescu
34 1 Adrian Georgescu
[[Image(http://www.pjsip.org/images/diagram.jpg, nolink)]]
35 1 Adrian Georgescu
36 1 Adrian Georgescu
The diagram shows that there is a common base library, and two more or less independent stacks of libraries, one for SIP signaling and one for SIP media.
37 71 Adrian Georgescu
The latter also includes an abstraction layer for the sound-card.
38 1 Adrian Georgescu
Both of these stracks are integrated in the high level library, called PJSUA.
39 1 Adrian Georgescu
40 1 Adrian Georgescu
PJSIP itself provides a high-level [http://www.pjsip.org/python/pjsua.htm Python wrapper for PJSUA].
41 1 Adrian Georgescu
Despite this, the choice was made to bypass PJSUA and write the SIP core of the {{{sipsimple}}} package as a Python wrapper, which directly uses the PJSIP and PJMEDIA libraries.
42 1 Adrian Georgescu
The main reasons for this are the following:
43 1 Adrian Georgescu
 * PJSUA assumes a session with exactly one audio stream, whilst for the SIP SIMPLE client more advanced (i.e. low-level) manipulation of the SDP is needed.
44 1 Adrian Georgescu
 * What is advertised as SIMPLE functionality, it is minimal and incomplete subset of it. Only page mode messaging using SIP MESSAGE method and basic device status presence are possible, while session mode IM and rich presence are desired.
45 1 Adrian Georgescu
 * PJSUA integrates the decoding and encoding of payloads (e.g. presence related XML documents), while in the SIP SIMPLE client this should be done at a high level, not by the SIP stack.
46 1 Adrian Georgescu
47 1 Adrian Georgescu
PJSIP itself is by nature asynchronous.
48 1 Adrian Georgescu
In the case of PJSIP it means that in general there will be one thread which handles reception and transmission of SIP signaling messages by means of a polling function which is continually called by the application.
49 1 Adrian Georgescu
Whenever the application performs some action through a function, this function will return immediately.
50 1 Adrian Georgescu
If PJSIP has a result for this action, it will notify the application by means of a callback function in the context of the polling function thread.
51 1 Adrian Georgescu
52 1 Adrian Georgescu
> NOTE: Currently the core starts the media handling as a separate C thread to avoid lag caused by the GIL.
53 71 Adrian Georgescu
> The sound-card also has its own C thread.
54 1 Adrian Georgescu
55 1 Adrian Georgescu
== Architecture ==
56 1 Adrian Georgescu
57 1 Adrian Georgescu
The {{{sipsimple}}} core wrapper itself is mostly written using [http://cython.org/ Cython] (formerly [http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ Pyrex]).
58 1 Adrian Georgescu
It allows a Python-like file with some added C manipulation statements to be compiled to C.
59 1 Adrian Georgescu
This in turn compiles to a Python C extension module, which links with the PJSIP static libraries.
60 1 Adrian Georgescu
61 1 Adrian Georgescu
The SIP core part of the {{{sipsimple}}} Python package is subdivided into three modules:
62 1 Adrian Georgescu
 '''sipsimple.engine'''::
63 1 Adrian Georgescu
  Python module that contains the {{{Engine}}} singleton class, which manages the thread that constantly polls the PJSIP library, i.e. the PJSIP worker thread.
64 1 Adrian Georgescu
  For the applications that use the core of {{{sipsimple}}}, the {{{Engine}}} object forms the main entry point.
65 1 Adrian Georgescu
 '''sipsimple.core'''::
66 1 Adrian Georgescu
  This is the Python C extension module ultimately compiled from the Cython file and PJSIP static libraries.
67 1 Adrian Georgescu
  It contains these types of classes:
68 1 Adrian Georgescu
   * The {{{PJSIPUA}}} class, which can only be instanced once, and is this case is only instanced once by the {{{Engine}}} object.
69 1 Adrian Georgescu
     In this way the {{{Engine}}} singleton class acts as a wrapper to the one {{{PJSIPUA}}} instance.
70 1 Adrian Georgescu
     The {{{PJSIPUA}}} class represents the SIP endpoint and manages the initialization and destruction of all the PJSIP libraries.
71 1 Adrian Georgescu
     It also provides a number of methods.
72 1 Adrian Georgescu
     The application however should never call these methods directly on the {{{PJSIPUA}}} object, rather it should call them on the {{{Engine}}} wrapper object.
73 1 Adrian Georgescu
     This object handles everything that for one reason or another cannot or should not be handled from Cython.
74 71 Adrian Georgescu
   * The classes that represent the main SIP primitives to be used by the application, or in the case of {{{Request}}} a generic SIP transaction.
75 1 Adrian Georgescu
     The application can instantiate these classes once the {{{Engine}}} class has been instantiated and the PJSIP worker thread has been started.
76 1 Adrian Georgescu
     All of these classes represent a state machine.
77 42 Ruud Klaver
     * {{{Request}}}
78 1 Adrian Georgescu
     * {{{Subscription}}}
79 82 Ruud Klaver
     * {{{IncomingSubscription}}}
80 1 Adrian Georgescu
     * {{{Invitation}}}
81 1 Adrian Georgescu
   * Several helper classes, which represent some structured collection of data to be passed as parameter to methods of the SIP primitive classes and to parameters of notifications.
82 1 Adrian Georgescu
     * {{{SIPURI}}}
83 1 Adrian Georgescu
     * {{{Credentials}}}
84 1 Adrian Georgescu
     * {{{Route}}}
85 1 Adrian Georgescu
   * A number of SDP manipulation classes, which directly wrap the PJSIP structures representing either the parsed or to be generated SDP.
86 1 Adrian Georgescu
     {{{SDPSession}}} objects may contain references to the other classes and are passed as arguments to methods of a {{{Invitiation}}} object or notifications sent by it.
87 1 Adrian Georgescu
     * {{{SDPSession}}}
88 1 Adrian Georgescu
     * {{{SDPMedia}}}
89 1 Adrian Georgescu
     * {{{SDPConnection}}}
90 1 Adrian Georgescu
     * {{{SDPAttribute}}}
91 1 Adrian Georgescu
   * Two classes related to transport of media traffic and audio traffic specifically, built on PJMEDIA.
92 1 Adrian Georgescu
     These classes can be instantiated independently from the other classes in order to keep signaling and media separate.
93 1 Adrian Georgescu
     * {{{RTPTransport}}}
94 1 Adrian Georgescu
     * {{{AudioTransport}}}
95 73 Ruud Klaver
   * Some other classes that are related to the PJSIP sound subsystem, the main one being the {{{ConferenceBirdge}}}, which audio mixing and input from and output to sound devices.
96 73 Ruud Klaver
     * {{{ConferenceBridge}}}
97 73 Ruud Klaver
     * {{{ToneGenerator}}}
98 1 Adrian Georgescu
     * {{{WaveFile}}}
99 1 Adrian Georgescu
     * {{{RecordingWaveFile}}}
100 1 Adrian Georgescu
   * Two exception classes, the second being a subclass of the first.
101 1 Adrian Georgescu
     * {{{SIPCoreError}}}
102 1 Adrian Georgescu
     * {{{PJSIPError}}}
103 1 Adrian Georgescu
   * Classes used internally within the {{{core}}} module, e.g. to wrap a particular PJSIP library.
104 42 Ruud Klaver
     These classes should not be imported directly and are not included in the {{{__all__}}} variable of this module.
105 42 Ruud Klaver
 '''sipsimple.primitives'''::
106 42 Ruud Klaver
  This module contains several SIP primitive classes that are based on the {{{Request}}} object from the core:
107 42 Ruud Klaver
   * {{{Registration}}}
108 1 Adrian Georgescu
   * {{{Message}}}
109 68 Ruud Klaver
   * {{{Publication}}}
110 1 Adrian Georgescu
111 1 Adrian Georgescu
These classes (except the ones internal to the {{{core}}} module) are illustrated in the following diagram:
112 1 Adrian Georgescu
113 67 Ruud Klaver
[[Image(sipsimple-core-classes.png, nolink)]]
114 67 Ruud Klaver
115 11 Adrian Georgescu
== Integration ==
116 1 Adrian Georgescu
117 1 Adrian Georgescu
The core itself has one Python dependency, the [http://pypi.python.org/pypi/python-application application] module, which in turn depends on the [http://pypi.python.org/pypi/zope.interface zope.interface] module.
118 1 Adrian Georgescu
These modules should be present on the system before the core can be used.
119 1 Adrian Georgescu
An application that uses the SIP core must use the notification system provided by the {{{application}}} module in order to receive notifications from it.
120 1 Adrian Georgescu
It does this by creating one or more classes that act as an observer for particular messages and registering it with the {{{NotificationCenter}}}, which is a singleton class.
121 1 Adrian Georgescu
This means that any call to instance an object from this class will result in the same object.
122 1 Adrian Georgescu
As an example, this bit of code will create an observer for logging messages only:
123 1 Adrian Georgescu
124 1 Adrian Georgescu
{{{
125 1 Adrian Georgescu
from zope.interface import implements
126 1 Adrian Georgescu
from application.notification import NotificationCenter, IObserver
127 1 Adrian Georgescu
128 29 Luci Stanescu
class SIPEngineLogObserver(object):
129 1 Adrian Georgescu
    implements(IObserver)
130 1 Adrian Georgescu
131 1 Adrian Georgescu
    def handle_notification(self, notification):
132 1 Adrian Georgescu
        print "%(timestamp)s (%(level)d) %(sender)14s: %(message)s" % notification.data.__dict__
133 1 Adrian Georgescu
134 1 Adrian Georgescu
notification_center = NotificationCenter()
135 1 Adrian Georgescu
log_observer = EngineLogObserver()
136 29 Luci Stanescu
notification_center.add_observer(self, name="SIPEngineLog")
137 1 Adrian Georgescu
}}}
138 1 Adrian Georgescu
139 1 Adrian Georgescu
Each notification object has three attributes:
140 1 Adrian Georgescu
 '''sender'''::
141 1 Adrian Georgescu
  The object that sent the notification.
142 1 Adrian Georgescu
  For generic notifications the sender will be the {{{Engine}}} instance, otherwise the relevant object.
143 1 Adrian Georgescu
 '''name'''::
144 1 Adrian Georgescu
  The name describing the notification.
145 29 Luci Stanescu
  All messages will be described in this document and start with the prefix "SIP".
146 1 Adrian Georgescu
 '''data'''::
147 1 Adrian Georgescu
  An instance of {{{application.notification.NotificationData}}} or a subclass of it.
148 1 Adrian Georgescu
  The attributes of this object provide additional data about the notification.
149 1 Adrian Georgescu
  Notifications described in this document will also have the data attributes described.
150 1 Adrian Georgescu
151 43 Ruud Klaver
Besides setting up the notification observers, the application should import the relevant objects from the {{{sipsimple.core}}}, {{{sipsimple.engine}}} and {{{sipsimple.primitives}}} modules.
152 1 Adrian Georgescu
It can then instance the {{{Engine}}} class, which is also a singleton, and start the PJSIP worker thread by calling {{{Engine.start()}}}, optionally providing a number of initialization options.
153 1 Adrian Georgescu
Most of these options can later be changed at runtime, by setting attributes of the same name on the {{{Engine}}} object.
154 1 Adrian Georgescu
The application may then instance one of the SIP primitive classes and perform operations on it.
155 1 Adrian Georgescu
156 1 Adrian Georgescu
When starting the {{{Engine}}} class, the application can pass a number of keyword arguments that influence the behaviour of the SIP endpoint.
157 1 Adrian Georgescu
For example, the SIP network ports may be set through the {{{local_udp_port}}}, {{{local_tcp_port}}} and {{{local_tls_port}}} arguments.
158 1 Adrian Georgescu
The UDP/RTP ports are described by a range of ports through {{{rtp_port_range}}}, two of which will be randomly selected for each {{{RTPTransport}}} object and effectively each audio stream.
159 1 Adrian Georgescu
160 1 Adrian Georgescu
The methods called on the SIP primitive objects and the {{{Engine}}} object (proxied to the {{{PJSIPUA}}} instance) may be called from any thread.
161 31 Ruud Klaver
They will return immediately and any delayed result, such as results depending on network traffic, will be returned later using a notification.
162 31 Ruud Klaver
In this manner the SIP core continues the asynchronous pattern of PJSIP.
163 1 Adrian Georgescu
If there is an error in processing the request, an instance of {{{SIPCoreError}}}, or its subclass {{{PJSIPError}}} will be raised.
164 1 Adrian Georgescu
The former will be raised whenever an error occurs inside the core, the latter whenever an underlying PJSIP function returns an error.
165 1 Adrian Georgescu
The {{{PJSIPError}}} object also contains a status attribute, which is the PJSIP errno as an integer.
166 1 Adrian Georgescu
167 43 Ruud Klaver
As a very basic example, one can {{{REGISTER}}} for a sip account by typing the following lines on a Python console:
168 1 Adrian Georgescu
{{{
169 43 Ruud Klaver
from sipsimple.engine import Engine
170 43 Ruud Klaver
from sipsimple.primitives import Registration
171 43 Ruud Klaver
from sipsimple.core import Credentials, SIPURI, Route
172 1 Adrian Georgescu
e = Engine()
173 1 Adrian Georgescu
e.start()
174 65 Ruud Klaver
uri = SIPURI(user="alice", host="example.com")
175 65 Ruud Klaver
cred = Credentials("alice", "mypassword")
176 65 Ruud Klaver
reg = Registration(uri, credentials=cred)
177 43 Ruud Klaver
reg.register(SIPURI("127.0.0.1",port=12345), Route("1.2.3.4"))
178 1 Adrian Georgescu
}}}
179 1 Adrian Georgescu
Note that in this example no observer for notifications from this {{{Registration}}} object are registered, so the result of the operation cannot be seen.
180 43 Ruud Klaver
Also note that this will not keep the registration registered when it is about to expire, as it is the application's responsibility.
181 43 Ruud Klaver
See the {{{Registration}}} documentation for more details.
182 43 Ruud Klaver
When performing operations with a running {{{Engine}}} on a Python console, be sure to call the {{{stop()}}} method of the {{{Engine}}} before exiting the console.
183 43 Ruud Klaver
Failure to do so will keep the {{{Engine}}} running and will cause the program to hang.
184 1 Adrian Georgescu
185 1 Adrian Georgescu
To see how this example can be converted to actually wait for the response without creating an observer, see the example for GreenRegistration at [wiki:SipSynchronousAPI#sipsimple.green.core.GreenRegistration SynchronousAPI].
186 43 Ruud Klaver
187 43 Ruud Klaver
> NOTE: GreenRegistration is outdated and should probably not be used anymore.
188 43 Ruud Klaver
189 43 Ruud Klaver
Another convention that is worth mentioning at this point is that the SIP core will never perform DNS lookups.
190 43 Ruud Klaver
For the sake of flexibility, it is the responsibility of the application to do this and pass the result to SIP core objects using the {{{Route}}} helper object, indicating the destination IP address the resulting SIP request should be sent to.
191 32 Ruud Klaver
192 1 Adrian Georgescu
== Components ==
193 1 Adrian Georgescu
194 1 Adrian Georgescu
=== Engine ===
195 1 Adrian Georgescu
196 1 Adrian Georgescu
As explained above, this singleton class needs to be instantiated by the application using the SIP core of {{{sipsimple}}} and represents the whole SIP core stack.
197 1 Adrian Georgescu
Once the {{{start()}}} method is called, it instantiates the {{{core.PJSIPUA}}} object and will proxy attribute and methods from it to the application.
198 1 Adrian Georgescu
199 1 Adrian Georgescu
==== attributes ====
200 1 Adrian Georgescu
201 1 Adrian Georgescu
 '''default_start_options''' (class attribute)::
202 1 Adrian Georgescu
  This dictionary is a class attribute that describes the default values for the initialization options passed as keyword arguments to the {{{start()}}} method.
203 1 Adrian Georgescu
  Consult this method for documentation of the contents.
204 32 Ruud Klaver
 '''is_running'''::
205 32 Ruud Klaver
  A boolean property indicating if the {{{Engine}}} is running and if it is safe to try calling any proxied methods or attributes on it.
206 1 Adrian Georgescu
207 1 Adrian Georgescu
==== methods ====
208 1 Adrian Georgescu
209 1 Adrian Georgescu
 '''!__init!__'''(''self'')::
210 1 Adrian Georgescu
  This will either create the {{{Engine}}} if it is called for the first time or return the one {{{Engine}}} instance if it is called subsequently.
211 1 Adrian Georgescu
 '''start'''(''self'', '''**kwargs''')::
212 71 Adrian Georgescu
  Initialize all PJSIP libraries based on the keyword parameters provided and start the PJSIP worker thread.
213 1 Adrian Georgescu
  If this fails an appropriate exception is raised.
214 1 Adrian Georgescu
  After the {{{Engine}}} has been started successfully, it can never be started again after being stopped.
215 1 Adrian Georgescu
  The keyword arguments will be discussed here.
216 1 Adrian Georgescu
  Many of these values are also readable as (proxied) attributes on the Engine once the {{{start()}}} method has been called.
217 1 Adrian Georgescu
  Many of them can also be set at runtime, either by modifying the attribute or by calling a particular method.
218 1 Adrian Georgescu
  This will also be documented for each argument in the following list of options.
219 1 Adrian Georgescu
  [[BR]]''local_ip'': (Default: {{{None}}})[[BR]]
220 1 Adrian Georgescu
  IP address of a local interface to bind to.
221 44 Ruud Klaver
  If this is {{{None}}} or {{{0.0.0.0}}} on start, the {{{Engine}}} will listen on all network interfaces.
222 44 Ruud Klaver
  As an attribute, this value is read-only and cannot be changed at runtime.
223 1 Adrian Georgescu
  [[BR]]''local_udp_port'': (Default: {{{0}}})[[BR]]
224 1 Adrian Georgescu
  The local UDP port to listen on for UDP datagrams.
225 1 Adrian Georgescu
  If this is 0, a random port will be chosen.
226 1 Adrian Georgescu
  If it is {{{None}}}, the UDP transport is disabled, both for incoming and outgoing traffic.
227 1 Adrian Georgescu
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_udp_port()}}} method.
228 1 Adrian Georgescu
  [[BR]]''local_tcp_port'': (Default: {{{0}}})[[BR]]
229 1 Adrian Georgescu
  The local TCP port to listen on for new TCP connections.
230 1 Adrian Georgescu
  If this is 0, a random port will be chosen.
231 1 Adrian Georgescu
  If it is {{{None}}}, the TCP transport is disabled, both for incoming and outgoing traffic.
232 1 Adrian Georgescu
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_tcp_port()}}} method.
233 1 Adrian Georgescu
  [[BR]]''local_tls_port'': (Default: {{{0}}})[[BR]]
234 1 Adrian Georgescu
  The local TCP port to listen on for new TLS over TCP connections.
235 28 Adrian Georgescu
  If this is 0, a random port will be chosen.
236 1 Adrian Georgescu
  If it is {{{None}}}, the TLS transport is disabled, both for incoming and outgoing traffic.
237 35 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation. 
238 32 Ruud Klaver
  [[BR]]''tls_protocol'': (Default: "TLSv1")[[BR]] 
239 32 Ruud Klaver
  This string describes the (minimum) TLS protocol that should be used. 
240 32 Ruud Klaver
  Its values should be either {{{None}}}, "SSLv2", "SSLv23", "SSLv3" or "TLSv1". 
241 32 Ruud Klaver
  If {{{None}}} is specified, the PJSIP default will be used, which is currently "TLSv1". 
242 1 Adrian Georgescu
  [[BR]]''tls_verify_server'': (Default: {{{False}}})[[BR]]
243 28 Adrian Georgescu
  This boolean indicates whether PJSIP should verify the certificate of the server against the local CA list when making an outgoing TLS connection.
244 32 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation.
245 1 Adrian Georgescu
  [[BR]]''tls_ca_file'': (Default: {{{None}}})[[BR]]
246 1 Adrian Georgescu
  This string indicates the location of the file containing the local list of CA certificates, to be used for TLS connections.
247 32 Ruud Klaver
  If this is set to {{{None}}}, no CA certificates will be read. 
248 32 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation. 
249 32 Ruud Klaver
  [[BR]]''tls_cert_file'': (Default: {{{None}}})[[BR]] 
250 32 Ruud Klaver
  This string indicates the location of a file containing the TLS certificate to be used for TLS connections. 
251 32 Ruud Klaver
  If this is set to {{{None}}}, no certificate file will be read. 
252 32 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation. 
253 32 Ruud Klaver
  [[BR]]''tls_privkey_file'': (Default: {{{None}}})[[BR]] 
254 32 Ruud Klaver
  This string indicates the location of a file containing the TLS private key associated with the above mentioned certificated to be used for TLS connections. 
255 32 Ruud Klaver
  If this is set to {{{None}}}, no private key file will be read. 
256 32 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation. 
257 32 Ruud Klaver
  [[BR]]''tls_timeout'': (Default: 1000)[[BR]] 
258 32 Ruud Klaver
  The timeout value for a TLS negotiation in milliseconds. 
259 32 Ruud Klaver
  Note that this value should be reasonably small, as a TLS negotiation blocks the whole PJSIP polling thread. 
260 32 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_options()}}} method, as internally the TLS transport needs to be restarted for this operation.
261 71 Adrian Georgescu
  [[BR]]''user_agent'': (Default: {{{"sipsimple-%version"}}})[[BR]]
262 1 Adrian Georgescu
  This value indicates what should be set in the {{{User-Agent}}} header, which is included in each request or response sent.
263 1 Adrian Georgescu
  It can be read and set directly as an attribute at runtime.
264 1 Adrian Georgescu
  [[BR]]''log_level'': (Default: 5)[[BR]]
265 29 Luci Stanescu
  This integer dictates the maximum log level that may be reported to the application by PJSIP through the {{{SIPEngineLog}}} notification.
266 1 Adrian Georgescu
  By default the maximum amount of logging information is reported.
267 1 Adrian Georgescu
  This value can be read and set directly as an attribute at runtime.
268 1 Adrian Georgescu
  [[BR]]''trace_sip'': (Default: {{{False}}})[[BR]]
269 29 Luci Stanescu
  This boolean indicates if the SIP core should send the application SIP messages as seen on the wire through the {{{SIPEngineSIPTrace}}} notification.
270 1 Adrian Georgescu
  It can be read and set directly as an attribute at runtime.
271 1 Adrian Georgescu
  [[BR]]''rtp_port_range'': (Default: (40000, 40100))[[BR]]
272 1 Adrian Georgescu
  This tuple of two integers indicates the range to select UDP ports from when creating a new {{{RTPTransport}}} object, which is used to transport media.
273 1 Adrian Georgescu
  It can be read and set directly as an attribute at runtime, but the ports of previously created {{{RTPTransport}}} objects remain unaffected.
274 71 Adrian Georgescu
  [[BR]]''codecs'': (Default: {{{["speex", "G722", "PCMU", "PCMA", "iLBC", "GSM"]}}})[[BR]]
275 1 Adrian Georgescu
  This list specifies the codecs to use for audio sessions and their preferred order.
276 40 Ruud Klaver
  It can be read and set directly as an attribute at runtime.
277 1 Adrian Georgescu
  Note that this global option can be overridden by an argument passed to {{{AudioTransport.__init__()}}}.
278 1 Adrian Georgescu
  The strings in this list is case insensitive.
279 1 Adrian Georgescu
  [[BR]]''events'': (Default: <some sensible events>)[[BR]]
280 1 Adrian Georgescu
  PJSIP needs a mapping between SIP SIMPLE event packages and content types.
281 1 Adrian Georgescu
  This dictionary provides some default packages and their event types.
282 1 Adrian Georgescu
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_tls_port()}}} method.
283 82 Ruud Klaver
  [[BR]]''incoming_events'': (Default: {{{set()}}})[[BR]]
284 82 Ruud Klaver
  A list that specifies for which SIP SIMPLE event packages the application wishes to receive {{{IncomingSubscribe}}} objects.
285 82 Ruud Klaver
  When a {{{SUBSCRIBE}}} request is received containing an event name that is not in this list, a 489 "Bad event" response is internally generated.
286 82 Ruud Klaver
  When the event is in the list, an {{{IncomingSubscribe}}} object is created based on the request and passed to the application by means of a notification.
287 82 Ruud Klaver
  Note that each of the events specified here should also be a key in the {{{events}}} dictionary argument.
288 82 Ruud Klaver
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{add_incoming_event()}}} and {{{remove_incoming_event()}}} methods.
289 74 Ruud Klaver
 '''start_cfg'''(''self'', '''**kwargs''')::
290 40 Ruud Klaver
  This provides a [wiki:SipConfigurationAPI Configuration API] aware start method.
291 1 Adrian Georgescu
  It will retrieve all the arguments that can be passed to {{{start()}}} from the configuration framework, unless they are overridden by the keyword arguments to this method.
292 74 Ruud Klaver
  Any argument that can be passed to {{{start()}}} may be specified.
293 36 Adrian Georgescu
 '''stop'''(''self'')::
294 32 Ruud Klaver
  Stop the PJSIP worker thread and unload all PJSIP libraries.
295 32 Ruud Klaver
  Note that after this all references to SIP core objects can no longer be used, these should be properly removed by the application itself before stopping the {{{Engine}}}.
296 35 Ruud Klaver
  Also note that, once stopped the {{{Engine}}} cannot be started again.
297 1 Adrian Georgescu
  This method is automatically called when the Python interpreter exits.
298 39 Ruud Klaver
299 1 Adrian Georgescu
==== proxied attributes ====
300 1 Adrian Georgescu
301 20 Ruud Klaver
Besides all the proxied attributes described for the {{{__init__}}} method above, two other attributes are provided once the {{{Engine}}} has been started.
302 1 Adrian Georgescu
303 74 Ruud Klaver
 '''input_devices'''::
304 74 Ruud Klaver
  This read-only attribute is a list of strings, representing all audio input devices on the system that can be used.
305 74 Ruud Klaver
  One of these device names can be passed as the {{{input_device}}} argument when creating a {{{ConferenceBridge}}} object.
306 74 Ruud Klaver
 '''output_devices'''::
307 74 Ruud Klaver
  This read-only attribute is a list of string, representing all audio output devices on the system that can be used.
308 74 Ruud Klaver
  One of these device names can be passed as the {{{output_device}}} argument when creating a {{{ConferenceBridge}}} object.
309 1 Adrian Georgescu
 '''available_codecs'''::
310 1 Adrian Georgescu
  A read-only list of codecs available in the core, regardless of the codecs configured through the {{{codecs}}} attribute.
311 1 Adrian Georgescu
312 1 Adrian Georgescu
==== proxied methods ====
313 1 Adrian Georgescu
314 29 Luci Stanescu
 '''add_event'''(''self'', '''event''', '''accept_types''')::
315 1 Adrian Georgescu
  Couple a certain event package to a list of content types.
316 1 Adrian Georgescu
  Once added it cannot be removed or modified.
317 82 Ruud Klaver
 '''add_incoming_event'''(''self'', '''event''')::
318 82 Ruud Klaver
  Adds a SIP SIMPLE event package to the set of events for which the {{{Engine}}} should create an {{{IncomingSubscribe}}} object when a {{{SUBSCRIBE}}} request is received.
319 82 Ruud Klaver
  Note that this event should be known to the {{{Engine}}} by means of the {{{events}}} attribute.
320 82 Ruud Klaver
 '''remove_incoming_event'''(''self'', '''event''')::
321 82 Ruud Klaver
  Removes an event from the {{{incoming_events}}} attribute.
322 82 Ruud Klaver
  Incoming {{{SUBSCRIBE}}} requests with this event package will automatically be replied to with a 489 "Bad Event" response.
323 38 Ruud Klaver
 '''detect_nat_type'''(''self'', '''stun_server_address''', '''stun_server_port'''=3478, '''user_data'''=None)::
324 1 Adrian Georgescu
  Will start a series of STUN requests which detect the type of NAT this host is behind.
325 1 Adrian Georgescu
  The {{{stun_server_address}}} parameter indicates the IP address or hostname of the STUN server to be used and {{{stun_server_port}}} specifies the remote UDP port to use.
326 38 Ruud Klaver
  When the type of NAT is detected, this will be reported back to the application by means of a {{{SIPEngineDetectedNATType}}} notification, including the user_data object passed with this method.
327 1 Adrian Georgescu
 '''set_local_udp_port'''(''self'', '''value''')::
328 1 Adrian Georgescu
  Update the {{{local_udp_port}}} attribute to the newly specified value.
329 1 Adrian Georgescu
 '''set_local_tcp_port'''(''self'', '''value''')::
330 1 Adrian Georgescu
  Update the {{{local_tcp_port}}} attribute to the newly specified value.
331 44 Ruud Klaver
 '''set_tls_options'''(''self'', '''local_port'''={{{None}}}, '''protocol'''="TLSv1", '''verify_server'''={{{False}}}, '''ca_file'''={{{None}}}, '''cert_file'''={{{None}}}, '''privkey_file'''={{{None}}}, '''timeout'''=1000):: 
332 44 Ruud Klaver
  Calling this method will (re)start the TLS transport with the specified arguments, or stop it in the case that the '''local_port''' argument is set to {{{None}}}. 
333 44 Ruud Klaver
  The semantics of the arguments are the same as on the {{{start()}}} method. 
334 83 Ruud Klaver
 '''parse_sip_uri'''(''self'', '''uri_string''')::
335 44 Ruud Klaver
  Will parse the provided SIP URI string using the PJSIP parsing capabilities and return a {{{SIPURI}}} object, or raise an exception if there was an error parsing the URI.
336 1 Adrian Georgescu
337 1 Adrian Georgescu
==== notifications ====
338 1 Adrian Georgescu
339 16 Ruud Klaver
Notifications sent by the {{{Engine}}} are notifications that are related to the {{{Engine}}} itself or unrelated to any SIP primitive object.
340 1 Adrian Georgescu
They are described here including the data attributes that is included with them.
341 1 Adrian Georgescu
342 29 Luci Stanescu
 '''SIPEngineWillStart'''::
343 16 Ruud Klaver
  This notification is sent when the {{{Engine}}} is about to start.
344 16 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
345 16 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
346 29 Luci Stanescu
 '''SIPEngineDidStart'''::
347 16 Ruud Klaver
  This notification is sent when the {{{Engine}}} is has just been started.
348 16 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
349 16 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
350 29 Luci Stanescu
 '''SIPEngineDidFail'''::
351 16 Ruud Klaver
  This notification is sent whenever the {{{Engine}}} has failed fatally and either cannot start or is about to stop.
352 16 Ruud Klaver
  It is not recommended to call any methods on the {{{Engine}}} at this point.
353 16 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
354 16 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
355 29 Luci Stanescu
 '''SIPEngineWillEnd'''::
356 16 Ruud Klaver
  This notification is sent when the {{{Engine}}} is about to stop because the application called the {{{stop()}}} method.
357 16 Ruud Klaver
  Methods on the {{{Engine}}} can be called at this point, but anything that has a delayed result will probably not return any notification.
358 16 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
359 16 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
360 29 Luci Stanescu
 '''SIPEngineDidEnd'''::
361 16 Ruud Klaver
  This notification is sent when the {{{Engine}}} was running and is now stopped, either because of failure or because the application requested it.
362 16 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
363 16 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
364 29 Luci Stanescu
 '''SIPEngineLog'''::
365 1 Adrian Georgescu
  This notification is a wrapper for PJSIP logging messages.
366 1 Adrian Georgescu
  It can be used by the application to output PJSIP logging to somewhere meaningful, possibly doing filtering based on log level.
367 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
368 1 Adrian Georgescu
  A {{{datetime.datetime}}} object representing the time when the log message was output by PJSIP.
369 1 Adrian Georgescu
  [[BR]]''sender'':[[BR]]
370 1 Adrian Georgescu
  The PJSIP module that originated this log message.
371 1 Adrian Georgescu
  [[BR]]''level'':[[BR]]
372 1 Adrian Georgescu
  The logging level of the message as an integer.
373 1 Adrian Georgescu
  Currently this is 1 through 5, 1 being the most critical.
374 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
375 1 Adrian Georgescu
  The actual log message.
376 29 Luci Stanescu
 '''SIPEngineSIPTrace'''::
377 1 Adrian Georgescu
  Will be sent only when the {{{do_siptrace}}} attribute of the {{{Engine}}} instance is set to {{{True}}}.
378 1 Adrian Georgescu
  The notification data attributes will contain the SIP messages as they are sent and received on the wire.
379 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
380 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
381 1 Adrian Georgescu
  [[BR]]''received'':[[BR]]
382 1 Adrian Georgescu
  A boolean indicating if this message was sent from or received by PJSIP (i.e. the direction of the message).
383 1 Adrian Georgescu
  [[BR]]''source_ip'':[[BR]]
384 1 Adrian Georgescu
  The source IP address as a string.
385 1 Adrian Georgescu
  [[BR]]''source_port'':[[BR]]
386 29 Luci Stanescu
  The source port of the message as an integer.
387 1 Adrian Georgescu
  [[BR]]''destination_ip'':[[BR]]
388 1 Adrian Georgescu
  The destination IP address as a string.
389 1 Adrian Georgescu
  [[BR]]''source_port'':[[BR]]
390 1 Adrian Georgescu
  The source port of the message as an integer.
391 1 Adrian Georgescu
  [[BR]]''data'':[[BR]]
392 1 Adrian Georgescu
  The contents of the message as a string.
393 1 Adrian Georgescu
394 1 Adrian Georgescu
> For received message the destination_ip and for sent messages the source_ip may not be reliable.
395 1 Adrian Georgescu
396 29 Luci Stanescu
 '''SIPEngineDetectedNATType'''::
397 1 Adrian Georgescu
  This notification is sent some time after the application request the NAT type this host behind to be detected using a STUN server.
398 1 Adrian Georgescu
  Note that there is no way to associate a request to do this with a notification, although every call to the {{{detect_nat_type()}}} method will generate exactly one notification.
399 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
400 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
401 1 Adrian Georgescu
  [[BR]]''succeeded'':[[BR]]
402 1 Adrian Georgescu
  A boolean indicating if the NAT detection succeeded.
403 38 Ruud Klaver
  [[BR]]''user_data'':[[BR]]
404 38 Ruud Klaver
  The {{{user_data}}} argument passed while calling the {{{detect_nat_type()}}} method.
405 38 Ruud Klaver
  This can be any object and could be used for matching requests to responses.
406 1 Adrian Georgescu
  [[BR]]''nat_type'':[[BR]]
407 1 Adrian Georgescu
  A string describing the type of NAT found.
408 1 Adrian Georgescu
  This value is only present if NAT detection succeeded.
409 1 Adrian Georgescu
  [[BR]]''error'':[[BR]]
410 1 Adrian Georgescu
  A string indicating the error that occurred while attempting to detect the type of NAT.
411 1 Adrian Georgescu
  This value only present if NAT detection did not succeed.
412 1 Adrian Georgescu
 '''SIPEngineGotException'''::
413 1 Adrian Georgescu
  This notification is sent whenever there is an unexpected exception within the PJSIP working thread.
414 1 Adrian Georgescu
  The application should show the traceback to the user somehow.
415 1 Adrian Georgescu
  An exception need not be fatal, but if it is it will be followed by a '''SIPEngineDidFail''' notification.
416 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
417 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
418 1 Adrian Georgescu
  [[BR]]''traceback'':[[BR]]
419 1 Adrian Georgescu
  A string containing the traceback of the exception.
420 1 Adrian Georgescu
  In general this should be printed on the console.
421 1 Adrian Georgescu
422 79 Ruud Klaver
=== ConferenceBridge ===
423 79 Ruud Klaver
424 79 Ruud Klaver
A {{{ConferenceBridges}}} manages two audio devices, on for input and one for output, and a fully routable audio mixer for a number of sources.
425 79 Ruud Klaver
It wraps a [http://www.pjsip.org/pjmedia/docs/html/group__PJMEDIA__CONF.htm PJSIP conference bridge], the concept of which is explained in the [http://trac.pjsip.org/repos/wiki/Python_SIP/Media PJSIP documentation].
426 79 Ruud Klaver
Any component in the core that either produces or consumes sound, i.e. {{{AudioTransport}}}, {{{ToneGenerator}}}, {{{WaveFile}}} and {{{RecordingWaveFile}}} objects, has a {{{ConferenceBridge}}} associated with it and a corresponding slot on that conference bridge.
427 79 Ruud Klaver
The sound devices, both input and output, together always occupy slot 0.
428 79 Ruud Klaver
It is up to the application to setup the desired routing between these components.
429 79 Ruud Klaver
430 79 Ruud Klaver
==== attributes ====
431 79 Ruud Klaver
432 79 Ruud Klaver
 '''input_device'''::
433 79 Ruud Klaver
  A string specifying the audio input device that is currently being used.
434 79 Ruud Klaver
  If there is no input device, this attribute will be {{{None}}}.
435 79 Ruud Klaver
  This attribute is read-only, but may be updated by calling the {{{set_sound_devices()}}} method.
436 79 Ruud Klaver
 '''output_device'''::
437 79 Ruud Klaver
  A string specifying the audio output device that is currently being used.
438 79 Ruud Klaver
  If there is no output device, this attribute will be {{{None}}}.
439 79 Ruud Klaver
  This attribute is read-only, but may be updated by calling the {{{set_sound_devices()}}} method.
440 79 Ruud Klaver
 '''sample_rate'''::
441 79 Ruud Klaver
  The sample rate in Hz that the conference bridge is currently operating on.
442 79 Ruud Klaver
  This read-only attribute is passed when the object is created.
443 79 Ruud Klaver
 '''ec_tail_length'''::
444 79 Ruud Klaver
  The current echo cancellation tail length in ms.
445 79 Ruud Klaver
  If this value is 0, no echo cancellation is used.
446 79 Ruud Klaver
  This attribute is read-only, but may be updated by calling the {{{set_sound_devices()}}} method.
447 79 Ruud Klaver
 '''slot_count'''::
448 79 Ruud Klaver
  The total number of slots that is available on the conference bridge
449 79 Ruud Klaver
  This read-only attribute is passed when the object is created.
450 79 Ruud Klaver
 '''used_slot_count'''::
451 79 Ruud Klaver
  A read-only attribute indicating the number of slots that are used by objects.
452 79 Ruud Klaver
 '''volume'''::
453 79 Ruud Klaver
  This writable property indicates the % of volume that is sent to the audio output device.
454 79 Ruud Klaver
  By default this value is 100.
455 79 Ruud Klaver
 '''is_muted'''::
456 79 Ruud Klaver
  This writable boolean property indicates if the input audio device is muted.
457 79 Ruud Klaver
 '''connected_slots'''::
458 79 Ruud Klaver
  A read-only list of tupples indicating which slot is connected to which.
459 79 Ruud Klaver
  Connections are directional.
460 79 Ruud Klaver
461 79 Ruud Klaver
==== methods ====
462 79 Ruud Klaver
463 79 Ruud Klaver
 '''!__init!__'''(''self'', '''input_device''', '''output_device''', '''sample_rate''', '''ec_tail_length'''=200, '''slot_count'''=254)::
464 79 Ruud Klaver
  Creates a new {{{ConferenceBridge}}} object.
465 79 Ruud Klaver
  [[BR]]''input_device'':[[BR]]
466 79 Ruud Klaver
  The name of the audio input device to use as a string, or {{{None}}} if no input device is to be used.
467 79 Ruud Klaver
  A list of known input devices can be queried through the {{{Engine.input_devices}}} attribute.
468 79 Ruud Klaver
  If {{{"default"}}} is used, PJSIP will select the system default output device, or {{{None}}} if no audio input device is present.
469 79 Ruud Klaver
  The device that was selected can be queried afterwards through the {{{input_device}}} attribute.
470 79 Ruud Klaver
  [[BR]]''output_device'':[[BR]]
471 79 Ruud Klaver
  The name of the audio output device to use as a string, or {{{None}}} if no output device is to be used.
472 79 Ruud Klaver
  A list of known output devices can be queried through the {{{Engine.output_devices}}} attribute.
473 79 Ruud Klaver
  If {{{"default"}}} is used, PJSIP will select the system default output device, or {{{None}}} if no audio output device is present.
474 79 Ruud Klaver
  The device that was selected can be queried afterwards through the {{{output_device}}} attribute.
475 79 Ruud Klaver
  [[BR]]''sample_rate'':[[BR]]
476 79 Ruud Klaver
  The sample rate on which the conference bridge and sound devices should operate in Hz.
477 79 Ruud Klaver
  This must be a multiple of 50.
478 79 Ruud Klaver
  [[BR]]''ec_tail_length'':[[BR]]
479 79 Ruud Klaver
  The echo cancellation tail length in ms.
480 79 Ruud Klaver
  If this value is 0, no echo cancellation is used.
481 79 Ruud Klaver
  [[BR]]''slot_count'':[[BR]]
482 79 Ruud Klaver
  The number of slots to allocate on the conference bridge.
483 79 Ruud Klaver
  Not that this includes the slot that is occupied by the sound devices.
484 79 Ruud Klaver
 '''set_sound_devices'''(''self'', '''input_device''', '''output_device''', '''ec_tail_length''')::
485 79 Ruud Klaver
  Change the sound devices used (including echo cancellation) by the conference bridge.
486 79 Ruud Klaver
  The meaning of the parameters is that same as for {{{__init__()}}}.
487 79 Ruud Klaver
 '''connect_slots'''(''self'', '''src_slot''', '''dst_slot''')::
488 79 Ruud Klaver
  Connect two slots on the conference bridge, making audio flow from {{{src_slot}}} to {{{dst_slot}}}.
489 79 Ruud Klaver
 '''disconnect_slots'''(''self'', '''src_slot''', '''dst_slot''')::
490 79 Ruud Klaver
  Break the connection between the specified slots.
491 79 Ruud Klaver
  Note that when an audio object is stopped or destroyed, its connections on the conference bridge will automatically be removed.
492 79 Ruud Klaver
493 1 Adrian Georgescu
=== SIPURI ===
494 1 Adrian Georgescu
495 1 Adrian Georgescu
This is a helper object for representing a SIP URI.
496 1 Adrian Georgescu
This object needs to be used whenever a SIP URI should be specified to the SIP core.
497 1 Adrian Georgescu
It supports comparison to other {{{SIPURI}}} objects using the == and != expressions.
498 1 Adrian Georgescu
As all of its attributes are set by the {{{__init__}}} method, the individual attributes will not be documented here.
499 1 Adrian Georgescu
500 1 Adrian Georgescu
==== methods ====
501 1 Adrian Georgescu
502 23 Ruud Klaver
 '''!__init!__'''(''self'', '''host''', '''user'''={{{None}}}, '''port'''={{{None}}}, '''display'''={{{None}}}, '''secure'''={{{False}}}, '''parameters'''={{{None}}}, '''headers'''={{{None}}})::
503 1 Adrian Georgescu
  Creates the SIPURI object with the specified parameters as attributes.
504 1 Adrian Georgescu
  Each of these attributes can be accessed and changed on the object once instanced.
505 1 Adrian Georgescu
  {{{host}}} is the only mandatory attribute.
506 1 Adrian Georgescu
  [[BR]]''host'':[[BR]]
507 1 Adrian Georgescu
  The host part of the SIP URI as a string.
508 1 Adrian Georgescu
  [[BR]]''user'':[[BR]]
509 1 Adrian Georgescu
  The username part of the SIP URI as a string, or None if not set.
510 1 Adrian Georgescu
  [[BR]]''port'':[[BR]]
511 1 Adrian Georgescu
  The port part of the SIP URI as an int, or None or 0 if not set.
512 1 Adrian Georgescu
  [[BR]]''display'':[[BR]]
513 1 Adrian Georgescu
  The optional display name of the SIP URI as a string, or None if not set.
514 1 Adrian Georgescu
  [[BR]]''secure'':[[BR]]
515 1 Adrian Georgescu
  A boolean indicating whether this is a SIP or SIPS URI, the latter being indicated by a value of {{{True}}}.
516 1 Adrian Georgescu
  [[BR]]''parameters'':[[BR]]
517 1 Adrian Georgescu
  The URI parameters. represented by a dictionary.
518 1 Adrian Georgescu
  [[BR]]''headers'':[[BR]]
519 1 Adrian Georgescu
  The URI headers, represented by a dictionary.
520 1 Adrian Georgescu
 '''!__str!__'''(''self'')::
521 1 Adrian Georgescu
  The special Python method to represent this object as a string, the output is the properly formatted SIP URI.
522 1 Adrian Georgescu
 '''copy'''(''self'')::
523 1 Adrian Georgescu
  Returns a copy of the {{{SIPURI}}} object.
524 1 Adrian Georgescu
525 1 Adrian Georgescu
=== Credentials ===
526 1 Adrian Georgescu
527 61 Ruud Klaver
This simple object represents authentication credentials for a particular SIP account.
528 61 Ruud Klaver
These can be included whenever creating a SIP primitive object that originates SIP requests.
529 1 Adrian Georgescu
As with the {{{SIPURI}}} object, the attributes of this object are the same as the arguments to the {{{__init__}}} method.
530 61 Ruud Klaver
Note that the domain name of the SIP account is not stored on this object.
531 1 Adrian Georgescu
532 1 Adrian Georgescu
==== methods ====
533 1 Adrian Georgescu
534 61 Ruud Klaver
 '''!__init!__'''(''self'', '''username''', '''password''')::
535 1 Adrian Georgescu
  Creates the Credentials object with the specified parameters as attributes.
536 1 Adrian Georgescu
  Each of these attributes can be accessed and changed on the object once instanced.
537 61 Ruud Klaver
  [[BR]]''username'':[[BR]]
538 61 Ruud Klaver
  A string representing the username of the account for which these are the credentials.
539 1 Adrian Georgescu
  [[BR]]''password'':[[BR]]
540 1 Adrian Georgescu
  The password for this SIP account as a string.
541 1 Adrian Georgescu
 '''copy'''(''self'')::
542 1 Adrian Georgescu
  Returns a copy of the {{{Credentials}}} object.
543 1 Adrian Georgescu
544 1 Adrian Georgescu
=== Route ===
545 1 Adrian Georgescu
546 22 Ruud Klaver
This class provides a means for the application using the SIP core to set the destination address, port and transport for a particular request, i.e. the outbound proxy.
547 33 Ruud Klaver
As it is the application's responsibility to look this up and pass it as an argument for every SIP primitive class it creates.
548 22 Ruud Klaver
The contents of the {{{Route}}} object will be placed in the {{{Route}}} header of the request.
549 1 Adrian Georgescu
As with the {{{SIPURI}}} object, the attributes of this object are the same as the arguments to the {{{__init__}}} method.
550 1 Adrian Georgescu
551 1 Adrian Georgescu
==== methods ====
552 1 Adrian Georgescu
553 22 Ruud Klaver
 '''!__init!__'''(''self'', '''address''', '''port'''=5060, '''transport'''={{{None}}})::
554 1 Adrian Georgescu
  Creates the Route object with the specified parameters as attributes.
555 1 Adrian Georgescu
  Each of these attributes can be accessed on the object once instanced.
556 22 Ruud Klaver
  [[BR]]''address'':[[BR]]
557 45 Ruud Klaver
  The IPv4 address that the request in question should be sent to as a string.
558 1 Adrian Georgescu
  [[BR]]''port'':[[BR]]
559 22 Ruud Klaver
  The port to send the requests to, represented as an int.
560 1 Adrian Georgescu
  [[BR]]''transport'':[[BR]]
561 35 Ruud Klaver
  The transport to use, this can be a string of either "udp", "tcp" or "tls" (case insensitive), depending on what transports are enabled on the {{{PJSIPUA}}} object.
562 1 Adrian Georgescu
 '''copy'''(''self'')::
563 1 Adrian Georgescu
  Returns a copy of the {{{Route}}} object.
564 22 Ruud Klaver
565 46 Ruud Klaver
=== Request ===
566 46 Ruud Klaver
567 46 Ruud Klaver
The {{{sipsimple.core.Request}}} object encapsulates a single SIP request transaction from the client side, which includes sending the request, receiving the response and possibly waiting for the result of the request to expire.
568 46 Ruud Klaver
Although this class can be used by the application to construct and send an arbitrary SIP request, most applications will use the classes provided in the {{{sipsimple.primitives}}} module, which are built on top of one or several {{{Request}}} objects and deal with instances of specific SIP methods.
569 46 Ruud Klaver
570 46 Ruud Klaver
The lifetime of this object is linear and is described by the following diagram:
571 46 Ruud Klaver
572 46 Ruud Klaver
[[Image(sipsimple-request-lifetime.png, nolink)]]
573 46 Ruud Klaver
574 46 Ruud Klaver
The bar denotes which state the object is in and at the top are the notifications which may be emitted at certain points in time.
575 46 Ruud Klaver
Directly after the object is instantiated, it will be in the {{{INIT}}} state.
576 46 Ruud Klaver
The request will be sent over the network once its {{{send()}}} method is called, moving the object into the {{{IN_PROGRESS}}} state.
577 46 Ruud Klaver
On each provisional response that is received in reply to this request, the {{{SIPRequestGotProvisionalResponse}}} notification is sent, with data describing the response.
578 46 Ruud Klaver
Note that this may not occur at all if not provisional responses are received.
579 46 Ruud Klaver
When the {{{send()}}} method has been called and it does not return an exception, the object will send either a {{{SIPRequestDidSucceed}}} or a {{{SIPRequestDidFail}}} notification.
580 46 Ruud Klaver
Both of these notifications include data on the response that triggered it.
581 46 Ruud Klaver
Note that a SIP response that requests authentication (401 or 407) will be handled internally the first time, if a {{{Credentials}}} object was supplied.
582 46 Ruud Klaver
If this is the sort of request that expires (detected by a {{{Expires}}} header in the response or a {{{expires}}} parameter in the {{{Contact}}} header of the response), and the request was successful, the object will go into the {{{EXPIRING}}} state.
583 46 Ruud Klaver
A certain amount of time before the result of the request will expire, governed by the {{{expire_warning_time}}} class attribute and the actual returned expiration time, a {{{SIPRequestWillExpire}}} notification will be sent.
584 46 Ruud Klaver
This should usually trigger whomever is using this {{{Request}}} object to construct a new {{{Request}}} for a refreshing operation.
585 46 Ruud Klaver
When the {{{Request}}} actually expires, or when the {{{EXPIRING}}} state is skipped directly after sending {{{SIPRequestDidSucceed}}} or {{{SIPRequestDidFail}}}, a {{{SIPRequestDidEnd}}} notification will be sent.
586 46 Ruud Klaver
587 46 Ruud Klaver
==== attributes ====
588 46 Ruud Klaver
589 49 Ruud Klaver
 '''expire_warning_time''' (class attribute)::
590 49 Ruud Klaver
  The {{{SIPRequestWillExpire}}} notification will be sent halfway between the positive response and the actual expiration time, but at least this amount of seconds before.
591 49 Ruud Klaver
  The default value is 30 seconds.
592 47 Ruud Klaver
 '''state'''::
593 47 Ruud Klaver
  Indicates the state the {{{Request}}} object is in, in the form of a string.
594 47 Ruud Klaver
  Refer to the diagram above for possible states.
595 47 Ruud Klaver
  This attribute is read-only.
596 47 Ruud Klaver
 '''method'''::
597 47 Ruud Klaver
  The method of the SIP request as a string.
598 47 Ruud Klaver
  This attribute is set on instantiation and is read-only.
599 47 Ruud Klaver
 '''from_uri'''::
600 47 Ruud Klaver
  The SIP URI to put in the {{{From}}} header of the request, in the form of a {{{SIPURI}}} object.
601 62 Ruud Klaver
  This attribute is set on instantiation and is read-only.
602 47 Ruud Klaver
 '''to_uri'''::
603 47 Ruud Klaver
  The SIP URI to put in the {{{To}}} header of the request, in the form of a {{{SIPURI}}} object.
604 47 Ruud Klaver
  This attribute is set on instantiation and is read-only.
605 47 Ruud Klaver
 '''request_uri'''::
606 47 Ruud Klaver
  The SIP URI to put as request URI in the request, in the form of a {{{SIPURI}}} object.
607 47 Ruud Klaver
  This attribute is set on instantiation and is read-only.
608 1 Adrian Georgescu
 '''route'''::
609 1 Adrian Georgescu
  Where to send the SIP request to, including IP, port and transport, in the form of a {{{SIPURI}}} object.
610 1 Adrian Georgescu
  This will also be included in the {{{Route}}} header of the request.
611 1 Adrian Georgescu
  This attribute is set on instantiation and is read-only.
612 62 Ruud Klaver
 '''credentials'''::
613 62 Ruud Klaver
  The credentials to be used when challenged for authentication, represented by a {{{Credentials}}} object.
614 62 Ruud Klaver
  If no credentials were supplied when the object was created this attribute is {{{None}}}.
615 62 Ruud Klaver
  This attribute is set on instantiation and is read-only.
616 47 Ruud Klaver
 '''contact_uri'''::
617 47 Ruud Klaver
  The SIP URI to put in the {{{Contact}}} header of the request, in the form of a {{{SIPURI}}} object.
618 47 Ruud Klaver
  If this was not specified, this attribute is {{{None}}}.
619 47 Ruud Klaver
  It is set on instantiation and is read-only.
620 47 Ruud Klaver
 '''call_id'''::
621 47 Ruud Klaver
  The {{{Call-ID}}} to be used for this transaction as a string.
622 47 Ruud Klaver
  If no call id was specified on instantiation, this attribute contains the generated id.
623 47 Ruud Klaver
  This attribute is set on instantiation and is read-only.
624 47 Ruud Klaver
 '''cseq'''::
625 47 Ruud Klaver
  The sequence number to use in the request as an int.
626 47 Ruud Klaver
  If no sequence number was specified on instantiation, this attribute contains the generated sequence number.
627 47 Ruud Klaver
  Note that this number may be increased by one if an authentication challenge is received and a {{{Credentials}}} object is given.
628 47 Ruud Klaver
  This attribute is read-only.
629 47 Ruud Klaver
 '''extra_headers'''::
630 47 Ruud Klaver
  Extra headers to include in the request as a dictionary.
631 47 Ruud Klaver
  This attribute is set on instantiation and is read-only.
632 47 Ruud Klaver
 '''content_type'''::
633 47 Ruud Klaver
  What string to put as content type in the {{{Content-Type}}} headers, if the request contains a body.
634 47 Ruud Klaver
  If no body was specified, this attribute is {{{None}}}
635 47 Ruud Klaver
  It is set on instantiation and is read-only.
636 47 Ruud Klaver
 '''body'''::
637 47 Ruud Klaver
  The body of the request as a string.
638 47 Ruud Klaver
  If no body was specified, this attribute is {{{None}}}
639 47 Ruud Klaver
  It is set on instantiation and is read-only.
640 47 Ruud Klaver
 '''expires_in'''::
641 1 Adrian Georgescu
  This read-only property indicates in how many seconds from now this {{{Request}}} will expire, if it is in the {{{EXPIRING}}} state.
642 47 Ruud Klaver
  If this is not the case, this property is 0.
643 47 Ruud Klaver
644 46 Ruud Klaver
==== methods ====
645 46 Ruud Klaver
646 62 Ruud Klaver
 '''!__init!__'''(''self'', '''method''', '''from_uri''', '''to_uri''', '''request_uri''', '''route''', '''credentials'''={{{None}}}, '''contact_uri'''={{{None}}}, '''call_id'''={{{None}}}, '''cseq'''={{{None}}}, '''extra_headers'''={{{None}}}, '''content_type'''={{{None}}}, '''body'''={{{None}}})::
647 48 Ruud Klaver
  Creates a new {{{Request}}} object in the {{{INIT}}} state.
648 48 Ruud Klaver
  The arguments to this method are documented in the attributes section.
649 48 Ruud Klaver
 '''send'''(''self'', '''timeout'''={{{None}}})::
650 48 Ruud Klaver
   Compose the SIP request and send it to the destination.
651 48 Ruud Klaver
   This moves the {{{Request}}} object into the {{{IN_PROGRESS}}} state.
652 48 Ruud Klaver
  [[BR]]''timeout'':[[BR]]
653 48 Ruud Klaver
  This can be either an int or a float, indicating in how many seconds the request should timeout with an internally generated 408 response.
654 48 Ruud Klaver
  This is is {{{None}}}, the internal 408 is only triggered by the internal PJSIP transaction timeout.
655 48 Ruud Klaver
  Note that, even if the timeout is specified, the PJSIP timeout is also still valid.
656 57 Ruud Klaver
 '''end'''(''self'')::
657 48 Ruud Klaver
  Terminate the transaction, whichever state it is in, sending the appropriate notifications.
658 48 Ruud Klaver
  Note that calling this method while in the {{{INIT}}} state does nothing.
659 48 Ruud Klaver
660 46 Ruud Klaver
==== notifications ====
661 49 Ruud Klaver
662 49 Ruud Klaver
 '''SIPRequestGotProvisionalResponse'''::
663 49 Ruud Klaver
  This notification will be sent on every provisional response received in reply to the sent request.
664 49 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
665 49 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
666 49 Ruud Klaver
  [[BR]]''code'':[[BR]]
667 49 Ruud Klaver
  The SIP response code of the received provisional response as an int, which will be in the 1xx range.
668 49 Ruud Klaver
  [[BR]]''reason'':[[BR]]
669 49 Ruud Klaver
  The reason text string included with the SIP response code.
670 49 Ruud Klaver
  [[BR]]''headers'':[[BR]]
671 49 Ruud Klaver
  The headers included in the provisional response as a dictionary.
672 49 Ruud Klaver
  [[BR]]''body'':[[BR]]
673 49 Ruud Klaver
  The body of the provisional response as a string, or {{{None}}} if there was no body.
674 49 Ruud Klaver
 '''SIPRequestDidSucceed'''::
675 49 Ruud Klaver
  This notification will be sent when a positive final response was received in reply to the request.
676 49 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
677 49 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
678 49 Ruud Klaver
  [[BR]]''code'':[[BR]]
679 49 Ruud Klaver
  The SIP response code of the received positive final response as an int, which will be in the 2xx range.
680 49 Ruud Klaver
  [[BR]]''reason'':[[BR]]
681 49 Ruud Klaver
  The reason text string included with the SIP response code.
682 49 Ruud Klaver
  [[BR]]''headers'':[[BR]]
683 49 Ruud Klaver
  The headers included in the positive final response as a dictionary.
684 49 Ruud Klaver
  [[BR]]''body'':[[BR]]
685 49 Ruud Klaver
  The body of the positive final response as a string, or {{{None}}} if there was no body.
686 49 Ruud Klaver
  [[BR]]''expires'':[[BR]]
687 49 Ruud Klaver
  Indicates in how many seconds the {{{Request}}} will expire as an int.
688 49 Ruud Klaver
  If it does not expire and the {{{EXPIRING}}} state is skipped, this attribute is 0.
689 49 Ruud Klaver
 '''SIPRequestDidFail'''::
690 49 Ruud Klaver
  This notification will be sent when a negative final response is received in reply to the request or if an internal error occurs.
691 49 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
692 49 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
693 49 Ruud Klaver
  [[BR]]''code'':[[BR]]
694 49 Ruud Klaver
  The SIP response code of the received negative final response as an int.
695 49 Ruud Klaver
  This could also be a response code generated by PJSIP internally, or 0 when an internal error occurs.
696 49 Ruud Klaver
  [[BR]]''reason'':[[BR]]
697 49 Ruud Klaver
  The reason text string included with the SIP response code or error.
698 49 Ruud Klaver
  [[BR]]''headers'': (only if a negative final response was received)[[BR]]
699 49 Ruud Klaver
  The headers included in the negative final response as a dictionary, if this is what triggered the notification.
700 49 Ruud Klaver
  [[BR]]''body'': (only if a negative final response was received)[[BR]]
701 49 Ruud Klaver
  The body of the negative final response as a string, or {{{None}}} if there was no body.
702 49 Ruud Klaver
  This attribute is absent if no response was received.
703 49 Ruud Klaver
 '''SIPRequestWillExpire'''::
704 49 Ruud Klaver
  This notification will be sent when a {{{Request}}} in the {{{EXPIRING}}} state will expire soon.
705 49 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
706 49 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
707 49 Ruud Klaver
  [[BR]]''expires'':[[BR]]
708 49 Ruud Klaver
  An int indicating in how many seconds from now the {{{Request}}} will actually expire.
709 49 Ruud Klaver
 '''SIPRequestDidEnd'''::
710 49 Ruud Klaver
  This notification will be sent when a {{{Request}}} object enters the {{{TERMINATED}}} state and can no longer be used.
711 49 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
712 49 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
713 46 Ruud Klaver
714 51 Ruud Klaver
=== Message ===
715 51 Ruud Klaver
716 51 Ruud Klaver
The {{{sipsimple.primitives.Message}}} class is a simple wrapper for the {{{Request}}} class, with the purpose of sending {{{MESSAGE}}} requests, as described in [http://tools.ietf.org/html/rfc3428 RFC 3428].
717 51 Ruud Klaver
It is a one-shot object that manages only one {{{Request}}} object.
718 51 Ruud Klaver
719 51 Ruud Klaver
==== attributes ====
720 51 Ruud Klaver
721 64 Ruud Klaver
 '''from_uri'''::
722 64 Ruud Klaver
  The SIP URI to put in the {{{From}}} header of the {{{MESSAGE}}} request, in the form of a {{{SIPURI}}} object.
723 51 Ruud Klaver
  This attribute is set on instantiation and is read-only.
724 51 Ruud Klaver
 '''to_uri'''::
725 51 Ruud Klaver
  The SIP URI to put in the {{{To}}} header of the {{{MESSAGE}}} request, in the form of a {{{SIPURI}}} object.
726 51 Ruud Klaver
  This attribute is set on instantiation and is read-only.
727 51 Ruud Klaver
 '''route'''::
728 51 Ruud Klaver
  Where to send the {{{MESSAGE}}} request to, including IP, port and transport, in the form of a {{{SIPURI}}} object.
729 51 Ruud Klaver
  This will also be included in the {{{Route}}} header of the request.
730 51 Ruud Klaver
  This attribute is set on instantiation and is read-only.
731 51 Ruud Klaver
 '''content_type'''::
732 51 Ruud Klaver
  What string to put as content type in the {{{Content-Type}}} headers.
733 51 Ruud Klaver
  It is set on instantiation and is read-only.
734 51 Ruud Klaver
 '''body'''::
735 51 Ruud Klaver
  The body of the {{{MESSAGE}}} request as a string.
736 1 Adrian Georgescu
  If no body was specified, this attribute is {{{None}}}
737 1 Adrian Georgescu
  It is set on instantiation and is read-only.
738 64 Ruud Klaver
 '''credentials'''::
739 64 Ruud Klaver
  The credentials to be used when challenged for authentication, represented by a {{{Credentials}}} object.
740 64 Ruud Klaver
  If no credentials were specified, this attribute is {{{None}}}.
741 64 Ruud Klaver
  This attribute is set on instantiation and is read-only.
742 51 Ruud Klaver
 '''is_sent'''::
743 51 Ruud Klaver
  A boolean read-only property indicating if the {{{MESSAGE}}} request was sent.
744 51 Ruud Klaver
 '''in_progress'''::
745 51 Ruud Klaver
  A boolean read-only property indicating if the object is waiting for the response from the remote party.
746 51 Ruud Klaver
747 51 Ruud Klaver
==== methods ====
748 51 Ruud Klaver
749 51 Ruud Klaver
 '''!__init!__'''(''self'', '''credentials''', '''to_uri''', '''route''', '''content_type''', '''body''')::
750 51 Ruud Klaver
  Creates a new {{{Message}}} object with the specified arguments.
751 51 Ruud Klaver
  These arguments are documented in the attributes section for this class.
752 51 Ruud Klaver
 '''send'''(''self'', '''timeout'''={{{None}}})::
753 51 Ruud Klaver
  Send the {{{MESSAGE}}} request to the remote party.
754 51 Ruud Klaver
  [[BR]]''timeout'':[[BR]]
755 51 Ruud Klaver
  This argument as the same meaning as it does for {{{Request.send()}}}.
756 51 Ruud Klaver
 '''end'''(''self'')::
757 51 Ruud Klaver
  Stop trying to send the {{{MESSAGE}}} request.
758 51 Ruud Klaver
  If it was not sent yet, calling this method does nothing.
759 51 Ruud Klaver
760 51 Ruud Klaver
==== notifications ====
761 51 Ruud Klaver
762 51 Ruud Klaver
 '''SIPMessageDidSucceed'''::
763 51 Ruud Klaver
  This notification will be sent when the remote party acknowledged the reception of the {{{MESSAGE}}} request.
764 52 Ruud Klaver
  It has not data attributes.
765 51 Ruud Klaver
 '''SIPMessageDidFail'''::
766 51 Ruud Klaver
  This notification will be sent when transmission of the {{{MESSAGE}}} request fails for whatever reason.
767 51 Ruud Klaver
  [[BR]]''code'':[[BR]]
768 1 Adrian Georgescu
  An int indicating the SIP or internal PJSIP code that was given in response to the {{{MESSAGE}}} request.
769 1 Adrian Georgescu
  This is 0 if the failure is caused by an internal error.
770 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
771 1 Adrian Georgescu
  A status string describing the failure, either taken from the SIP response or the internal error.
772 52 Ruud Klaver
773 52 Ruud Klaver
=== Registration ===
774 52 Ruud Klaver
775 52 Ruud Klaver
The {{{sipsimple.primitives.Registration}}} class wraps a series of {{{Request}}} objects, managing the registration of a particular contact URI at a SIP registrar through the sending of {{{REGISTER}}} requests.
776 52 Ruud Klaver
For details, see [http://tools.ietf.org/html/rfc3261 RFC 3261].
777 52 Ruud Klaver
This object is designed in such a way that it will not initiate sending a refreshing {{{REGISTER}}} itself, rather it will inform the application that a registration is about to expire.
778 1 Adrian Georgescu
The application should then perform a DNS lookup to find the relevant SIP registrar and call the {{{register()}}} method on this object.
779 1 Adrian Georgescu
780 52 Ruud Klaver
==== attributes ====
781 69 Ruud Klaver
782 64 Ruud Klaver
 '''uri''::
783 64 Ruud Klaver
  The SIP URI of the account the {{{Registration}}} is for in the form of a {{{SIPURI}}} object.
784 52 Ruud Klaver
 '''credentials'''::
785 64 Ruud Klaver
  The credentials to be used when challenged for authentication by the registrar, represented by a {{{Credentials}}} object. 
786 64 Ruud Klaver
  This attribute is set at instantiation, can be {{{None}}} if it was not specified and can be updated to be used for the next {{{REGISTER}}} request.
787 52 Ruud Klaver
  Note that, in contrast to other classes mentioned in this document, the {{{Registration}}} class does not make a copy of the {{{Credentials}}} object on instantiation, but instead retains a reference to it.
788 52 Ruud Klaver
 '''duration'''::
789 52 Ruud Klaver
  The amount of time in seconds to request the registration for at the registrar.
790 52 Ruud Klaver
  This attribute is set at object instantiation and can be updated for subsequent {{{REGISTER}}} requests.
791 52 Ruud Klaver
 '''is_registered'''::
792 52 Ruud Klaver
  A boolean read-only property indicating if this object is currently registered.
793 52 Ruud Klaver
 '''contact_uri'''::
794 52 Ruud Klaver
  If the {{{Registration}}} object is registered, this attribute contains the latest contact URI that was sent to the registrar as a {{{SIPURI}}} object.
795 1 Adrian Georgescu
  Otherwise, this attribute is {{{None}}}
796 52 Ruud Klaver
 '''expires_in'''::
797 52 Ruud Klaver
  If registered, this read-only property indicates in how many seconds from now this {{{Registration}}} will expire.
798 52 Ruud Klaver
  If this is not the case, this property is 0.
799 52 Ruud Klaver
800 52 Ruud Klaver
==== methods ====
801 52 Ruud Klaver
802 64 Ruud Klaver
 '''!__init!__'''(''self'', '''uri''', '''credentials'''={{{None}}}, '''duration'''=300)::
803 52 Ruud Klaver
  Creates a new {{{Registration}}} object with the specified arguments.
804 52 Ruud Klaver
  These arguments are documented in the attributes section for this class.
805 52 Ruud Klaver
 '''register'''(''self'', '''contact_uri''', '''route''', '''timeout'''={{{None}}})::
806 52 Ruud Klaver
  Calling this method will attempt to send a new {{{REGISTER}}} request to the registrar provided, whatever state the object is in.
807 52 Ruud Klaver
  If the object is currently busy sending a {{{REGISTER}}}, this request will be preempted for the new one.
808 52 Ruud Klaver
  Once sent, the {{{Registration}}} object will send either a {{{SIPRegistrationDidSucceed}}} or a {{{SIPRegistrationDidFail}}} notification.
809 58 Ruud Klaver
  The {{{contact_uri}}} argument is mentioned in the attributes section of this class.
810 52 Ruud Klaver
  The {{{route}}} argument specifies the IP address, port and transport of the SIP registrar in the form of a {{{Route}}} object and {{{timeout}}} has the same meaning as it does for {{{Request.send()}}}.
811 52 Ruud Klaver
 '''end'''(''self'', '''timeout'''={{{None}}})::
812 52 Ruud Klaver
  Calling this method while the object is registered will attempt to send a {{{REGISTER}}} request with the {{{Expires}}} headers set to 0, effectively unregistering the contact URI at the registrar.
813 52 Ruud Klaver
  The {{{Route}}} used for this will be the same as the last successfully sent {{{REGISTER}}} request.
814 52 Ruud Klaver
  If another {{{REGISTER}}} is currently being sent, it will be preempted.
815 71 Adrian Georgescu
  When the unregistering {{{REGISTER}}} request is sent, a {{{SIPRegistrationWillEnd}}} notification is sent.
816 52 Ruud Klaver
  After this, either a {{{SIPRegistrationDidEnd}}} with the {{{expired}}} data attribute set to {{{False}}} will be sent, indicating a successful unregister, or a {{{SIPRegistrationDidNotEnd}}} notification is send if unregistering fails for some reason.
817 52 Ruud Klaver
  Calling this method when the object is not registered will do nothing.
818 52 Ruud Klaver
  The {{{timeout}}} argument has the same meaning as for the {{{register()}}} method.
819 52 Ruud Klaver
820 52 Ruud Klaver
==== notifications ====
821 52 Ruud Klaver
822 52 Ruud Klaver
 '''SIPRegistrationDidSucceed'''::
823 52 Ruud Klaver
  This notification will be sent when the {{{register()}}} method was called and the registration succeeded.
824 52 Ruud Klaver
  [[BR]]''code'':[[BR]]
825 52 Ruud Klaver
  The SIP response code as received from the registrar as an int.
826 52 Ruud Klaver
  [[BR]]''reason'':[[BR]]
827 52 Ruud Klaver
  The reason string received from the SIP registrar.
828 52 Ruud Klaver
  [[BR]]''route'':[[BR]]
829 52 Ruud Klaver
  The {{{Route}}} object passed as an argument to the {{{register()}}} method.
830 52 Ruud Klaver
  [[BR]]''contact_uri'':[[BR]]
831 52 Ruud Klaver
  The contact URI that was sent to the registrar as a {{{SIPURI}}} object.
832 52 Ruud Klaver
  [[BR]]''contact_uri_list'':[[BR]]
833 52 Ruud Klaver
  A full list of contact URIs that are registered for this SIP account, including the one used for this registration.
834 52 Ruud Klaver
  The format of this data attribute is a list of 2-item tuples.
835 52 Ruud Klaver
  The first item is a SIP URI indicating the contact URI, the second item is a dictionary of additional parameters, including the {{{expires}}} parameter.
836 52 Ruud Klaver
  [[BR]]''expires_in'':[[BR]]
837 52 Ruud Klaver
  The number of seconds before this registration expires
838 52 Ruud Klaver
 '''SIPRegistrationDidFail'''::
839 52 Ruud Klaver
  This notification will be sent when the {{{register()}}} method was called and the registration failed, for whatever reason.
840 52 Ruud Klaver
  [[BR]]''code'':[[BR]]
841 52 Ruud Klaver
  The SIP response code as received from the registrar as an int.
842 52 Ruud Klaver
  This can also be a PJSIP generated response code, or 0 if the failure was because of an internal error.
843 52 Ruud Klaver
  [[BR]]''reason'':[[BR]]
844 52 Ruud Klaver
  The reason string received from the SIP registrar or the error string.
845 52 Ruud Klaver
  [[BR]]''route'':[[BR]]
846 52 Ruud Klaver
  The {{{Route}}} object passed as an argument to the {{{register()}}} method.
847 52 Ruud Klaver
 '''SIPRegistrationWillExpire'''::
848 52 Ruud Klaver
  This notification will be sent when a registration will expire soon.
849 1 Adrian Georgescu
  It should be used as an indication to re-perform DNS lookup of the registrar and call the {{{register()}}} method.
850 69 Ruud Klaver
  [[BR]]''expires'':[[BR]]
851 58 Ruud Klaver
  The number of seconds in which the registration will expire.
852 52 Ruud Klaver
 '''SIPRegistrationWillEnd'''::
853 52 Ruud Klaver
  Will be sent whenever the {{{end()}}} method was called and an unregistering {{{REGISTER}}} is sent.
854 52 Ruud Klaver
 '''SIPRegistrationDidNotEnd'''::
855 52 Ruud Klaver
  This notification will be sent when the unregistering {{{REGISTER}}} request failed for some reason.
856 52 Ruud Klaver
  [[BR]]''code'':[[BR]]
857 52 Ruud Klaver
  The SIP response code as received from the registrar as an int.
858 52 Ruud Klaver
  This can also be a PJSIP generated response code, or 0 if the failure was because of an internal error.
859 52 Ruud Klaver
  [[BR]]''reason'':[[BR]]
860 52 Ruud Klaver
  The reason string received from the SIP registrar or the error string.
861 52 Ruud Klaver
 '''SIPRegistrationDidEnd'''::
862 52 Ruud Klaver
  This notification will be sent when a {{{Registration}}} has become unregistered.
863 58 Ruud Klaver
  [[BR]]''expired'':[[BR]]
864 52 Ruud Klaver
  This boolean indicates if the object is unregistered because the registration expired, in which case it will be set to {{{True}}}.
865 52 Ruud Klaver
  If this data attribute is {{{False}}}, it means that unregistration was explicitly requested through the {{{end()}}} method.
866 52 Ruud Klaver
867 52 Ruud Klaver
==== example code ====
868 51 Ruud Klaver
869 1 Adrian Georgescu
For an example on how to use this object, see the Integration section.
870 1 Adrian Georgescu
871 1 Adrian Georgescu
=== Publication ===
872 1 Adrian Georgescu
873 1 Adrian Georgescu
Publication of SIP events is an Internet standard published at [http://tools.ietf.org/html/rfc3903 RFC 3903]. 
874 70 Ruud Klaver
{{{PUBLISH}}} is similar to {{{REGISTER}}} in that it allows a user to create, modify, and remove state in another entity which manages this state on behalf of the user.
875 1 Adrian Georgescu
876 69 Ruud Klaver
A {{{Publication}}} object represents publishing some content for a particular SIP account and a particular event type at the SIP presence agent through a series of {{{PUBLISH}}} request.
877 69 Ruud Klaver
This object is similar in behaviour to the {{{Registration}}} object, as it is also based on a sequence of {{{Request}}} objects.
878 69 Ruud Klaver
As with this other object, the {{{Publication}}} object will notify the application when a published item is about to expire and it is the applications responsibility to perform a DNS lookup and call the {{{publish()}}} method in order to send the {{{PUBLISH}}} request.
879 1 Adrian Georgescu
880 1 Adrian Georgescu
==== attributes ====
881 1 Adrian Georgescu
882 69 Ruud Klaver
 '''uri''::
883 69 Ruud Klaver
  The SIP URI of the account the {{{Publication}}} is for in the form of a {{{SIPURI}}} object.
884 69 Ruud Klaver
 '''event''::
885 69 Ruud Klaver
  The name of the event this object is publishing for the specified SIP URI, as a string.
886 69 Ruud Klaver
 '''content_type''::
887 69 Ruud Klaver
  The {{{Content-Type}}} of the body that will be in the {{{PUBLISH}}} requests.
888 69 Ruud Klaver
  Typically this will remain the same throughout the publication session, but the attribute may be updated by the application if needed.
889 69 Ruud Klaver
  Note that this attribute needs to be in the typical MIME type form, containing a "/" character.
890 1 Adrian Georgescu
 '''credentials'''::
891 69 Ruud Klaver
  The credentials to be used when challenged for authentication by the presence agent, represented by a {{{Credentials}}} object. 
892 69 Ruud Klaver
  This attribute is set at instantiation, can be {{{None}}} if it was not specified and can be updated to be used for the next {{{PUBLISH}}} request.
893 69 Ruud Klaver
  Note that, in contrast to most other classes mentioned in this document, the {{{Publication}}} class does not make a copy of the {{{Credentials}}} object on instantiation, but instead retains a reference to it.
894 69 Ruud Klaver
 '''duration'''::
895 69 Ruud Klaver
  The amount of time in seconds that the publication should be valid for.
896 69 Ruud Klaver
  This attribute is set at object instantiation and can be updated for subsequent {{{PUBLISH}}} requests.
897 69 Ruud Klaver
 '''is_published'''::
898 69 Ruud Klaver
  A boolean read-only property indicating if this object is currently published.
899 69 Ruud Klaver
 '''expires_in'''::
900 69 Ruud Klaver
  If published, this read-only property indicates in how many seconds from now this {{{Publication}}} will expire.
901 69 Ruud Klaver
  If this is not the case, this property is 0.
902 1 Adrian Georgescu
903 1 Adrian Georgescu
==== methods ====
904 1 Adrian Georgescu
905 69 Ruud Klaver
 '''!__init!__'''(''self'', '''uri''', '''event''', '''content_type''', '''credentials'''={{{None}}}, '''duration'''=300)::
906 69 Ruud Klaver
  Creates a new {{{Publication}}} object with the specified arguments.
907 69 Ruud Klaver
  These arguments are documented in the attributes section for this class.
908 69 Ruud Klaver
 '''publish'''(''self'', '''body''', '''route''', '''timeout'''={{{None}}})::
909 69 Ruud Klaver
  Send an actual {{{PUBLISH}}} request to the specified presence agent.
910 69 Ruud Klaver
  [[BR]]''body'':[[BR]]
911 69 Ruud Klaver
  The body to place in the {{{PUBLISH}}} request as a string.
912 69 Ruud Klaver
  This body needs to be of the content type specified at object creation.
913 69 Ruud Klaver
  For the initial request, a body will need to be specified.
914 69 Ruud Klaver
  For subsequent refreshing {{{PUBLISH}}} requests, the body can be {{{None}}} to indicate that the last published body should be refreshed.
915 69 Ruud Klaver
  If there was an ETag error with the previous refreshing {{{PUBLISH}}}, calling this method with a body of {{{None}}} will throw a {{{PublicationError}}}.
916 1 Adrian Georgescu
  [[BR]]''route'':[[BR]]
917 69 Ruud Klaver
  The host where the request should be sent to in the form of a {{{Route}}} object.
918 69 Ruud Klaver
  [[BR]]''timeout'':[[BR]]
919 69 Ruud Klaver
  This can be either an int or a float, indicating in how many seconds the {{{SUBSCRIBE}}} request should timeout with an internally generated 408 response.
920 69 Ruud Klaver
  This is is {{{None}}}, the internal 408 is only triggered by the internal PJSIP transaction timeout.
921 69 Ruud Klaver
  Note that, even if the timeout is specified, the PJSIP timeout is also still valid.
922 69 Ruud Klaver
 '''end'''(''self'', '''timeout'''={{{None}}})::
923 69 Ruud Klaver
  End the publication by sending a {{{PUBLISH}}} request with an {{{Expires}}} header of 0.
924 69 Ruud Klaver
  If the object is not published, this will result in a {{{PublicationError}}} being thrown.
925 69 Ruud Klaver
  [[BR]]''timeout'':[[BR]]
926 69 Ruud Klaver
  The meaning of this argument is the same as it is for the {{{publish()}}} method.
927 1 Adrian Georgescu
928 1 Adrian Georgescu
==== notifications ====
929 1 Adrian Georgescu
930 69 Ruud Klaver
 '''SIPPublicationDidSucceed'''::
931 69 Ruud Klaver
  This notification will be sent when the {{{publish()}}} method was called and the publication succeeded.
932 69 Ruud Klaver
  [[BR]]''code'':[[BR]]
933 69 Ruud Klaver
  The SIP response code as received from the SIP presence agent as an int.
934 69 Ruud Klaver
  [[BR]]''reason'':[[BR]]
935 69 Ruud Klaver
  The reason string received from the SIP presence agent.
936 69 Ruud Klaver
  [[BR]]''route'':[[BR]]
937 69 Ruud Klaver
  The {{{Route}}} object passed as an argument to the {{{publish()}}} method.
938 69 Ruud Klaver
  [[BR]]''expires_in'':[[BR]]
939 69 Ruud Klaver
  The number of seconds before this publication expires
940 69 Ruud Klaver
 '''SIPPublicationDidFail'''::
941 69 Ruud Klaver
  This notification will be sent when the {{{publish()}}} method was called and the publication failed, for whatever reason.
942 69 Ruud Klaver
  [[BR]]''code'':[[BR]]
943 69 Ruud Klaver
  The SIP response code as received from the presence agent as an int.
944 69 Ruud Klaver
  This can also be a PJSIP generated response code, or 0 if the failure was because of an internal error.
945 69 Ruud Klaver
  [[BR]]''reason'':[[BR]]
946 69 Ruud Klaver
  The reason string received from the presence agent or the error string.
947 69 Ruud Klaver
  [[BR]]''route'':[[BR]]
948 69 Ruud Klaver
  The {{{Route}}} object passed as an argument to the {{{publish()}}} method.
949 69 Ruud Klaver
 '''SIPPublicationWillExpire'''::
950 69 Ruud Klaver
  This notification will be sent when a publication will expire soon.
951 69 Ruud Klaver
  It should be used as an indication to re-perform DNS lookup of the presence agent and call the {{{publish()}}} method.
952 69 Ruud Klaver
  [[BR]]''expires'':[[BR]]
953 69 Ruud Klaver
  The number of seconds in which the publication will expire.
954 69 Ruud Klaver
 '''SIPPublicationWillEnd'''::
955 69 Ruud Klaver
  Will be sent whenever the {{{end()}}} method was called and an unpublishing {{{PUBLISH}}} is sent.
956 69 Ruud Klaver
 '''SIPPublicationDidNotEnd'''::
957 69 Ruud Klaver
  This notification will be sent when the unpublishing {{{PUBLISH}}} request failed for some reason.
958 69 Ruud Klaver
  [[BR]]''code'':[[BR]]
959 69 Ruud Klaver
  The SIP response code as received from the presence agent as an int.
960 69 Ruud Klaver
  This can also be a PJSIP generated response code, or 0 if the failure was because of an internal error.
961 69 Ruud Klaver
  [[BR]]''reason'':[[BR]]
962 69 Ruud Klaver
  The reason string received from the presence agent or the error string.
963 69 Ruud Klaver
 '''SIPPublicationDidEnd'''::
964 69 Ruud Klaver
  This notification will be sent when a {{{Publication}}} has become unpublished.
965 69 Ruud Klaver
  [[BR]]''expired'':[[BR]]
966 69 Ruud Klaver
  This boolean indicates if the object is unpublished because the publication expired, in which case it will be set to {{{True}}}.
967 69 Ruud Klaver
  If this data attribute is {{{False}}}, it means that unpublication was explicitly requested through the {{{end()}}} method.
968 1 Adrian Georgescu
969 1 Adrian Georgescu
=== Subscription ===
970 1 Adrian Georgescu
971 1 Adrian Georgescu
Subscription and notifications for SIP events is an Internet standard published at [http://tools.ietf.org/html/rfc3856 RFC 3856].
972 1 Adrian Georgescu
973 59 Ruud Klaver
This SIP primitive class represents a subscription to a specific event type of a particular SIP URI.
974 1 Adrian Georgescu
This means that the application should instance this class for each combination of event and SIP URI that it wishes to subscribe to.
975 1 Adrian Georgescu
The event type and the content types that are acceptable for it need to be registered first, either through the {{{init_options}}} attribute of {{{Engine}}} (before starting it), or by calling the {{{add_event()}}} method of the {{{Engine}}} instance.
976 1 Adrian Georgescu
Whenever a {{{NOTIFY}}} is received, the application will receive the {{{SIPSubscriptionGotNotify}}} event.
977 1 Adrian Georgescu
978 1 Adrian Georgescu
Internally a {{{Subscription}}} object has a state machine, which reflects the state of the subscription.
979 59 Ruud Klaver
It is a direct mirror of the state machine of the underlying {{{pjsip_evsub}}} object, whose possible states are at least {{{NULL}}}, {{{SENT}}}, {{{ACCEPTED}}}, {{{PENDING}}}, {{{ACTIVE}}} or {{{TERMINATED}}}.
980 59 Ruud Klaver
The last three states are directly copied from the contents of the {{{Subscription-State}}} header of the received {{{NOTIFY}}} request.
981 1 Adrian Georgescu
Also, the state can be an arbitrary string if the contents of the {{{Subscription-State}}} header are not one of the three above.
982 1 Adrian Georgescu
The state of the object is presented in the {{{state}}} attribute and changes of the state are indicated by means of the {{{SIPSubscriptionChangedState}}} notification.
983 1 Adrian Georgescu
This notification is only informational, an application using this object should take actions based on the other notifications sent by this object.
984 1 Adrian Georgescu
985 1 Adrian Georgescu
==== attributes ====
986 1 Adrian Georgescu
987 59 Ruud Klaver
 '''state'''::
988 59 Ruud Klaver
  Indicates which state the internal state machine is in.
989 1 Adrian Georgescu
  See the previous section for a list of states the state machine can be in.
990 1 Adrian Georgescu
 '''from_uri'''::
991 71 Adrian Georgescu
  The SIP URI to be put in the {{{From}}} header of the {{{SUBSCRIBE}}} requests in the form of a {{{SIPURI}}} object.
992 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
993 59 Ruud Klaver
 '''to_uri'''::
994 59 Ruud Klaver
  The SIP URI that is the target for the subscription in the form of a {{{SIPURI}}} object.
995 59 Ruud Klaver
  This attribute is set on object instantiation and is read-only.
996 1 Adrian Georgescu
 '''contact_uri'''::
997 71 Adrian Georgescu
  The SIP URI to be put in the {{{Contact}}} header of the {{{SUBSCRIBE}}} requests in the form of a {{{SIPURI}}} object.
998 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
999 1 Adrian Georgescu
 '''event'''::
1000 1 Adrian Georgescu
  The event package for which the subscription is as a string.
1001 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
1002 59 Ruud Klaver
 '''route'''::
1003 59 Ruud Klaver
  The outbound proxy to use in the form of a {{{Route}}} object.
1004 59 Ruud Klaver
  This attribute is set on object instantiation and is read-only.
1005 1 Adrian Georgescu
 '''credentials'''::
1006 59 Ruud Klaver
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
1007 59 Ruud Klaver
  If none was specified when creating the {{{Subscription}}} object, this attribute is {{{None}}}.
1008 59 Ruud Klaver
  This attribute is set on object instantiation and is read-only.
1009 59 Ruud Klaver
 '''refresh'''::
1010 59 Ruud Klaver
  The refresh interval in seconds that was requested on object instantiation as an int.
1011 59 Ruud Klaver
  This attribute is set on object instantiation and is read-only.
1012 59 Ruud Klaver
 '''extra_headers'''::
1013 59 Ruud Klaver
  This contains the dictionary of extra headers that was last passed to a successful call to the {{{subscribe()}}} method.
1014 59 Ruud Klaver
  If the argument was not provided, this attribute is an empty dictionary.
1015 59 Ruud Klaver
  This attribute is read-only.
1016 59 Ruud Klaver
 '''content_type'''::
1017 59 Ruud Klaver
  This attribute contains the {{{Content-Type}}} of the body that was last passed to a successful call to the {{{subscribe()}}} method.
1018 59 Ruud Klaver
  If the argument was not provided, this attribute is {{{None}}}.
1019 1 Adrian Georgescu
 '''body'''::
1020 1 Adrian Georgescu
  This attribute contains the {{{body}}} string argument that was last passed to a successful call to the {{{subscribe()}}} method.
1021 1 Adrian Georgescu
  If the argument was not provided, this attribute is {{{None}}}.
1022 59 Ruud Klaver
1023 59 Ruud Klaver
==== methods ====
1024 59 Ruud Klaver
1025 59 Ruud Klaver
 '''!__init!__'''(''self'', '''from_uri''', '''to_uri''', '''contact_uri, '''event''', '''route''', '''credentials'''={{{None}}}, '''refresh'''=300)::
1026 59 Ruud Klaver
  Creates a new {{{Subscription}}} object which will be in the {{{NULL}}} state.
1027 59 Ruud Klaver
  The arguments for this method are documented in the attributes section above.
1028 59 Ruud Klaver
 '''subscribe'''(''self'', '''extra_headers'''={{{None}}}, '''content_type'''={{{None}}}, '''body'''={{{None}}}, '''timeout'''={{{None}}})::
1029 59 Ruud Klaver
  Calling this method triggers sending a {{{SUBSCRIBE}}} request to the presence agent.
1030 1 Adrian Georgescu
  The arguments passed will be stored and used for subsequent refreshing {{{SUBSCRIBE}}} requests.
1031 59 Ruud Klaver
  This method may be used both to send the initial request and to update the arguments while the subscription is ongoing.
1032 59 Ruud Klaver
  It may not be called when the object is in the {{{TERMINATED}}} state.
1033 59 Ruud Klaver
  [[BR]]''extra_headers'':[[BR]]
1034 59 Ruud Klaver
  A dictionary of additional headers to include in the {{{SUBSCRIBE}}} requests.
1035 59 Ruud Klaver
  [[BR]]''content_type'':[[BR]]
1036 59 Ruud Klaver
  The {{{Content-Type}}} of the supplied {{{body}}} argument as a string.
1037 59 Ruud Klaver
  If this argument is supplied, the {{{body}}} argument cannot be {{{None}}}.
1038 59 Ruud Klaver
  [[BR]]''body'':[[BR]]
1039 59 Ruud Klaver
  The optional body to include in the {{{SUBSCRIBE}}} request as a string.
1040 59 Ruud Klaver
  If this argument is supplied, the {{{content_type}}} argument cannot be {{{None}}}.
1041 59 Ruud Klaver
  [[BR]]''timeout'':[[BR]]
1042 59 Ruud Klaver
  This can be either an int or a float, indicating in how many seconds the request should timeout with an internally generated 408 response.
1043 59 Ruud Klaver
  If this is {{{None}}}, the internal 408 is only triggered by the internal PJSIP transaction timeout.
1044 59 Ruud Klaver
  Note that, even if the timeout is specified, the PJSIP timeout is also still valid.
1045 59 Ruud Klaver
 '''end'''(''self'', '''timeout'''={{{None}}})::
1046 59 Ruud Klaver
  This will end the subscription by sending a {{{SUBSCRIBE}}} request with an {{{Expires}}} value of 0.
1047 1 Adrian Georgescu
  If this object is no longer subscribed, this method will return without performing any action.
1048 1 Adrian Georgescu
  This method cannot be called when the object is in the {{{NULL}}} state.
1049 1 Adrian Georgescu
  The {{{timeout}}} argument has the same meaning as it does for the {{{subscribe()}}} method.
1050 1 Adrian Georgescu
1051 1 Adrian Georgescu
==== notifications ====
1052 1 Adrian Georgescu
1053 1 Adrian Georgescu
 '''SIPSubscriptionChangedState'''::
1054 59 Ruud Klaver
  This notification will be sent every time the internal state machine of a {{{Subscription}}} object changes state.
1055 59 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1056 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1057 1 Adrian Georgescu
  [[BR]]''prev_state'':[[BR]]
1058 59 Ruud Klaver
  The previous state that the sate machine was in.
1059 59 Ruud Klaver
  [[BR]]''state'':[[BR]]
1060 59 Ruud Klaver
  The new state the state machine moved into.
1061 59 Ruud Klaver
 '''SIPSubscriptionWillStart'''::
1062 59 Ruud Klaver
  This notification will be emitted when the initial {{{SUBSCRIBE}}} request is sent.
1063 59 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1064 59 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1065 59 Ruud Klaver
 '''SIPSubscriptionDidStart'''::
1066 29 Luci Stanescu
  This notification will be sent when the initial {{{SUBSCRIBE}}} was accepted by the presence agent.
1067 29 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1068 59 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1069 1 Adrian Georgescu
 '''SIPSubscriptionGotNotify'''::
1070 1 Adrian Georgescu
  This notification will be sent when a {{{NOTIFY}}} is received that corresponds to a particular {{{Subscription}}} object.
1071 59 Ruud Klaver
  Note that this notification could be sent when a {{{NOTIFY}}} without a body is received.
1072 59 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1073 59 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1074 59 Ruud Klaver
  [[BR]]''method'':[[BR]]
1075 59 Ruud Klaver
  The method of the SIP request as a string.
1076 59 Ruud Klaver
  This will always be {{{NOTIFY}}}.
1077 59 Ruud Klaver
  [[BR]]''request_uri'':[[BR]]
1078 59 Ruud Klaver
  The request URI of the {{{NOTIFY}}} request as a {{{SIPURI}}} object.
1079 59 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1080 1 Adrian Georgescu
  The headers of the {{{NOTIFY}}} request as a dict.
1081 59 Ruud Klaver
  Each SIP header is represented in its parsed for as long as PJSIP supports it.
1082 59 Ruud Klaver
  The format of the parsed value depends on the header.
1083 59 Ruud Klaver
  [[BR]]''body'':[[BR]]
1084 59 Ruud Klaver
  The body of the {{{NOTIFY}}} request as a string, or {{{None}}} if no body was included.
1085 59 Ruud Klaver
  The content type of the body can be learned from the {{{Content-Type}}} header in the headers data attribute.
1086 59 Ruud Klaver
 '''SIPSubscriptionDidFail'''::
1087 59 Ruud Klaver
  This notification will be sent whenever there is a failure, such as a rejected initial or refreshing {{{SUBSCRIBE}}}.
1088 59 Ruud Klaver
  After this notification the {{{Subscription}}} object is in the {{{TERMINATED}}} state and can no longer be used.
1089 59 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1090 59 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1091 59 Ruud Klaver
  [[BR]]''code'':[[BR]]
1092 59 Ruud Klaver
  An integer SIP code from the fatal response that was received from the remote party of generated by PJSIP.
1093 59 Ruud Klaver
  If the error is internal to the SIP core, this attribute will have a value of 0.
1094 59 Ruud Klaver
  [[BR]]''reason'':[[BR]]
1095 71 Adrian Georgescu
  An text string describing the failure that occurred.
1096 59 Ruud Klaver
 '''SIPSubscriptionDidEnd'''::
1097 59 Ruud Klaver
  This notification will be sent when the subscription ends normally, i.e. the {{{end()}}} method was called and the remote party sent a positive response.
1098 1 Adrian Georgescu
  After this notification the {{{Subscription}}} object is in the {{{TERMINATED}}} state and can no longer be used.
1099 56 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1100 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1101 1 Adrian Georgescu
1102 84 Ruud Klaver
=== IncomingSubscription ===
1103 84 Ruud Klaver
1104 84 Ruud Klaver
Subscription and notifications for SIP events is an Internet standard published at [http://tools.ietf.org/html/rfc3856 RFC 3856].
1105 84 Ruud Klaver
1106 84 Ruud Klaver
This SIP primitive class is the mirror companion to the {{{Subscription}}} class and allows the application to take on the server role in a {{{SUBSCRIBE}}} session.
1107 84 Ruud Klaver
This means that it can accept a {{{SUBSCRIBE}}} request and subsequent refreshing {{{SUBSCRIBE}}}s and sent {{{NOTIFY}}} requests containing event state.
1108 84 Ruud Klaver
1109 84 Ruud Klaver
In order to be able to receive {{{SUBSCRIBE}}} requests for a particular event package, the application needs to add the name of this event package to the {{{incoming_events}}} set attribute on the {{{Engine}}}, either at startup or at a later time, using the {{{add_incoming_event()}}} method.
1110 84 Ruud Klaver
This event needs to be known by the {{{Engine}}}, i.e. it should already be present in the {{{events}}} dictionary attribute.
1111 84 Ruud Klaver
Once the event package name is in the {{{incoming_events}}} set attribute, any incoming {{{SUBSCRIBE}}} request containing this name in the {{{Event}}} header causes the creation of a {{{IncomingSubscribe}}} object.
1112 84 Ruud Klaver
This will be indicated to the application through a {{{SIPIncomingSubscriptionGotSubscribe}}} notification.
1113 84 Ruud Klaver
It is then up to the application to check if the {{{SUBSCRIBE}}} request was valid, e.g. if it was actually directed at the correct SIP URI, and respond to it in a timely fashion.
1114 84 Ruud Klaver
1115 84 Ruud Klaver
The application can either reject the subscription by calling the {{{reject()}}} method or accept it through the {{{accept()}}} method, optionally first accepting it in the {{{pending}}} state by calling the {{{accept_pending()}}} method.
1116 84 Ruud Klaver
After the {{{IncomingSubscription}}} is accepted, the application can trigger sending a {{{NOTIFY}}} request with a body reflecting the event state through the {{{push_content()}}} method.
1117 84 Ruud Klaver
Whenever a refreshing {{{SUBSCRIBE}}} is received, the latest contents to be set are sent in the resulting {{{NOTIFY}}} request.
1118 84 Ruud Klaver
The subscription can be ended by using the {{{end()}}} method.
1119 84 Ruud Klaver
1120 84 Ruud Klaver
==== attributes ====
1121 84 Ruud Klaver
1122 84 Ruud Klaver
 '''state'''::
1123 84 Ruud Klaver
  Indicates which state the incoming subscription session is in.
1124 84 Ruud Klaver
  This can be one of {{{None}}}, {{{"incoming"}}}, {{{"pending"}}}, {{{"active"}}} or {{{"terminated"}}}.
1125 84 Ruud Klaver
  This attribute is read-only.
1126 84 Ruud Klaver
 '''event'''::
1127 84 Ruud Klaver
  The name of the event package that this {{{IncomingSubscription}}} relates to.
1128 84 Ruud Klaver
  This attribute is a read-only string.
1129 84 Ruud Klaver
 '''content_type'''::
1130 84 Ruud Klaver
  The {{{Content-Type}}} of the last set content in this subscription session.
1131 84 Ruud Klaver
  Inititally this will be {{{None}}}.
1132 84 Ruud Klaver
  This attribute is a read-only string.
1133 84 Ruud Klaver
 '''content'''::
1134 84 Ruud Klaver
  The last set content in this subscription session as a read-only string.
1135 84 Ruud Klaver
1136 84 Ruud Klaver
==== methods ====
1137 84 Ruud Klaver
1138 84 Ruud Klaver
 '''!__init!__'''(''self'')::
1139 84 Ruud Klaver
  An application should never create an {{{IncomingSubscription}}} object itself.
1140 84 Ruud Klaver
  Doing this will create a useless object in the {{{None}}} state.
1141 84 Ruud Klaver
 '''reject'''(''self'', '''code''')::
1142 84 Ruud Klaver
  Will reply to the initial {{{SUBSCRIBE}}} with a negative response.
1143 84 Ruud Klaver
  This method can only be called in the {{{"incoming"}}} state and sets the subscription to the {{{"terminated"}}} state.
1144 84 Ruud Klaver
  [[BR]]''code'':[[BR]]
1145 84 Ruud Klaver
  The SIP response code to use.
1146 84 Ruud Klaver
  This should be a negative response, i.e. in the 3xx, 4xx, 5xx or 6xx range.
1147 84 Ruud Klaver
 '''accept_pending'''(''self'')::
1148 84 Ruud Klaver
  Accept the initial incoming {{{SUBSCRIBE}}}, but put the subscription in the {{{"pending"}}} state and reply with a 202, followed by a {{{NOTIFY}}} request indicating the state.
1149 84 Ruud Klaver
  The application can later decide to fully accept the subscription or terminate it.
1150 84 Ruud Klaver
  This method can only be called in the {{{"incoming"}}} state.
1151 84 Ruud Klaver
 '''accept'''(''self'', '''content_type'''={{{None}}}, '''content'''={{{None}}})::
1152 84 Ruud Klaver
  Accept the initial incoming {{{SUBSCRIBE}}} and respond to it with a 200 OK, or fully accept an {{{IncomingSubscription}}} that is in the {{{"pending"}}} state.
1153 84 Ruud Klaver
  In either case, a {{{NOTIFY}}} will be sent to update the state to "active", optionally with the content specified in the arguments.
1154 84 Ruud Klaver
  This method can only be called in the {{{"incoming"}}} or {{{"pending"}}} state.
1155 84 Ruud Klaver
  [[BR]]''content_type'':[[BR]]
1156 84 Ruud Klaver
  The Content-Type of the content to be set supplied as a string containing a {{{"/"}}} character.
1157 84 Ruud Klaver
  Note that if this argument is set, the {{{content}}} argument should also be set.
1158 84 Ruud Klaver
  [[BR]]''content'':[[BR]]
1159 84 Ruud Klaver
  The body of the {{{NOTIFY}}} to send when accepting the subscription, as a string.
1160 84 Ruud Klaver
  Note that if this argument is set, the {{{content_type}}} argument should also be set.
1161 84 Ruud Klaver
 '''push_content'''(''self'', '''content_type''', '''content''')::
1162 84 Ruud Klaver
  Sets or updates the body of the {{{NOTIFY}}}s to be sent within this subscription and causes a {{{NOTIFY}}} to be sent to the subscriber.
1163 84 Ruud Klaver
  This method can only be called in the {{{"active"}}} state.
1164 84 Ruud Klaver
  [[BR]]''content_type'':[[BR]]
1165 84 Ruud Klaver
  The Content-Type of the content to be set supplied as a string containing a {{{"/"}}} character.
1166 84 Ruud Klaver
  [[BR]]''content'':[[BR]]
1167 84 Ruud Klaver
  The body of the {{{NOTIFY}}} as a string.
1168 84 Ruud Klaver
1169 84 Ruud Klaver
==== notifications ====
1170 84 Ruud Klaver
1171 84 Ruud Klaver
 '''SIPIncomingSubscriptionChangedState'''::
1172 84 Ruud Klaver
  This notification will be sent every time the an {{{IncomingSubscription}}} object changes state.
1173 84 Ruud Klaver
  This notification is mostly indicative, an application should not let its logic depend on it.
1174 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1175 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1176 84 Ruud Klaver
  [[BR]]''prev_state'':[[BR]]
1177 84 Ruud Klaver
  The previous state that the subscription was in.
1178 84 Ruud Klaver
  [[BR]]''state'':[[BR]]
1179 84 Ruud Klaver
  The new state the subscription has.
1180 84 Ruud Klaver
 '''SIPIncomingSubscriptionGotSubscribe'''::
1181 84 Ruud Klaver
  This notification will be sent when a new {{{IncomingSubscription}}} is created as result of an incoming {{{SUBSCRIBE}}} request.
1182 84 Ruud Klaver
  The application should listen for this notification, retain a reference to the object that sent it and either accept or reject it.
1183 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1184 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1185 84 Ruud Klaver
  [[BR]]''method'':[[BR]]
1186 84 Ruud Klaver
  The method of the SIP request as a string, which will be {{{SUBSCRIBE}}}.
1187 84 Ruud Klaver
  [[BR]]''request_uri'':[[BR]]
1188 84 Ruud Klaver
  The request URI of the {{{SUBSCRIBE}}} request as a {{{FrozenSIPURI}}} object.
1189 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1190 84 Ruud Klaver
  The headers of the {{{SUBSCRIBE}}} request as a dict, the values of which are the relevant header objects.
1191 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1192 84 Ruud Klaver
  The body of the {{{SUBSCRIBE}}} request or response as a string, or {{{None}}} if no body was included.
1193 84 Ruud Klaver
 '''SIPIncomingSubscriptionGotRefreshingSubscribe'''::
1194 84 Ruud Klaver
  This notification indicates that a refreshing {{{SUBSCRIBE}}} request was received from the subscriber.
1195 84 Ruud Klaver
  It is purely informative, no action needs to be taken by the application as a result of it.
1196 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1197 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1198 84 Ruud Klaver
  [[BR]]''method'':[[BR]]
1199 84 Ruud Klaver
  The method of the SIP request as a string, which will be {{{SUBSCRIBE}}}.
1200 84 Ruud Klaver
  [[BR]]''request_uri'':[[BR]]
1201 84 Ruud Klaver
  The request URI of the {{{SUBSCRIBE}}} request as a {{{FrozenSIPURI}}} object.
1202 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1203 84 Ruud Klaver
  The headers of the {{{SUBSCRIBE}}} request as a dict, the values of which are the relevant header objects.
1204 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1205 84 Ruud Klaver
  The body of the {{{SUBSCRIBE}}} request or response as a string, or {{{None}}} if no body was included.
1206 84 Ruud Klaver
 '''SIPIncomingSubscriptionGotUnsubscribe'''::
1207 84 Ruud Klaver
  This notification indicates that a {{{SUBSCRIBE}}} request with an {{{Expires}}} header of 0 was received from the subscriber, effectively requesting to unsubscribe.
1208 84 Ruud Klaver
  It is purely informative, no action needs to be taken by the application as a result of it.
1209 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1210 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1211 84 Ruud Klaver
  [[BR]]''method'':[[BR]]
1212 84 Ruud Klaver
  The method of the SIP request as a string, which will be {{{SUBSCRIBE}}}.
1213 84 Ruud Klaver
  [[BR]]''request_uri'':[[BR]]
1214 84 Ruud Klaver
  The request URI of the {{{SUBSCRIBE}}} request as a {{{FrozenSIPURI}}} object.
1215 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1216 84 Ruud Klaver
  The headers of the {{{SUBSCRIBE}}} request as a dict, the values of which are the relevant header objects.
1217 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1218 84 Ruud Klaver
  The body of the {{{SUBSCRIBE}}} request or response as a string, or {{{None}}} if no body was included.
1219 84 Ruud Klaver
 '''SIPIncomingSubscriptionAnsweredSubscribe'''::
1220 84 Ruud Klaver
  This notification is sent whenever a response to a {{{SUBSCRIBE}}} request is send by the object, including an unsubscribing {{{SUBSCRIBE}}}.
1221 84 Ruud Klaver
  It is purely informative, no action needs to be taken by the application as a result of it.
1222 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1223 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1224 84 Ruud Klaver
  [[BR]]''code'':[[BR]]
1225 84 Ruud Klaver
  The code of the SIP response as an int.
1226 84 Ruud Klaver
  [[BR]]''reason'':[[BR]]
1227 84 Ruud Klaver
  The reason text of the SIP response as an int.
1228 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1229 84 Ruud Klaver
  The headers of the response as a dict, the values of which are the relevant header objects.
1230 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1231 84 Ruud Klaver
  This will be {{{None}}}.
1232 84 Ruud Klaver
 '''SIPIncomingSubscriptionSentNotify'''::
1233 84 Ruud Klaver
  This notification indicates that a {{{NOTIFY}}} request was sent to the subscriber.
1234 84 Ruud Klaver
  It is purely informative, no action needs to be taken by the application as a result of it.
1235 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1236 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1237 84 Ruud Klaver
  [[BR]]''method'':[[BR]]
1238 84 Ruud Klaver
  The method of the SIP request as a string, which will be {{{NOTIFY}}}.
1239 84 Ruud Klaver
  [[BR]]''request_uri'':[[BR]]
1240 84 Ruud Klaver
  The request URI of the {{{NOTIFY}}} request as a {{{FrozenSIPURI}}} object.
1241 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1242 84 Ruud Klaver
  The headers of the {{{NOTIFY}}} request as a dict, the values of which are the relevant header objects.
1243 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1244 84 Ruud Klaver
  The body of the {{{NOTIFY}}} request or response as a string, or {{{None}}} if no body was included.
1245 84 Ruud Klaver
 '''SIPIncomingSubscriptionNotifyDidSucceed'''::
1246 84 Ruud Klaver
  This indicates that a positive final response was received from the subscriber in reply to a sent {{{NOTIFY}}} request.
1247 84 Ruud Klaver
  The notification is purely informative, no action needs to be taken by the application as a result of it.
1248 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1249 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1250 84 Ruud Klaver
  [[BR]]''code'':[[BR]]
1251 84 Ruud Klaver
  The code of the SIP response as an int.
1252 84 Ruud Klaver
  [[BR]]''reason'':[[BR]]
1253 84 Ruud Klaver
  The reason text of the SIP response as a string.
1254 84 Ruud Klaver
  [[BR]]''headers'':[[BR]]
1255 84 Ruud Klaver
  The headers of the response as a dict, the values of which are the relevant header objects.
1256 84 Ruud Klaver
  [[BR]]''body'':[[BR]]
1257 84 Ruud Klaver
  This will be {{{None}}}.
1258 84 Ruud Klaver
 '''SIPIncomingSubscriptionNotifyDidFail'''::
1259 84 Ruud Klaver
  This indicates that a negative response was received from the subscriber in reply to a sent {{{NOTIFY}}} request or that the {{{NOTIFY}}} failed to send.
1260 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1261 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1262 84 Ruud Klaver
  [[BR]]''code'':[[BR]]
1263 84 Ruud Klaver
  The code of the SIP response as an int.
1264 84 Ruud Klaver
  If this is 0, the notification was sent as a result of an internal error.
1265 84 Ruud Klaver
  [[BR]]''reason'':[[BR]]
1266 84 Ruud Klaver
  The reason text of the SIP response as a string or the internal error if the code attribute is 0.
1267 84 Ruud Klaver
  [[BR]]''headers'': (if the notification was caused by a negative response)[[BR]]
1268 84 Ruud Klaver
  The headers of the response as a dict, the values of which are the relevant header objects.
1269 84 Ruud Klaver
  [[BR]]''body'': (if the notification was caused by a negative response)[[BR]]
1270 84 Ruud Klaver
  This will be {{{None}}}.
1271 84 Ruud Klaver
 '''SIPIncomingSubscriptionNotifyDidEnd'''::
1272 84 Ruud Klaver
  This notification is sent whenever the {{{IncomingSubscription}}} object reaches the {{{"terminated"}}} state and is no longer valid.
1273 84 Ruud Klaver
  After receiving this notification, the application should not longer try to use the object.
1274 84 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1275 84 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1276 84 Ruud Klaver
1277 1 Adrian Georgescu
=== Invitation ===
1278 29 Luci Stanescu
1279 1 Adrian Georgescu
The {{{Invitation}}} class represents an {{{INVITE}}} session, which governs a complete session of media exchange between two SIP endpoints from start to finish.
1280 1 Adrian Georgescu
It is implemented to be agnostic to the media stream or streams negotiated, which is achieved by using the {{{SDPSession}}} class and its companion classes, which directly represents the parsed SDP.
1281 1 Adrian Georgescu
The {{{Invitation}}} class represents both incoming and outgoing sessions.
1282 29 Luci Stanescu
1283 1 Adrian Georgescu
The state machine contained in each {{{Invitation}}} object is based on the one used by the underlying PJSIP [http://www.pjsip.org/pjsip/docs/html/group__PJSIP__INV.htm pjsip_inv_session] object.
1284 1 Adrian Georgescu
In order to represent re-{{{INVITE}}}s and user-requested disconnections, three more states have been added to this state machine.
1285 1 Adrian Georgescu
The progression through this state machine is fairly linear and is dependent on whether this is an incoming or an outgoing session.
1286 1 Adrian Georgescu
State changes are triggered either by incoming or by outgoing SIP requests and responses.
1287 1 Adrian Georgescu
The states and the transitions between them are shown in the following diagram:
1288 1 Adrian Georgescu
1289 1 Adrian Georgescu
[[Image(sipsimple-core-invite-state-machine.png, nolink)]]
1290 1 Adrian Georgescu
1291 1 Adrian Georgescu
The state changes of this machine are triggered by the following:
1292 1 Adrian Georgescu
 1. An {{{Invitation}}} object is newly created, either by the application for an outgoing session, or by the core for an incoming session.
1293 1 Adrian Georgescu
 2. The application requested an outgoing session by calling the {{{send_invite()}}} method and and initial {{{INVITE}}} request is sent.
1294 1 Adrian Georgescu
 3. A new incoming session is received by the core.
1295 1 Adrian Georgescu
    The application should look out for state change to this state in order to be notified of new incoming sessions.
1296 1 Adrian Georgescu
 4. A provisional response (1xx) is received from the remove party.
1297 1 Adrian Georgescu
 5. A provisional response (1xx) is sent to the remote party, after the application called the {{{respond_to_invite_provisionally()}}} method.
1298 1 Adrian Georgescu
 6. A positive final response (2xx) is received from the remote party.
1299 1 Adrian Georgescu
 7. A positive final response (2xx) is sent to the remote party, after the application called the {{{accept_invite()}}} method.
1300 1 Adrian Georgescu
 8. A positive final response (2xx) is sent or received, depending on the orientation of the session.
1301 1 Adrian Georgescu
 9. An {{{ACK}}} is sent or received, depending on the orientation of the session.
1302 1 Adrian Georgescu
    If the {{{ACK}}} is sent from the local to the remote party, it is initiated by PJSIP, not by a call from the application.
1303 1 Adrian Georgescu
 10. The local party sent a re-{{{INVITE}}} to the remote party by calling the {{{send_reinvite()}}} method.
1304 1 Adrian Georgescu
 11. The remote party has sent a final response to the re-{{{INVITE}}}.
1305 1 Adrian Georgescu
 12. The remote party has sent a re-{{{INVITE}}}.
1306 1 Adrian Georgescu
 13. The local party has responded to the re-{{{INVITE}}} by calling the {{{respond_to_reinvite()}}} method.
1307 1 Adrian Georgescu
 14. The application requests that the session ends by calling the {{{end()}}} method.
1308 1 Adrian Georgescu
 15. A response is received from the remote party to whichever message was sent by the local party to end the session.
1309 1 Adrian Georgescu
 16. A message is received from the remote party which ends the session.
1310 1 Adrian Georgescu
1311 1 Adrian Georgescu
The application is notified of a state change in either state machine through the {{{SIPInvitationChangedState}}} notification, which has as data the current and previous states.
1312 1 Adrian Georgescu
If the event is triggered by and incoming message, extensive data about that message, such as method/code, headers and body, is also included with the notification.
1313 1 Adrian Georgescu
The application should compare the previous and current states and perform the appropriate action.
1314 1 Adrian Georgescu
1315 1 Adrian Georgescu
An {{{Invitiation}}} object also emits the {{{SIPInvitationGotSDPUpdate}}} notification, which indicates that SDP negotiation between the two parties has been completed.
1316 1 Adrian Georgescu
This will occur (at least) once during the initial session negotiation steps, during re-{{{INVITE}}}s in both directions and whenever an {{{UPDATE}}} request is received.
1317 1 Adrian Georgescu
In the last case, the {{{Invitation}}} object will automatically include the current local SDP in the response.
1318 1 Adrian Georgescu
1319 1 Adrian Georgescu
==== attributes ====
1320 33 Ruud Klaver
1321 33 Ruud Klaver
 '''state'''::
1322 33 Ruud Klaver
  The state the {{{Invitation}}} state machine is currently in.
1323 33 Ruud Klaver
  See the diagram above for possible states.
1324 33 Ruud Klaver
  This attribute is read-only.
1325 1 Adrian Georgescu
 '''is_outgoing'''::
1326 63 Ruud Klaver
  Boolean indicating if the original {{{INVITE}}} was outgoing, or incoming if set to {{{False}}}.
1327 1 Adrian Georgescu
 '''credentials'''::
1328 60 Ruud Klaver
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
1329 1 Adrian Georgescu
  If this {{{Invitation}}} object represents an incoming {{{INVITE}}} session this attribute will be {{{None}}}.
1330 63 Ruud Klaver
  On an outgoing session this attribute will be {{{None}}} if it was not specified when the object was created.
1331 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
1332 22 Ruud Klaver
 '''from_uri'''::
1333 60 Ruud Klaver
  The SIP URI of the caller represented by a {{{SIPURI}}} object.
1334 1 Adrian Georgescu
  If this is an outgoing {{{INVITE}}} session, this is the from_uri from the !__init!__ method.
1335 60 Ruud Klaver
  Otherwise the URI is taken from the {{{From:}}} header of the initial {{{INVITE}}}.
1336 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
1337 1 Adrian Georgescu
 '''to_uri'''::
1338 1 Adrian Georgescu
  The SIP URI of the callee represented by a {{{SIPURI}}} object.
1339 33 Ruud Klaver
  If this is an outgoing {{{INVITE}}} session, this is the to_uri from the !__init!__ method.
1340 60 Ruud Klaver
  Otherwise the URI is taken from the {{{To:}}} header of the initial {{{INVITE}}}.
1341 33 Ruud Klaver
  This attribute is set on object instantiation and is read-only.
1342 1 Adrian Georgescu
 '''local_uri'''::
1343 60 Ruud Klaver
  The local SIP URI used in this session.
1344 1 Adrian Georgescu
  If the original {{{INVITE}}} was incoming, this is the same as {{{to_uri}}}, otherwise it will be the same as {{{from_uri}}}.
1345 1 Adrian Georgescu
 '''remote_uri'''::
1346 1 Adrian Georgescu
  The SIP URI of the remote party in this session.
1347 1 Adrian Georgescu
  If the original {{{INVITE}}} was incoming, this is the same as {{{from_uri}}}, otherwise it will be the same as {{{to_uri}}}.
1348 1 Adrian Georgescu
 '''route'''::
1349 1 Adrian Georgescu
  The outbound proxy that was requested to be used in the form of a {{{Route}}} object, including the desired transport.
1350 1 Adrian Georgescu
  If this {{{Invitation}}} object represents an incoming {{{INVITE}}} session this attribute will always be {{{None}}}.
1351 1 Adrian Georgescu
  This attribute is set on object instantiation and is read-only.
1352 1 Adrian Georgescu
 '''call_id'''::
1353 1 Adrian Georgescu
  The call ID of the {{{INVITE}}} session as a read-only string.
1354 1 Adrian Georgescu
  In the {{{NULL}}} and {{{DISCONNECTED}}} states, this attribute is {{{None}}}.
1355 1 Adrian Georgescu
 '''transport'''::
1356 1 Adrian Georgescu
  A string indicating the transport used for the application.
1357 1 Adrian Georgescu
  This can be "udp", "tcp" or "tls".
1358 60 Ruud Klaver
 '''local_contact_uri'''::
1359 72 Ruud Klaver
  The Contact URI that the local side provided to the remote side within this {{{INVITE}}} session as a {{{SIPURI}}} object.
1360 72 Ruud Klaver
  Note that this can either be set on object creation or updated using the {{{update_local_contact()}}} method.
1361 72 Ruud Klaver
 '''local_contact_parameters'''::
1362 72 Ruud Klaver
  The Contact header parameters that the local side provided to the remote side within this {{{INVITE}}} session as dictionary.
1363 1 Adrian Georgescu
  Note that this can either be set on object creation or updated using the {{{update_local_contact()}}} method.
1364 63 Ruud Klaver
1365 1 Adrian Georgescu
==== methods ====
1366 72 Ruud Klaver
1367 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''from_uri''', '''to_uri''', '''route''', '''credentials'''={{{None}}}, '''contact_uri'''={{{None}}}, '''contact_parameters'''={{{None}}})::
1368 1 Adrian Georgescu
  Creates a new {{{Invitation}}} object for an outgoing session.
1369 60 Ruud Klaver
  [[BR]]''from_uri'':[[BR]]
1370 53 Ruud Klaver
  The SIP URI of the local account in the form of a {{{SIPURI}}} object.
1371 1 Adrian Georgescu
  [[BR]]''to_uri'':[[BR]]
1372 63 Ruud Klaver
  The SIP URI we want to send the {{{INVITE}}} to, represented as a {{{SIPURI}}} object.
1373 63 Ruud Klaver
  [[BR]]''route'':[[BR]]
1374 1 Adrian Georgescu
  The outbound proxy to use in the form of a {{{Route}}} object.
1375 1 Adrian Georgescu
  This includes the desired transport to use.
1376 1 Adrian Georgescu
  [[BR]]''credentials'':[[BR]]
1377 1 Adrian Georgescu
  The optional SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
1378 1 Adrian Georgescu
  [[BR]]''contact_uri'':[[BR]]
1379 1 Adrian Georgescu
  The Contact URI to include in the {{{INVITE}}} request, a {{{SIPURI}}} object.
1380 72 Ruud Klaver
  If this is {{{None}}}, a Contact URI will be internally generated.
1381 72 Ruud Klaver
  [[BR]]''contact_parameters'':[[BR]]
1382 72 Ruud Klaver
  The parameters to be included in the Contact header of the {{{INVITE}}} request as a dictionary.
1383 72 Ruud Klaver
  Entries that have their value set to {{{None}}} will have only the key set as a header parameter.
1384 1 Adrian Georgescu
  If this argument is {{{None}}}, no Contact header parameters will be included.
1385 1 Adrian Georgescu
 '''get_active_local_sdp'''(''self'')::
1386 1 Adrian Georgescu
  Returns a new {{{SDPSession}}} object representing the currently active local SDP.
1387 1 Adrian Georgescu
  If no SDP was negotiated yet, this returns {{{None}}}.
1388 56 Ruud Klaver
 '''get_active_remote_sdp'''(''self'')::
1389 1 Adrian Georgescu
  Returns a new {{{SDPSession}}} object representing the currently active local SDP.
1390 1 Adrian Georgescu
  If no SDP was negotiated yet, this returns {{{None}}}.
1391 1 Adrian Georgescu
 '''get_offered_local_sdp'''(''self'')::
1392 1 Adrian Georgescu
  Returns a new {{{SDPSession}}} object representing the currently proposed local SDP.
1393 1 Adrian Georgescu
  If no local offered SDP has been set, this returns {{{None}}}.
1394 1 Adrian Georgescu
 '''set_offered_local_sdp'''(''self'', '''local_sdp''')::
1395 41 Ruud Klaver
  Sets the offered local SDP, either for an initial {{{INVITE}}} or re-{{{INVITE}}}, or as an SDP answer in response to an initial {{{INVITE}}} or re-{{{INVITE}}}.
1396 1 Adrian Georgescu
  [[BR]]''local_sdp'':[[BR]]
1397 41 Ruud Klaver
  The SDP to send as offer or answer to the remote party.
1398 53 Ruud Klaver
 '''get_offered_remote_sdp'''(''self'')::
1399 1 Adrian Georgescu
  Returns a new {{{SDPSession}}} object representing the currently proposed remote SDP.
1400 72 Ruud Klaver
  If no remote SDP has been offered in the current state, this returns {{{None}}}.
1401 72 Ruud Klaver
 '''update_local_contact'''(''self'', '''contact_uri''', '''parameters'''={{{None}}})::
1402 72 Ruud Klaver
  This method allows the application to update the contents of the Contact header sent in (re-){{{INVITE}}} requests.
1403 72 Ruud Klaver
  It can be useful to set to Contact URI to something different than the default on an incoming {{{INVITE}}} session, on a IP address change during the session.
1404 72 Ruud Klaver
  Note that that the number of calls to this method should be limited, as memory is allocated each time it is called which is only released when the {{{Invitation}}} object reaches the {{{DISCONNECTED}}} state.
1405 72 Ruud Klaver
  [[BR]]''contact_uri'':[[BR]]
1406 72 Ruud Klaver
  The Contact URI to include in the {{{INVITE}}} request, a {{{SIPURI}}} object.
1407 72 Ruud Klaver
  [[BR]]''contact_parameters'':[[BR]]
1408 72 Ruud Klaver
  The parameters to be included in the Contact header of the {{{INVITE}}} request as a dictionary.
1409 72 Ruud Klaver
  Entries that have their value set to {{{None}}} will have only the key set as a header parameter.
1410 1 Adrian Georgescu
  If this argument is {{{None}}}, no Contact header parameters will be included.
1411 1 Adrian Georgescu
 '''send_invite'''(''self'', '''extra_headers'''={{{None}}}, '''timeout'''={{{None}}})::
1412 1 Adrian Georgescu
  This tries to move the state machine into the {{{CALLING}}} state by sending the initial {{{INVITE}}} request.
1413 1 Adrian Georgescu
  It may only be called from the {{{NULL}}} state on an outgoing {{{Invitation}}} object.
1414 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1415 1 Adrian Georgescu
  Any extra headers that should be included in the {{{INVITE}}} request in the form of a dict.
1416 1 Adrian Georgescu
  [[BR]]''timeout'':[[BR]]
1417 1 Adrian Georgescu
  How many seconds to wait for the remote party to reply before changing the state to {{{DISCONNECTED}}} and internally replying with a 408, as an int or a float.
1418 1 Adrian Georgescu
  If this is set to {{{None}}}, the default PJSIP timeout will be used, which appears to be slightly longer than 30 seconds.
1419 1 Adrian Georgescu
 '''respond_to_invite_provisionally'''(''self'', '''response_code'''=180, '''extra_headers'''={{{None}}})::
1420 1 Adrian Georgescu
  This tries to move the state machine into the {{{EARLY}}} state by sending a provisional response to the initial {{{INVITE}}}.
1421 1 Adrian Georgescu
  It may only be called from the {{{INCOMING}}} state on an incoming {{{Invitation}}} object.
1422 1 Adrian Georgescu
  [[BR]]''response_code'':[[BR]]
1423 1 Adrian Georgescu
  The code of the provisional response to use as an int.
1424 1 Adrian Georgescu
  This should be in the 1xx range.
1425 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1426 29 Luci Stanescu
  Any extra headers that should be included in the response in the form of a dict.
1427 1 Adrian Georgescu
 '''accept_invite'''(''self'', '''extra_headers'''={{{None}}})::
1428 1 Adrian Georgescu
  This tries to move the state machine into the {{{CONNECTING}}} state by sending a 200 OK response to the initial {{{INVITE}}}.
1429 1 Adrian Georgescu
  It may only be called from the {{{INCOMING}}} or {{{EARLY}}} states on an incoming {{{Invitation}}} object.
1430 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1431 1 Adrian Georgescu
  Any extra headers that should be included in the response in the form of a dict.
1432 1 Adrian Georgescu
 '''end'''(''self'', '''response_code'''=603, '''extra_headers'''={{{None}}}, '''timeout'''={{{None}}})::
1433 1 Adrian Georgescu
  This moves the {{{INVITE}}} state machine into the {{{DISCONNECTING}}} state by sending the necessary SIP message.
1434 1 Adrian Georgescu
  When a response from the remote party is received, the state machine will go into the {{{DISCONNECTED}}} state.
1435 1 Adrian Georgescu
  Depending on the current state, this could be a CANCEL or BYE request or a negative response.
1436 1 Adrian Georgescu
  [[BR]]''response_code'':[[BR]]
1437 1 Adrian Georgescu
  The code of the response to use as an int, if transmission of a response is needed.
1438 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1439 1 Adrian Georgescu
  Any extra headers that should be included in the request or response in the form of a dict.
1440 1 Adrian Georgescu
  [[BR]]''timeout'':[[BR]]
1441 1 Adrian Georgescu
  How many seconds to wait for the remote party to reply before changing the state to {{{DISCONNECTED}}}, as an int or a float.
1442 1 Adrian Georgescu
  If this is set to {{{None}}}, the default PJSIP timeout will be used, which currently appears to be 3.5 seconds for an established session.
1443 1 Adrian Georgescu
 '''respond_to_reinvite'''(''self'', '''response_code'''=200, '''extra_headers'''={{{None}}})::
1444 1 Adrian Georgescu
  Respond to a received re-{{{INVITE}}} with a response that is either provisional (1xx), positive (2xx) or negative (3xx and upwards).
1445 1 Adrian Georgescu
  This method can be called by the application when the state machine is in the {{{REINVITED}}} state and will move the state machine back into the {{{CONFIRMED}}} state.
1446 1 Adrian Georgescu
  Before giving a positive final response, the SDP needs to be set using the {{{set_offered_local_sdp()}}} method.
1447 1 Adrian Georgescu
  [[BR]]''response_code'':[[BR]]
1448 1 Adrian Georgescu
  The code of the response to use as an int.
1449 29 Luci Stanescu
  This should be a 3 digit number.
1450 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1451 1 Adrian Georgescu
 '''send_reinvite'''(''self'', '''extra_headers'''={{{None}}})::
1452 1 Adrian Georgescu
  The application may only call this method when the state machine is in the {{{CONFIRMED}}} state to induce sending a re-{{{INVITE}}}.
1453 1 Adrian Georgescu
  Before doing this it needs to set the new local SDP offer by calling the {{{set_offered_local_sdp()}}} method.
1454 1 Adrian Georgescu
  After this method is called, the state machine will be in the {{{REINVITING}}} state, until a final response from the remote party is received.
1455 1 Adrian Georgescu
  [[BR]]''extra_headers'':[[BR]]
1456 1 Adrian Georgescu
  Any extra headers that should be included in the re-{{{INVITE}}} in the form of a dict.
1457 1 Adrian Georgescu
1458 1 Adrian Georgescu
==== notifications ====
1459 1 Adrian Georgescu
1460 1 Adrian Georgescu
 '''SIPInvitationChangedState'''::
1461 1 Adrian Georgescu
  This notification is sent by an {{{Invitation}}} object whenever its state machine changes state.
1462 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1463 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1464 1 Adrian Georgescu
  [[BR]]''prev_state'':[[BR]]
1465 1 Adrian Georgescu
  The previous state of the INVITE state machine.
1466 1 Adrian Georgescu
  [[BR]]''state'':[[BR]]
1467 1 Adrian Georgescu
  The new state of the INVITE state machine, which may be the same as the previous state.
1468 1 Adrian Georgescu
  [[BR]]''method'': (only if the state change got triggered by an incoming SIP request)[[BR]]
1469 1 Adrian Georgescu
  The method of the SIP request as a string.
1470 1 Adrian Georgescu
  [[BR]]''request_uri'': (only if the state change got triggered by an incoming SIP request)[[BR]]
1471 1 Adrian Georgescu
  The request URI of the SIP request as a {{{SIPURI}}} object.
1472 1 Adrian Georgescu
  [[BR]]''code'': (only if the state change got triggered by an incoming SIP response or internal timeout or error)[[BR]]
1473 1 Adrian Georgescu
  The code of the SIP response or error as an int.
1474 1 Adrian Georgescu
  [[BR]]''reason'': (only if the state change got triggered by an incoming SIP response or internal timeout or error)[[BR]]
1475 84 Ruud Klaver
  The reason text of the SIP response or error as a string.
1476 23 Ruud Klaver
  [[BR]]''headers'': (only if the state change got triggered by an incoming SIP request or response)[[BR]]
1477 1 Adrian Georgescu
  The headers of the SIP request or response as a dict.
1478 1 Adrian Georgescu
  Each SIP header is represented in its parsed for as long as PJSIP supports it.
1479 1 Adrian Georgescu
  The format of the parsed value depends on the header.
1480 1 Adrian Georgescu
  [[BR]]''body'': (only if the state change got triggered by an incoming SIP request or response)[[BR]]
1481 1 Adrian Georgescu
  The body of the SIP request or response as a string, or {{{None}}} if no body was included.
1482 1 Adrian Georgescu
  The content type of the body can be learned from the {{{Content-Type:}}} header in the headers argument.
1483 1 Adrian Georgescu
 '''SIPInvitationGotSDPUpdate'''::
1484 71 Adrian Georgescu
  This notification is sent by an {{{Invitation}}} object whenever SDP negotiation has been performed.
1485 1 Adrian Georgescu
  It should be used by the application as an indication to start, change or stop any associated media streams.
1486 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1487 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1488 1 Adrian Georgescu
  [[BR]]''succeeded'':[[BR]]
1489 71 Adrian Georgescu
  A boolean indicating if the SDP negotiation has succeeded.
1490 71 Adrian Georgescu
  [[BR]]''error'': (only if SDP negotiation did not succeed)[[BR]]
1491 71 Adrian Georgescu
  A string indicating why SDP negotiation failed.
1492 71 Adrian Georgescu
  [[BR]]''local_sdp'': (only if SDP negotiation succeeded)[[BR]]
1493 1 Adrian Georgescu
  A SDPSession object indicating the local SDP that was negotiated.
1494 71 Adrian Georgescu
  [[BR]]''remote_sdp'': (only if SDP negotiation succeeded)[[BR]]
1495 1 Adrian Georgescu
  A SDPSession object indicating the remote SDP that was negotiated.
1496 1 Adrian Georgescu
1497 1 Adrian Georgescu
=== SDPSession ===
1498 1 Adrian Georgescu
1499 1 Adrian Georgescu
SDP stands for Session Description Protocol. Session Description Protocol (SDP) is a format for describing streaming media initialization parameters in an ASCII string. SDP is intended for describing multimedia communication sessions for the purposes of session announcement, session invitation, and other forms of multimedia session initiation. It is an IETF standard described by [http://tools.ietf.org/html/rfc4566 RFC 4566]. [http://tools.ietf.org/html/rfc3264 RFC 3264] defines an Offer/Answer Model with the Session Description Protocol (SDP), a mechanism by which two entities can make use of the Session Description Protocol (SDP) to arrive at a common view of a multimedia session between them. 
1500 1 Adrian Georgescu
1501 1 Adrian Georgescu
SDPSession object directly represents the contents of a SDP body, as carried e.g. in a INVITE request, and is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__session.htm pjmedia_sdp_session] structure.
1502 1 Adrian Georgescu
It can be passed to those methods of an {{{Invitation}}} object that result in transmission of a message that includes SDP, or is passed to the application through a notification that is triggered by reception of a message that includes SDP.
1503 1 Adrian Georgescu
A {{{SDPSession}}} object may contain {{{SDPMedia}}}, {{{SDPConnection}}} and {{{SDPAttribute}}} objects.
1504 1 Adrian Georgescu
It supports comparison to other {{{SDPSession}}} objects using the == and != expressions.
1505 1 Adrian Georgescu
As all the attributes of the {{{SDPSession}}} class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1506 1 Adrian Georgescu
1507 1 Adrian Georgescu
==== methods ====
1508 1 Adrian Georgescu
1509 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''address''', '''id'''={{{None}}}, '''version'''={{{None}}}, '''user='''"-", net_type="IN", '''address_type'''="IP4", '''name'''=" ", '''info'''={{{None}}}, '''connection'''={{{None}}}, '''start_time'''=0, '''stop_time'''=0, '''attributes'''={{{None}}}, '''media'''={{{None}}})::
1510 1 Adrian Georgescu
  Creates the SDPSession object with the specified parameters as attributes.
1511 1 Adrian Georgescu
  Each of these attributes can be accessed and changed on the object once instanced.
1512 1 Adrian Georgescu
  [[BR]]''address'':[[BR]]
1513 1 Adrian Georgescu
  The address that is contained in the "o" (origin) line of the SDP as a string.
1514 1 Adrian Georgescu
  [[BR]]''id'':[[BR]]
1515 1 Adrian Georgescu
  The session identifier contained in the "o" (origin) line of the SDP as an int.
1516 1 Adrian Georgescu
  If this is set to {{{None}}} on init, a session identifier will be generated.
1517 1 Adrian Georgescu
  [[BR]]''version'':[[BR]]
1518 1 Adrian Georgescu
  The version identifier contained in the "o" (origin) line of the SDP as an int.
1519 1 Adrian Georgescu
  If this is set to {{{None}}} on init, a version identifier will be generated.
1520 24 Ruud Klaver
  [[BR]]''user'':[[BR]]
1521 1 Adrian Georgescu
  The user name contained in the "o" (origin) line of the SDP as a string.
1522 1 Adrian Georgescu
  [[BR]]''net_type'':[[BR]]
1523 1 Adrian Georgescu
  The network type contained in the "o" (origin) line of the SDP as a string.
1524 1 Adrian Georgescu
  [[BR]]''address_type'':[[BR]]
1525 1 Adrian Georgescu
  The address type contained in the "o" (origin) line of the SDP as a string.
1526 1 Adrian Georgescu
  [[BR]]''name'':[[BR]]
1527 1 Adrian Georgescu
  The contents of the "s" (session name) line of the SDP as a string.
1528 1 Adrian Georgescu
  [[BR]]''info'':[[BR]]
1529 1 Adrian Georgescu
  The contents of the session level "i" (information) line of the SDP as a string.
1530 1 Adrian Georgescu
  If this is {{{None}}} or an empty string, the SDP has no "i" line.
1531 1 Adrian Georgescu
  [[BR]]''connection'':[[BR]]
1532 1 Adrian Georgescu
  The contents of the "c" (connection) line of the SDP as a {{{SDPConnection}}} object.
1533 1 Adrian Georgescu
  If this is set to {{{None}}}, the SDP has no session level "c" line.
1534 1 Adrian Georgescu
  [[BR]]''start_time'':[[BR]]
1535 1 Adrian Georgescu
  The first value of the "t" (time) line of the SDP as an int.
1536 1 Adrian Georgescu
  [[BR]]''stop_time'':[[BR]]
1537 1 Adrian Georgescu
  The second value of the "t" (time) line of the SDP as an int.
1538 1 Adrian Georgescu
  [[BR]]''attributes'':[[BR]]
1539 1 Adrian Georgescu
  The session level "a" lines (attributes) in the SDP represented by a list of {{{SDPAttribute}}} objects.
1540 1 Adrian Georgescu
  [[BR]]''media'':[[BR]]
1541 1 Adrian Georgescu
  The media sections of the SDP represented by a list of {{{SDPMedia}}} objects.
1542 1 Adrian Georgescu
1543 1 Adrian Georgescu
=== SDPMedia ===
1544 1 Adrian Georgescu
1545 1 Adrian Georgescu
This object represents the contents of a media section of a SDP body, i.e. a "m" line and everything under it until the next "m" line.
1546 1 Adrian Georgescu
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__media.htm pjmedia_sdp_media] structure.
1547 1 Adrian Georgescu
One or more {{{SDPMedia}}} objects are usually contained in a {{{SDPSession}}} object.
1548 1 Adrian Georgescu
It supports comparison to other {{{SDPMedia}}} objects using the == and != expressions.
1549 1 Adrian Georgescu
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1550 1 Adrian Georgescu
1551 1 Adrian Georgescu
==== methods ====
1552 1 Adrian Georgescu
1553 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''media''', '''port''', '''transport''', '''port_count'''=1, '''formats'''={{{None}}}, '''info'''={{{None}}}, '''connection'''={{{None}}}, '''attributes'''={{{None}}})::
1554 1 Adrian Georgescu
  Creates the SDPMedia object with the specified parameters as attributes.
1555 1 Adrian Georgescu
  Each of these attributes can be accessed and changed on the object once instanced.
1556 1 Adrian Georgescu
  [[BR]]''media'':[[BR]]
1557 1 Adrian Georgescu
  The media type contained in the "m" (media) line as a string.
1558 1 Adrian Georgescu
  [[BR]]''port'':[[BR]]
1559 1 Adrian Georgescu
  The transport port contained in the "m" (media) line as an int.
1560 1 Adrian Georgescu
  [[BR]]''transport'':[[BR]]
1561 1 Adrian Georgescu
  The transport protocol in the "m" (media) line as a string.
1562 1 Adrian Georgescu
  [[BR]]''port_count'':[[BR]]
1563 1 Adrian Georgescu
  The port count in the "m" (media) line as an int.
1564 1 Adrian Georgescu
  If this is set to 1, it is not included in the SDP.
1565 1 Adrian Georgescu
  [[BR]]''formats'':[[BR]]
1566 1 Adrian Georgescu
  The media formats in the "m" (media) line represented by a list of strings.
1567 1 Adrian Georgescu
  [[BR]]''info'':[[BR]]
1568 1 Adrian Georgescu
  The contents of the "i" (information) line of this media section as a string.
1569 1 Adrian Georgescu
  If this is {{{None}}} or an empty string, the media section has no "i" line.
1570 1 Adrian Georgescu
  [[BR]]''connection'':[[BR]]
1571 1 Adrian Georgescu
  The contents of the "c" (connection) line that is somewhere below the "m" line of this section as a {{{SDPConnection}}} object.
1572 1 Adrian Georgescu
  If this is set to {{{None}}}, this media section has no "c" line.
1573 1 Adrian Georgescu
  [[BR]]''attributes'':[[BR]]
1574 1 Adrian Georgescu
  The "a" lines (attributes) that are somewhere below the "m" line of this section represented by a list of {{{SDPAttribute}}} objects.
1575 1 Adrian Georgescu
 '''get_direction'''(''self'')::
1576 1 Adrian Georgescu
  This is a convenience methods that goes through all the attributes of the media section and returns the direction, which is either "sendrecv", "sendonly", "recvonly" or "inactive".
1577 1 Adrian Georgescu
  If none of these attributes is present, the default direction is "sendrecv".
1578 1 Adrian Georgescu
1579 1 Adrian Georgescu
=== SDPConnection ===
1580 1 Adrian Georgescu
1581 1 Adrian Georgescu
This object represents the contents of a "c" (connection) line of a SDP body, either at the session level or for an individual media stream.
1582 1 Adrian Georgescu
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__conn.htm pjmedia_sdp_conn] structure.
1583 1 Adrian Georgescu
A {{{SDPConnection}}} object can be contained in a {{{SDPSession}}} object or {{{SDPMedia}}} object.
1584 1 Adrian Georgescu
It supports comparison to other {{{SDPConnection}}} objects using the == and != expressions.
1585 1 Adrian Georgescu
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1586 1 Adrian Georgescu
1587 1 Adrian Georgescu
==== methods ====
1588 1 Adrian Georgescu
1589 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''address''', '''net_type'''="IN", '''address_type'''="IP4")::
1590 1 Adrian Georgescu
  Creates the SDPConnection object with the specified parameters as attributes.
1591 1 Adrian Georgescu
  Each of these attributes can be accessed and changed on the object once instanced.
1592 1 Adrian Georgescu
  [[BR]]''address'':[[BR]]
1593 1 Adrian Georgescu
  The address part of the connection line as a string.
1594 1 Adrian Georgescu
  [[BR]]''net_type'':[[BR]]
1595 1 Adrian Georgescu
  The network type part of the connection line as a string.
1596 1 Adrian Georgescu
  [[BR]]''address_type'':[[BR]]
1597 1 Adrian Georgescu
  The address type part of the connection line as a string.
1598 1 Adrian Georgescu
1599 1 Adrian Georgescu
=== SDPAttribute ===
1600 1 Adrian Georgescu
1601 18 Adrian Georgescu
This object represents the contents of a "a" (attribute) line of a SDP body, either at the session level or for an individual media stream.
1602 1 Adrian Georgescu
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__attr.htm pjmedia_sdp_attr] structure.
1603 1 Adrian Georgescu
One or more {{{SDPAttribute}}} objects can be contained in a {{{SDPSession}}} object or {{{SDPMedia}}} object.
1604 17 Ruud Klaver
It supports comparison to other {{{SDPAttribute}}} objects using the == and != expressions.
1605 17 Ruud Klaver
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1606 17 Ruud Klaver
1607 17 Ruud Klaver
==== methods ====
1608 17 Ruud Klaver
1609 17 Ruud Klaver
 '''!__init!__'''(''self'', '''name''', '''value''')::
1610 17 Ruud Klaver
  Creates the SDPAttribute object with the specified parameters as attributes.
1611 17 Ruud Klaver
  Each of these attributes can be accessed and changed on the object once instanced.
1612 17 Ruud Klaver
  [[BR]]''name'':[[BR]]
1613 1 Adrian Georgescu
  The name part of the attribute line as a string.
1614 1 Adrian Georgescu
  [[BR]]''value'':[[BR]]
1615 1 Adrian Georgescu
  The value part of the attribute line as a string.
1616 1 Adrian Georgescu
1617 1 Adrian Georgescu
=== RTPTransport ===
1618 1 Adrian Georgescu
1619 1 Adrian Georgescu
This object represents a transport for RTP media, the basis of which is a pair of UDP sockets, one for RTP and one for RTCP.
1620 1 Adrian Georgescu
Internally it wraps a [http://www.pjsip.org/pjmedia/docs/html/group__PJMEDIA__TRANSPORT.htm pjmedia_transport] object.
1621 1 Adrian Georgescu
Initially this object will only be used by the {{{AudioTransport}}} object, but in the future it can also be used for video and [wiki:RTTProposal Real-Time Text].
1622 17 Ruud Klaver
For this reason the {{{AudioTransport}}} and {{{RTPTransport}}} are two distinct objects.
1623 1 Adrian Georgescu
1624 1 Adrian Georgescu
The {{{RTPTransport}}} object also allows support for ICE and SRTP functionality from PJSIP.
1625 1 Adrian Georgescu
Because these features are related to both the UDP transport and the SDP formatting, the SDP carried in SIP signaling message will need to "pass through" this object during the SDP negotiation.
1626 1 Adrian Georgescu
The code using this object, which in most cases will be the {{{AudioTransport}}} object, will need to call certain methods on the object at appropriate times.
1627 1 Adrian Georgescu
This process of SDP negotiation is represented by the internal state machine of the object, as shown in the following diagram:
1628 1 Adrian Georgescu
1629 17 Ruud Klaver
> The Real-time Transport Protocol (or RTP) defines a standardized packet format for delivering audio and video over the Internet.
1630 1 Adrian Georgescu
> It was developed by the Audio-Video Transport Working Group of the IETF and published in [http://tools.ietf.org/html/rfc3550 RFC 3550].
1631 1 Adrian Georgescu
> RTP is used in streaming media systems (together with the RTSP) as well as in videoconferencing and push to talk systems.
1632 1 Adrian Georgescu
> For these it carries media streams controlled by Session Initiation Protocol (SIP) signaling protocols, making it the technical foundation of the Voice over IP industry.
1633 1 Adrian Georgescu
1634 1 Adrian Georgescu
[[Image(sipsimple-rtp-transport-state-machine.png, nolink)]]
1635 1 Adrian Georgescu
1636 1 Adrian Georgescu
State changes are triggered by the following events:
1637 1 Adrian Georgescu
 1. The application calls the {{{set_INIT()}}} method after object creation and ICE+STUN is not used.
1638 1 Adrian Georgescu
 2. The application calls the {{{set_INIT()}}} method after object creation and ICE+STUN is used.
1639 1 Adrian Georgescu
 3. A successful STUN response is received from the STUN server.
1640 1 Adrian Georgescu
 4. The {{{set_LOCAL()}}} method is called.
1641 1 Adrian Georgescu
 5. The {{{set_ESTABLISHED()}}} method is called.
1642 1 Adrian Georgescu
 6. The {{{set_INIT()}}} method is called while the object is in the {{{LOCAL}}} or {{{ESTABLISHED}}} state.
1643 45 Ruud Klaver
 7. A method is called on the application, but in the meantime the {{{Engine}}} has stopped.
1644 1 Adrian Georgescu
    The object can no longer be used.
1645 1 Adrian Georgescu
 8. There was an error in getting the STUN candidates from the STUN server.
1646 1 Adrian Georgescu
1647 71 Adrian Georgescu
> It would make sense to be able to use the object even if the STUN request fails (and have ICE not include a STUN candidate), but for some reason the pjmedia_transport is unusable once STUN negotiation has failed.
1648 1 Adrian Georgescu
> This means that the RTPTransport object is also unusable once it has reached the STUN_FAILED state.
1649 1 Adrian Georgescu
> A workaround would be destroy the RTPTransport object and create a new one that uses ICE without STUN.
1650 1 Adrian Georgescu
1651 1 Adrian Georgescu
These states allow for two SDP negotiation scenarios to occur, represented by two paths that can be followed through the state machine.
1652 1 Adrian Georgescu
In this example we will assume that ICE with STUN is not used, as it is independent of the SDP negotiation procedure.
1653 1 Adrian Georgescu
 * The first scenario is where the local party generates the SDP offer.
1654 1 Adrian Georgescu
   For a stream that it wishes to include in this SDP offer, it instantiates a {{{RTPTransport}}} object.
1655 1 Adrian Georgescu
   After instantiation the object is initialized by calling the {{{set_INIT()}}} method and the local RTP address and port can be fetched from it using the {{{local_rtp_address}}} and {{{local_rtp_port}}} respectively, which can be used to generate the local SDP in the form of a {{{SDPSession}}} object (note that it needs the full object, not just the relevant {{{SDPMedia}}} object).
1656 1 Adrian Georgescu
   This local SDP then needs to be passed to the {{{set_LOCAL()}}} method, which moves the state machine into the {{{LOCAL}}} state.
1657 1 Adrian Georgescu
   Depending on the options used for the {{{RTPTransport}}} instantiation (such as ICE and SRTP), this may change the {{{SDPSession}}} object.
1658 1 Adrian Georgescu
   This (possibly changed) {{{SDPSession}}} object then needs to be passed to the {{{Invitation}}} object.
1659 1 Adrian Georgescu
   After SDP negotiation is completed, the application needs to pass both the local and remote SDP, in the form of {{{SDPSession}}} objects, to the {{{RTPTransport}}} object using the {{{set_ESTABLISHED()}}} method, moving the state machine into the {{{ESTABLISHED}}} state.
1660 1 Adrian Georgescu
   This will not change either of the {{{SDPSession}}} objects.
1661 1 Adrian Georgescu
 * The second scenario is where the local party is offered a media stream in SDP and wants to accept it.
1662 1 Adrian Georgescu
   In this case a {{{RTPTransport}}} is also instantiated and initialized using the {{{set_INIT()}}} method, and the application can generate the local SDP in response to the remote SDP, using the {{{local_rtp_address}}} and {{{local_rtp_port}}} attributes.
1663 1 Adrian Georgescu
   Directly after this it should pass the generated local SDP and received remote SDP, in the form of {{{SDPSession}}} objects, to the {{{set_ESTABLISHED()}}} method.
1664 1 Adrian Georgescu
   In this case the local SDP object may be changed, after which it can be passed to the {{{Invitation}}} object.
1665 1 Adrian Georgescu
1666 1 Adrian Georgescu
Whenever the {{{RTPTransport}}} object is in the {{{LOCAL}}} or {{{ESTABLISHED}}} states, it may be reset to the {{{INIT}}} state to facilitate re-use of the existing transport and its features.
1667 1 Adrian Georgescu
Before doing this however, the internal transport object must no longer be in use.
1668 1 Adrian Georgescu
1669 1 Adrian Georgescu
==== attributes ====
1670 1 Adrian Georgescu
1671 1 Adrian Georgescu
 '''state'''::
1672 1 Adrian Georgescu
  Indicates which state the internal state machine is in.
1673 1 Adrian Georgescu
  See the previous section for a list of states the state machine can be in.
1674 1 Adrian Georgescu
  This attribute is read-only.
1675 1 Adrian Georgescu
 '''local_rtp_address'''::
1676 19 Ruud Klaver
  The local IPv4 address of the interface the {{{RTPTransport}}} object is listening on and the address that should be included in the SDP.
1677 1 Adrian Georgescu
  If no address was specified during object instantiation, PJSIP will take guess out of the IP addresses of all interfaces.
1678 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} if PJSIP is not listening on the transport.
1679 1 Adrian Georgescu
 '''local_rtp_port'''::
1680 1 Adrian Georgescu
  The UDP port PJSIP is listening on for RTP traffic.
1681 1 Adrian Georgescu
  RTCP traffic will always be this port plus one.
1682 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} if PJSIP is not listening on the transport.
1683 1 Adrian Georgescu
 '''remote_rtp_address_sdp'''::
1684 1 Adrian Georgescu
  The remote IP address that was seen in the SDP.
1685 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} unless the object is in the {{{ESTABLISHED}}} state.
1686 1 Adrian Georgescu
 '''remote_rtp_port_sdp'''::
1687 1 Adrian Georgescu
  The remote UDP port for RTP that was seen in the SDP.
1688 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} unless the object is in the {{{ESTABLISHED}}} state.
1689 45 Ruud Klaver
 '''remote_rtp_address_received'''::
1690 1 Adrian Georgescu
  The remote IP address from which RTP data was received.
1691 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} unless RTP was actually received.
1692 1 Adrian Georgescu
 '''remote_rtp_port_received'''::
1693 1 Adrian Georgescu
  The remote UDP port from which RTP data was received.
1694 1 Adrian Georgescu
  This attribute is read-only and will be {{{None}}} unless RTP was actually received.
1695 1 Adrian Georgescu
 '''use_srtp'''::
1696 1 Adrian Georgescu
  A boolean indicating if the use of SRTP was requested when the object was instantiated.
1697 1 Adrian Georgescu
  This attribute is read-only.
1698 1 Adrian Georgescu
 '''force_srtp'''::
1699 1 Adrian Georgescu
  A boolean indicating if SRTP being mandatory for this transport if it is enabled was requested when the object was instantiated.
1700 1 Adrian Georgescu
  This attribute is read-only.
1701 1 Adrian Georgescu
 '''srtp_active'''::
1702 1 Adrian Georgescu
  A boolean indicating if SRTP encryption and decryption is running.
1703 1 Adrian Georgescu
  Querying this attribute only makes sense once the object is in the {{{ESTABLISHED}}} state and use of SRTP was requested.
1704 29 Luci Stanescu
  This attribute is read-only.
1705 1 Adrian Georgescu
 '''use_ice'''::
1706 1 Adrian Georgescu
  A boolean indicating if the use of ICE was requested when the object was instantiated.
1707 1 Adrian Georgescu
  This attribute is read-only.
1708 1 Adrian Georgescu
 '''ice_stun_address'''::
1709 34 Ruud Klaver
  A string indicating the IP address of the STUN server that was requested to be used.
1710 34 Ruud Klaver
  This attribute is read-only.
1711 34 Ruud Klaver
 '''ice_stun_port'''::
1712 34 Ruud Klaver
  A string indicating the UDP port of the STUN server that was requested to be used.
1713 1 Adrian Georgescu
  This attribute is read-only.
1714 1 Adrian Georgescu
1715 1 Adrian Georgescu
==== methods ====
1716 1 Adrian Georgescu
1717 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''local_rtp_address'''={{{None}}}, '''use_srtp'''={{{False}}}, '''srtp_forced'''={{{False}}}, '''use_ice'''={{{False}}}, '''ice_stun_address'''={{{None}}}, '''ice_stun_port'''=3478)::
1718 1 Adrian Georgescu
  Creates a new {{{RTPTransport}}} object and opens the RTP and RTCP UDP sockets.
1719 71 Adrian Georgescu
  If additional features are requested, they will be initialized.
1720 1 Adrian Georgescu
  After object instantiation, it is either in the {{{INIT}}} or the {{{WAIT_STUN}}} state, depending on the values of the {{{use_ice}}} and {{{ice_stun_address}}} arguments.
1721 1 Adrian Georgescu
  [[BR]]''local_rtp_address'':[[BR]]
1722 1 Adrian Georgescu
  Optionally contains the local IPv4 address to listen on.
1723 1 Adrian Georgescu
  If this is not specified, PJSIP will listen on all network interfaces.
1724 1 Adrian Georgescu
  [[BR]]''use_srtp'':[[BR]]
1725 1 Adrian Georgescu
  A boolean indicating if SRTP should be used.
1726 17 Ruud Klaver
  If this is set to {{{True}}}, SRTP information will be added to the SDP when it passes this object.
1727 17 Ruud Klaver
  [[BR]]''srtp_forced'':[[BR]]
1728 1 Adrian Georgescu
  A boolean indicating if use of SRTP is set to mandatory in the SDP.
1729 71 Adrian Georgescu
  If this is set to {{{True}}} and the remote party does not support SRTP, the SDP negotiation for this stream will fail.
1730 1 Adrian Georgescu
  This argument is relevant only if {{{use_srtp}}} is set to {{{True}}}.
1731 29 Luci Stanescu
  [[BR]]''use_ice'':[[BR]]
1732 17 Ruud Klaver
  A boolean indicating if ICE should be used.
1733 17 Ruud Klaver
  If this is set to {{{True}}}, ICE candidates will be added to the SDP when it passes this object.
1734 1 Adrian Georgescu
  [[BR]]''ice_stun_address'':[[BR]]
1735 1 Adrian Georgescu
  A string indicating the address (IP address or hostname) of the STUN server that should be used to add a STUN candidate to the ICE candidates.
1736 29 Luci Stanescu
  If this is set to {{{None}}} no STUN candidate will be added, otherwise the object will be put into the {{{WAIT_STUN}}} state until a reply, either positive or negative, is received from the specified STUN server.
1737 17 Ruud Klaver
  When this happens a {{{RTPTransportGotSTUNResponse}}} notification is sent.
1738 17 Ruud Klaver
  This argument is relevant only if {{{use_ice}}} is set to {{{True}}}.
1739 17 Ruud Klaver
  [[BR]]''ice_stun_address'':[[BR]]
1740 17 Ruud Klaver
  An int indicating the UDP port of the STUN server that should be used to add a STUN candidate to the ICE candidates.
1741 17 Ruud Klaver
  This argument is relevant only if {{{use_ice}}} is set to {{{True}}} and {{{ice_stun_address}}} is not {{{None}}}.
1742 1 Adrian Georgescu
 '''set_INIT'''(''self'')::
1743 1 Adrian Georgescu
  This moves the internal state machine into the {{{INIT}}} state.
1744 1 Adrian Georgescu
  If the state machine is in the {{{LOCAL}}} or {{{ESTABLISHED}}} states, this effectively resets the {{{RTPTransport}}} object for re-use.
1745 1 Adrian Georgescu
 '''set_LOCAL'''(''self'', '''local_sdp''', '''sdp_index''')::
1746 1 Adrian Georgescu
  This moves the the internal state machine into the {{{LOCAL}}} state.
1747 1 Adrian Georgescu
  [[BR]]''local_sdp'':[[BR]]
1748 1 Adrian Georgescu
  The local SDP to be proposed in the form of a {{{SDPSession}}} object.
1749 1 Adrian Georgescu
  Note that this object may be modified by this method.
1750 1 Adrian Georgescu
  [[BR]]''sdp_index'':[[BR]]
1751 1 Adrian Georgescu
  The index in the SDP for the media stream for which this object was created.
1752 1 Adrian Georgescu
 '''set_ESTABLISHED'''(''self'', '''local_sdp''', '''remote_sdp''', '''sdp_index''')::
1753 1 Adrian Georgescu
  This moves the the internal state machine into the {{{ESTABLISHED}}} state.
1754 1 Adrian Georgescu
  [[BR]]''local_sdp'':[[BR]]
1755 1 Adrian Georgescu
  The local SDP to be proposed in the form of a {{{SDPSession}}} object.
1756 1 Adrian Georgescu
  Note that this object may be modified by this method, but only when moving from the {{{LOCAL}}} to the {{{ESTABLISHED}}} state.
1757 1 Adrian Georgescu
  [[BR]]''remote_sdp'':[[BR]]
1758 1 Adrian Georgescu
  The remote SDP that was received in in the form of a {{{SDPSession}}} object.
1759 1 Adrian Georgescu
  [[BR]]''sdp_index'':[[BR]]
1760 1 Adrian Georgescu
  The index in the SDP for the media stream for which this object was created.
1761 1 Adrian Georgescu
1762 1 Adrian Georgescu
==== notifications ====
1763 1 Adrian Georgescu
1764 1 Adrian Georgescu
 '''RTPTransportDidInitialize'''::
1765 1 Adrian Georgescu
  This notification is sent when a {{{RTPTransport}}} object has successfully initialized.
1766 1 Adrian Georgescu
  If STUN+ICE is not requested, this is sent immediately on {{{set_INIT()}}}, otherwise it is sent after the STUN query has succeeded.
1767 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1768 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1769 1 Adrian Georgescu
 '''RTPTransportDidFail'''::
1770 1 Adrian Georgescu
  This notification is sent by a {{{RTPTransport}}} object that fails to retrieve ICE candidates from the STUN server after {{{set_INIT()}}} is called.
1771 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1772 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1773 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
1774 1 Adrian Georgescu
  A string describing the failure reason.
1775 1 Adrian Georgescu
1776 1 Adrian Georgescu
=== AudioTransport ===
1777 1 Adrian Georgescu
1778 1 Adrian Georgescu
This object represent an audio stream as it is transported over the network.
1779 1 Adrian Georgescu
It contains an instance of {{{RTPTransport}}} and wraps a [http://www.pjsip.org/pjmedia/docs/html/group__PJMED__STRM.htm pjmedia_stream] object, which in turn manages the RTP encapsulation, RTCP session, audio codec and adaptive jitter buffer.
1780 1 Adrian Georgescu
It also generates a {{{SDPMedia}}} object to be included in the local SDP.
1781 1 Adrian Georgescu
1782 75 Ruud Klaver
The {{{AudioTransport}}} is an object that, once started, is connected to a {{{ConferenceBridge}}} instance, and both produces and consumes sound.
1783 75 Ruud Klaver
1784 1 Adrian Georgescu
Like the {{{RTPTransport}}} object there are two usage scenarios.
1785 1 Adrian Georgescu
 * In the first scenario, only the {{{RTPTransport}}} instance to be used is passed to the AudioTransport object.
1786 1 Adrian Georgescu
   The application can then generate the {{{SDPMedia}}} object by calling the {{{get_local_media()}}} method and should include it in the SDP offer.
1787 40 Ruud Klaver
   Once the remote SDP is received, it should be set along with the complete local SDP by calling the {{{start()}}} method, which will start the audio stream.
1788 1 Adrian Georgescu
   The stream can then be connected to the conference bridge.
1789 1 Adrian Georgescu
 * In the other scenario the remote SDP is already known because it was received in an SDP offer and can be passed directly on object instantiation.
1790 1 Adrian Georgescu
   The local {{{SDPMedia}}} object can again be generated by calling the {{{get_local_media()}}} method and is to be included in the SDP answer.
1791 1 Adrian Georgescu
   The audio stream is started directly when the object is created.
1792 1 Adrian Georgescu
1793 1 Adrian Georgescu
Unlike the {{{RTPTransport}}} object, this object cannot be reused.
1794 1 Adrian Georgescu
1795 1 Adrian Georgescu
==== attributes ====
1796 1 Adrian Georgescu
1797 75 Ruud Klaver
 '''conference_bridge'''::
1798 75 Ruud Klaver
  The {{{ConferenceBridge}}} object that was passed when the object got instantiated.
1799 75 Ruud Klaver
  This attribute is read-only.
1800 1 Adrian Georgescu
 '''transport'''::
1801 71 Adrian Georgescu
  The {{{RTPTransport}}} object that was passed when the object got instantiated.
1802 40 Ruud Klaver
  This attribute is read-only.
1803 75 Ruud Klaver
 '''slot'''::
1804 75 Ruud Klaver
  A read-only property indicating the slot number at which this object is attached to the associated conference bridge.
1805 75 Ruud Klaver
  If the {{{AudioTransport}}} is not active (i.e. has not been started), this attribute will be {{{None}}}.
1806 75 Ruud Klaver
 '''volume'''::
1807 75 Ruud Klaver
  A writable property indicating the % of volume at which this object contributes audio to the conference bridge.
1808 75 Ruud Klaver
  By default this is set to 100.
1809 40 Ruud Klaver
 '''is_active'''::
1810 40 Ruud Klaver
  A boolean indicating if the object is currently sending and receiving audio.
1811 1 Adrian Georgescu
  This attribute is read-only.
1812 1 Adrian Georgescu
 '''is_started'''::
1813 1 Adrian Georgescu
  A boolean indicating if the object has been started.
1814 1 Adrian Georgescu
  Both this attribute and the {{{is_active}}} attribute get set to {{{True}}} once the {{{start()}}} method is called, but unlike the {{{is_active}}} attribute this attribute does not get set to {{{False}}} once {{{stop()}}} is called.
1815 1 Adrian Georgescu
  This is to prevent the object from being re-used.
1816 1 Adrian Georgescu
  This attribute is read-only.
1817 1 Adrian Georgescu
 '''codec'''::
1818 1 Adrian Georgescu
  Once the SDP negotiation is complete, this attribute indicates the audio codec that was negotiated, otherwise it will be {{{None}}}.
1819 54 Ruud Klaver
  This attribute is read-only.
1820 1 Adrian Georgescu
 '''sample_rate'''::
1821 1 Adrian Georgescu
  Once the SDP negotiation is complete, this attribute indicates the sample rate of the audio codec that was negotiated, otherwise it will be {{{None}}}.
1822 1 Adrian Georgescu
  This attribute is read-only.
1823 1 Adrian Georgescu
 '''direction'''::
1824 1 Adrian Georgescu
  The current direction of the audio transport, which is one of "sendrecv", "sendonly", "recvonly" or "inactive".
1825 1 Adrian Georgescu
  This attribute is read-only, although it can be set using the {{{update_direction()}}} method.
1826 1 Adrian Georgescu
1827 54 Ruud Klaver
==== methods ====
1828 1 Adrian Georgescu
1829 75 Ruud Klaver
 '''!__init!__'''(''self'', '''conference_bridge''', '''transport''', '''remote_sdp'''={{{None}}}, '''sdp_index'''=0, '''enable_silence_detection'''=True, '''codecs'''={{{None}}})::
1830 1 Adrian Georgescu
  Creates a new {{{AudioTransport}}} object and start the underlying stream if the remote SDP is already known.
1831 75 Ruud Klaver
  [[BR]]''conference_bridge'':[[BR]]
1832 75 Ruud Klaver
  The {{{ConferenceBridge}}} object that this object is to be connected to.
1833 1 Adrian Georgescu
  [[BR]]''transport'':[[BR]]
1834 1 Adrian Georgescu
  The transport to use in the form of a {{{RTPTransport}}} object.
1835 55 Ruud Klaver
  [[BR]]''remote_sdp'':[[BR]]
1836 55 Ruud Klaver
  The remote SDP that was received in the form of a {{{SDPSession}}} object.
1837 55 Ruud Klaver
  [[BR]]''sdp_index'':[[BR]]
1838 1 Adrian Georgescu
  The index within the SDP of the audio stream that should be created.
1839 1 Adrian Georgescu
  [[BR]]''enable_silence_detection''[[BR]]
1840 1 Adrian Georgescu
  Boolean that indicates if silence detection should be used for this audio stream.
1841 1 Adrian Georgescu
  When enabled, this {{{AudioTransport}}} object will stop sending audio to the remote party if the input volume is below a certain threshold.
1842 1 Adrian Georgescu
  [[BR]]''codecs''[[BR]]
1843 1 Adrian Georgescu
  A list of strings indicating the codecs that should be proposed in the SDP of this {{{AudioTransport}}}, in order of preference.
1844 1 Adrian Georgescu
  This overrides the global codecs list set on the {{{Engine}}}.
1845 1 Adrian Georgescu
  The values of this list are case insensitive.
1846 1 Adrian Georgescu
 '''get_local_media'''(''self'', '''is_offer''', '''direction'''="sendrecv")::
1847 1 Adrian Georgescu
  Generates a {{{SDPMedia}}} object which describes the audio stream.
1848 1 Adrian Georgescu
  This object should be included in a {{{SDPSession}}} object that gets passed to the {{{Invitation}}} object.
1849 1 Adrian Georgescu
  This method should also be used to obtain the SDP to include in re-INVITEs and replies to re-INVITEs.
1850 1 Adrian Georgescu
  [[BR]]''is_offer'':[[BR]]
1851 1 Adrian Georgescu
  A boolean indicating if the SDP requested is to be included in an offer.
1852 1 Adrian Georgescu
  If this is {{{False}}} it is to be included in an answer.
1853 1 Adrian Georgescu
  [[BR]]''direction'':[[BR]]
1854 29 Luci Stanescu
  The direction attribute to put in the SDP.
1855 1 Adrian Georgescu
 '''start'''(''self'', '''local_sdp''', '''remote_sdp''', '''sdp_index''', '''no_media_timeout'''=10, '''media_check_interval'''=30)::
1856 1 Adrian Georgescu
  This method should only be called once, when the application has previously sent an SDP offer and the answer has been received.
1857 1 Adrian Georgescu
  [[BR]]''local_sdp'':[[BR]]
1858 1 Adrian Georgescu
  The full local SDP that was included in the SDP negotiation in the form of a {{{SDPSession}}} object.
1859 1 Adrian Georgescu
  [[BR]]''remote_sdp'':[[BR]]
1860 1 Adrian Georgescu
  The remote SDP that was received in the form of a {{{SDPSession}}} object.
1861 55 Ruud Klaver
  [[BR]]''sdp_index'':[[BR]]
1862 54 Ruud Klaver
  The index within the SDP of the audio stream.
1863 54 Ruud Klaver
  [[BR]]''no_media_timeout'':[[BR]]
1864 54 Ruud Klaver
  This argument indicates after how many seconds after starting the {{{AudioTransport}}} the {{{RTPAudioTransportDidNotGetRTP}}} notification should be sent, if no RTP has been received at all.
1865 54 Ruud Klaver
  Setting this to 0 disables this an all subsequent RTP checks.
1866 54 Ruud Klaver
  [[BR]]''media_check_interval'':[[BR]]
1867 54 Ruud Klaver
  This indicates the interval at which the RTP stream should be checked, after it has initially received RTP at after {{{no_media_timeout}}} seconds.
1868 54 Ruud Klaver
  It means that if between two of these interval checks no RTP has been received, a {{{RTPAudioTransportDidNotGetRTP}}} notification will be sent.
1869 1 Adrian Georgescu
  Setting this to 0 will disable checking the RTP at intervals.
1870 1 Adrian Georgescu
  The initial check may still be performed if its timeout is non-zero.
1871 1 Adrian Georgescu
 '''stop'''(''self'')::
1872 1 Adrian Georgescu
  This method stops and destroys the audio stream encapsulated by this object.
1873 1 Adrian Georgescu
  After this it can no longer be used and should be deleted, while the {{{RTPTransport}}} object used by it can be re-used for something else.
1874 1 Adrian Georgescu
  This method will be called automatically when the object is deleted after it was started, but this should not be relied on because of possible reference counting issues.
1875 1 Adrian Georgescu
 '''send_dtmf'''(''self'', '''digit''')::
1876 1 Adrian Georgescu
  For a negotiated audio transport this sends one DTMF digit to the other party
1877 1 Adrian Georgescu
  [[BR]]''digit'':[[BR]]
1878 29 Luci Stanescu
  A string of length one indicating the DTMF digit to send.
1879 1 Adrian Georgescu
  This can be either a number or letters A through D.
1880 1 Adrian Georgescu
 '''update_direction'''(''self'', '''direction''')::
1881 1 Adrian Georgescu
  This method should be called after SDP negotiation has completed to update the direction of the media stream.
1882 1 Adrian Georgescu
  [[BR]]''direction'':[[BR]]
1883 1 Adrian Georgescu
  The direction that has been negotiated.
1884 1 Adrian Georgescu
1885 1 Adrian Georgescu
==== notifications ====
1886 1 Adrian Georgescu
1887 1 Adrian Georgescu
 '''RTPAudioTransportGotDTMF'''::
1888 1 Adrian Georgescu
  This notification will be sent when an incoming DTMF digit is received from the remote party.
1889 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1890 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1891 1 Adrian Georgescu
  [[BR]]''digit'':[[BR]]
1892 1 Adrian Georgescu
  The DTMF digit that was received, in the form of a string of length one.
1893 1 Adrian Georgescu
  This can be either a number or letters A through D.
1894 1 Adrian Georgescu
 '''RTPAudioTransportDidNotGetRTP'''::
1895 1 Adrian Georgescu
  This notification will be sent when no RTP packets have been received from the remote party for some time.
1896 1 Adrian Georgescu
  See the {{{start()}}} method for a more exact description.
1897 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1898 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1899 1 Adrian Georgescu
  [[BR]]''got_any'':[[BR]]
1900 1 Adrian Georgescu
  A boolean data attribute indicating if the {{{AudioTransport}}} every saw any RTP packets from the remote party.
1901 1 Adrian Georgescu
  In effect, if no RTP was received after {{{no_media_timeout}}} seconds, its value will be {{{False}}}.
1902 1 Adrian Georgescu
1903 78 Ruud Klaver
=== ToneGenerator ===
1904 78 Ruud Klaver
1905 78 Ruud Klaver
A {{{ToneGenerator}}} can generate a series of dual frequency tones and has a shortcut method for generating valid DTMF tones.
1906 78 Ruud Klaver
Each instance of this object is associated with a {{{ConferenceBridge}}} object, which it will connect to once started.
1907 78 Ruud Klaver
The tones will be sent to the slots on the conference bridge its slot is connected to.
1908 81 Ruud Klaver
Once started, a {{{ToneGenerator}}} can be stopped by calling the {{{stop()}}} method and is automatically destroyed when the reference count reaches 0.
1909 78 Ruud Klaver
1910 78 Ruud Klaver
==== attributes ====
1911 78 Ruud Klaver
1912 78 Ruud Klaver
 '''conference_bridge'''::
1913 78 Ruud Klaver
  The {{{ConferenceBridge}}} object that was passed when the object got instantiated.
1914 78 Ruud Klaver
  This attribute is read-only.
1915 78 Ruud Klaver
 '''slot'''::
1916 78 Ruud Klaver
  A read-only property indicating the slot number at which this object is attached to the associated conference bridge.
1917 78 Ruud Klaver
  If the {{{ToneGenerator}}} has not been started, this attribute will be {{{None}}}.
1918 78 Ruud Klaver
 '''volume'''::
1919 78 Ruud Klaver
  A writable property indicating the % of volume at which this object contributes audio to the conference bridge.
1920 78 Ruud Klaver
  By default this is set to 100.
1921 78 Ruud Klaver
 '''is_active'''::
1922 78 Ruud Klaver
  A boolean read-only property that indicates if the object has been started.
1923 78 Ruud Klaver
 '''is_busy'''::
1924 78 Ruud Klaver
  A boolean read-only property indicating if the {{{ToneGenerator}}} is busy playing tones.
1925 78 Ruud Klaver
1926 78 Ruud Klaver
==== methods ====
1927 78 Ruud Klaver
1928 78 Ruud Klaver
 '''!__init!__'''(''self'', '''conference_bridge''')::
1929 78 Ruud Klaver
  Creates a new {{{ToneGenerator}}} object.
1930 1 Adrian Georgescu
  [[BR]]''conference_bridge'':[[BR]]
1931 1 Adrian Georgescu
  The {{{ConferenceBridge}}} object that this object is to be connected to.
1932 78 Ruud Klaver
 '''start'''(''self'')::
1933 81 Ruud Klaver
  Start the tone generator and connect it to its associated {{{ConferenceBridge}}}.
1934 81 Ruud Klaver
 '''stop'''(''self'')::
1935 81 Ruud Klaver
  Stop the tone generator and remove it from the conference bridge.
1936 78 Ruud Klaver
 '''play_tones(''self'', '''tones''')::
1937 78 Ruud Klaver
  Play a sequence of single or dual frequency tones over the audio device.
1938 78 Ruud Klaver
  [[BR]]''tones'':[[BR]]
1939 78 Ruud Klaver
  This should be a list of 3-item tuples, in the form of {{{[(<freq1>, <freq2>, <duration>), ...]}}}, with Hz as unit for the frequencies and ms as unit for the duration.
1940 78 Ruud Klaver
  If {{{freq2}}} is 0, this indicates that only {{{freq1}}} should be used for the tone.
1941 78 Ruud Klaver
  If {{{freq1}}} is 0, this indicates a pause when no tone should be played for the set duration.
1942 78 Ruud Klaver
 '''play_dtmf(''self'', '''digit''')::
1943 78 Ruud Klaver
  Play a single DTMF digit.
1944 78 Ruud Klaver
  [[BR]]''digit'':[[BR]]
1945 80 Ruud Klaver
  A string of length 1 containing a valid DTMF digit, i.e. 0 through 9, #, * or A through D.
1946 78 Ruud Klaver
1947 78 Ruud Klaver
==== notifications ====
1948 78 Ruud Klaver
1949 78 Ruud Klaver
 '''ToneGeneratorDidFinishPlaying'''::
1950 78 Ruud Klaver
  This notification will be sent whenever playing of the queued tones has finished.
1951 78 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
1952 78 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1953 78 Ruud Klaver
1954 78 Ruud Klaver
1955 1 Adrian Georgescu
=== WaveFile ===
1956 1 Adrian Georgescu
1957 76 Ruud Klaver
This is a simple object that allows playing back of a {{{.wav}}} file over the PJSIP conference bridge.
1958 1 Adrian Georgescu
Only 16-bit PCM and A-law/U-law formats are supported.
1959 76 Ruud Klaver
Its main purpose is the playback of ringtones or previously recorded conversations.
1960 1 Adrian Georgescu
1961 77 Ruud Klaver
This object is associated with a {{{ConferenceBridge}}} instance and, once the {{{start()}}} method is called, connects to it and send sound to it.
1962 77 Ruud Klaver
Note that the slot of the {{{WaveFile}}} object still needs to be connected to another slot on the conference bridge before the file actually starts playing.
1963 76 Ruud Klaver
If the {{{stop()}}} method is called or the end of the {{{.wav}}} file is reached, a {{{WaveFileDidFinishPlaying}}} notification is sent by the object.
1964 1 Adrian Georgescu
After this the {{{start()}}} method may be called again in order to re-use the object.
1965 1 Adrian Georgescu
1966 1 Adrian Georgescu
It is the application's responsibility to keep a reference to the {{{WaveFile}}} object for the duration of playback.
1967 76 Ruud Klaver
If the reference count of the object reaches 0, playback will be stopped automatically.
1968 1 Adrian Georgescu
In this case no notification will be sent.
1969 1 Adrian Georgescu
1970 1 Adrian Georgescu
==== attributes ====
1971 1 Adrian Georgescu
1972 76 Ruud Klaver
 '''conference_bridge'''::
1973 76 Ruud Klaver
  The {{{ConferenceBridge}}} object that was passed when the object got instantiated.
1974 76 Ruud Klaver
  This attribute is read-only.
1975 1 Adrian Georgescu
 '''file_name'''::
1976 1 Adrian Georgescu
  The name of the {{{.wav}}} file, as specified when the object was created.
1977 76 Ruud Klaver
 '''slot'''::
1978 76 Ruud Klaver
  A read-only property indicating the slot number at which this object is attached to the associated conference bridge.
1979 76 Ruud Klaver
  If the {{{WaveFile}}} is not active, this attribute will be {{{None}}}.
1980 76 Ruud Klaver
 '''volume'''::
1981 76 Ruud Klaver
  A writable property indicating the % of volume at which this object contributes audio to the conference bridge.
1982 76 Ruud Klaver
  By default this is set to 100.
1983 1 Adrian Georgescu
 '''is_active'''::
1984 1 Adrian Georgescu
  A boolean read-only property that indicates if the file is currently being played back.
1985 1 Adrian Georgescu
1986 15 Ruud Klaver
==== methods ====
1987 15 Ruud Klaver
1988 76 Ruud Klaver
 '''!__init!__'''(''self'', '''conference_bridge''', '''file_name''')::
1989 1 Adrian Georgescu
  Creates a new {{{WaveFile}}} object.
1990 76 Ruud Klaver
  [[BR]]''conference_bridge'':[[BR]]
1991 76 Ruud Klaver
  The {{{ConferenceBridge}}} object that this object is to be connected to.
1992 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
1993 1 Adrian Georgescu
  The name of the {{{.wav}}} file to be played back as a string.
1994 1 Adrian Georgescu
  This should include the full path to the file.
1995 76 Ruud Klaver
 '''start'''(''self'')::
1996 76 Ruud Klaver
  Start playback of the {{{.wav}}} file.
1997 1 Adrian Georgescu
 '''stop'''(''self'')::
1998 1 Adrian Georgescu
  Stop playback of the file.
1999 15 Ruud Klaver
2000 15 Ruud Klaver
==== notifications ====
2001 15 Ruud Klaver
2002 15 Ruud Klaver
 '''WaveFileDidFinishPlaying'''::
2003 76 Ruud Klaver
  This notification will be sent whenever playing of the {{{.wav}}} has stopped.
2004 1 Adrian Georgescu
  After sending this event, the playback may be re-started.
2005 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
2006 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
2007 1 Adrian Georgescu
2008 1 Adrian Georgescu
=== RecordingWaveFile ===
2009 1 Adrian Georgescu
2010 77 Ruud Klaver
This is a simple object that allows recording audio from the conference bridge to a PCM {{{.wav}}} file.
2011 1 Adrian Georgescu
2012 77 Ruud Klaver
This object is associated with a {{{ConferenceBridge}}} instance and, once the {{{start()}}} method is called, connects to it and send records sound from it.
2013 77 Ruud Klaver
Note that that at least one slot on the conference bridge needs to be connected to the {{{RecordingWaveFile}}} slot in order to actually start recording.
2014 1 Adrian Georgescu
Recording to the file can be stopped either by calling the {{{stop()}}} method or by removing all references to the object.
2015 1 Adrian Georgescu
Once the {{{stop()}}} method has been called, the {{{start()}}} method may not be called again.
2016 77 Ruud Klaver
It is the application's responsibility to keep a reference to the {{{RecordingWaveFile}}} object for the duration of the recording, it will be stopped automatically when the reference count reaches 0.
2017 1 Adrian Georgescu
2018 1 Adrian Georgescu
==== attributes ====
2019 1 Adrian Georgescu
2020 77 Ruud Klaver
 '''conference_bridge'''::
2021 77 Ruud Klaver
  The {{{ConferenceBridge}}} object that was passed when the object got instantiated.
2022 77 Ruud Klaver
  This attribute is read-only.
2023 1 Adrian Georgescu
 '''file_name'''::
2024 1 Adrian Georgescu
  The name of the {{{.wav}}} file, as specified when the object was created.
2025 77 Ruud Klaver
 '''slot'''::
2026 77 Ruud Klaver
  A read-only property indicating the slot number at which this object is attached to the associated conference bridge.
2027 77 Ruud Klaver
  If the {{{RecordingWaveFile}}} is not active, this attribute will be {{{None}}}.
2028 77 Ruud Klaver
 '''volume'''::
2029 77 Ruud Klaver
  A writable property indicating the % of volume at which this object contributes audio to the conference bridge.
2030 77 Ruud Klaver
  By default this is set to 100.
2031 1 Adrian Georgescu
 '''is_active'''::
2032 1 Adrian Georgescu
  A boolean read-only attribute that indicates if the file is currently being written to.
2033 1 Adrian Georgescu
2034 1 Adrian Georgescu
==== methods ====
2035 1 Adrian Georgescu
2036 77 Ruud Klaver
 '''!__init!__'''(''self'', '''conference_bridge''', '''file_name''')::
2037 1 Adrian Georgescu
  Creates a new {{{RecordingWaveFile}}} object.
2038 77 Ruud Klaver
  [[BR]]''conference_bridge'':[[BR]]
2039 77 Ruud Klaver
  The {{{ConferenceBridge}}} object that this object is to be connected to.
2040 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
2041 1 Adrian Georgescu
  The name of the {{{.wav}}} file to record to as a string.
2042 1 Adrian Georgescu
  This should include the full path to the file.
2043 1 Adrian Georgescu
 '''start'''(''self'')::
2044 1 Adrian Georgescu
  Start recording the sound on the conference bridge to the {{{.wav}}} file.
2045 1 Adrian Georgescu
 '''stop'''(''self'')::
2046 1 Adrian Georgescu
  Stop recording to the file.