SipCoreApiDocumentation

Version 92 (Luci Stanescu, 03/24/2010 10:06 pm)

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