Project

General

Profile

SipCoreApiDocumentation » History » Version 101

Adrian Georgescu, 03/31/2010 10:13 AM

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