Project

General

Profile

SipCoreApiDocumentation » History » Version 18

Adrian Georgescu, 02/23/2009 08:13 PM

1 12 Adrian Georgescu
= SIP core API =
2 1 Adrian Georgescu
3 9 Adrian Georgescu
[[TOC(WikiStart, Sip*, 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 1 Adrian Georgescu
{{{sipsimple}}} is a Python package, the core of which wrapps the PJSIP C library, which handles SIP signaling and audio media for the SIP SIMPLE client.
9
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
== PJSIP C Library ==
29
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
The latter also includes an abstraction layer for the soundcard.
38
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
> The soundcard also has its own C thread.
54
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
The SIP core part of the {{{sipsimple}}} Python package is subdivided into three modules:
62
 '''sipimple.!__init!__'''::
63
  The the top-level module for the package which just defines the module version and the objects that should be imported when the package user performs {{{import * from sipsimple}}}.
64
 '''sipsimple.engine'''::
65
  Python module that contains the {{{Engine}}} singleton class, which manages the thread that constantly polls the PJSIP library, i.e. the PJSIP worker thread.
66
  For the applications that use the core of {{{sipsimple}}}, the {{{Engine}}} object forms the main entry point.
67
 '''sipsimple.core'''::
68
  This is the Python C extension module ultimately compiled from the Cython file and PJSIP static libraries.
69
  It contains these types of classes:
70
   * The {{{PJSIPUA}}} class, which can only be instanced once, and is this case is only instanced once by the {{{Engine}}} object.
71
     In this way the {{{Engine}}} singleton class acts as a wrapper to the one {{{PJSIPUA}}} instance.
72
     The {{{PJSIPUA}}} class represents the SIP endpoint and manages the initialization and destruction of all the PJSIP libraries.
73
     It also provides a number of methods.
74
     The application however should never call these methods directly on the {{{PJSIPUA}}} object, rather it should call them on the {{{Engine}}} wrapper object.
75
     This object handles everything that for one reason or another cannot or should not be handled from Cython.
76
   * The classes that represent the main SIP primitives to be used by the application.
77
     The application can instantiate these classes once the {{{Engine}}} class has been instantiated and the PJSIP worker thread has been started.
78
     All of these classes represent a state machine.
79
     * {{{Registration}}}
80
     * {{{Publication}}}
81
     * {{{Subscription}}}
82
     * {{{Invitation}}}
83
   * Several helper classes, which represent some structured collection of data to be passed as parameter to methods of the SIP primitive classes and to parameters of notifications.
84
     * {{{SIPURI}}}
85
     * {{{Credentials}}}
86
     * {{{Route}}}
87
   * A number of SDP manipulation classes, which directly wrap the PJSIP structures representing either the parsed or to be generated SDP.
88
     {{{SDPSession}}} objects may contain references to the other classes and are passed as arguments to methods of a {{{Invitiation}}} object or notifications sent by it.
89
     * {{{SDPSession}}}
90
     * {{{SDPMedia}}}
91
     * {{{SDPConnection}}}
92
     * {{{SDPAttribute}}}
93
   * Two classes related to transport of media traffic and audio traffic specifically, built on PJMEDIA.
94
     These classes can be instantiated independently from the other classes in order to keep signaling and media separate.
95
     * {{{RTPTransport}}}
96
     * {{{AudioTransport}}}
97
   * Two classes related to {{{.wav}}} files, one for playback and one for recording.
98
     * {{{WaveFile}}}
99
     * {{{RecordingWaveFile}}}
100
   * Two exception classes, the second being a subclass of the first.
101
     * {{{SIPCoreError}}}
102
     * {{{PJSIPError}}}
103
   * Classes used internally within the {{{core}}} module, e.g. to wrap a particular PJSIP library.
104
     These classes are not exposed through the {{{__init__}}} module and should never be used by the application
105
106
These classes (except the ones internal to the {{{core}}} module) are illustrated in the following diagram:
107
108
[[Image(sipsimple-core-classes.png, nolink)]]
109
110 11 Adrian Georgescu
== Integration ==
111 1 Adrian Georgescu
112
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.
113
These modules should be present on the system before the core can be used.
114
An application that uses the SIP core must use the notification system provided by the {{{application}}} module in order to receive notifications from it.
115
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.
116
This means that any call to instance an object from this class will result in the same object.
117
As an example, this bit of code will create an observer for logging messages only:
118
119
{{{
120
from zope.interface import implements
121
from application.notification import NotificationCenter, IObserver
122
123
class SCEngineLogObserver(object):
124
    implements(IObserver)
125
126
    def handle_notification(self, notification):
127
        print "%(timestamp)s (%(level)d) %(sender)14s: %(message)s" % notification.data.__dict__
128
129
notification_center = NotificationCenter()
130
log_observer = EngineLogObserver()
131
notification_center.add_observer(self, name="SCEngineLog")
132
}}}
133
134
Each notification object has three attributes:
135
 '''sender'''::
136
  The object that sent the notification.
137
  For generic notifications the sender will be the {{{Engine}}} instance, otherwise the relevant object.
138
 '''name'''::
139
  The name describing the notification.
140
  All messages will be described in this document and start with the prefix "SC", for SIP core.
141
 '''data'''::
142
  An instance of {{{application.notification.NotificationData}}} or a subclass of it.
143
  The attributes of this object provide additional data about the notification.
144
  Notifications described in this document will also have the data attributes described.
145
146
Besides setting up the notification observers, the application should import the relevant objects from the core by issuing the {{{from sipsimple import *}}} statement.
147
It can then instance the {{{Engine}}} class, which is also a singleton, and start the PJSIP worker thread by calling {{{Engine.start()}}}, optionally providing a number of initialization options.
148
Most of these options can later be changed at runtime, by setting attributes of the same name on the {{{Engine}}} object.
149
The application may then instance one of the SIP primitive classes and perform operations on it.
150
151
When starting the {{{Engine}}} class, the application can pass a number of keyword arguments that influence the behaviour of the SIP endpoint.
152
For example, the SIP network ports may be set through the {{{local_udp_port}}}, {{{local_tcp_port}}} and {{{local_tls_port}}} arguments.
153
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.
154
155
The methods called on the SIP primitive objects and the {{{Engine}}} object (proxied to the {{{PJSIPUA}}} instance) may be called from any thread.
156
They will return immediately and any delayed result will be returned later using a notification.
157
If there is an error in processing the request, an instance of {{{SIPCoreError}}}, or its subclass {{{PJSIPError}}} will be raised.
158
The former will be raised whenever an error occurs inside the core, the latter whenever an underlying PJSIP function returns an error.
159
The {{{PJSIPError}}} object also contains a status attribute, which is the PJSIP errno as an integer.
160
161
As a very basic example, one can REGISTER for a sip account by typing the following lines on a Python console:
162
{{{
163
from sipsimple import *
164
e = Engine()
165
e.start()
166
cred = Credentials(SIPURI(user="alice", host="example.com"), "password")
167
reg = Registration(cred)
168
reg.register()
169
}}}
170
Note that in this example no observer for notifications from this {{{Registration}}} object are registered, so the result of the operation cannot be seen.
171
172
== Components ==
173
174
=== Engine ===
175
176
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.
177
Once the {{{start()}}} method is called, it instantiates the {{{core.PJSIPUA}}} object and will proxy attribute and methods from it to the application.
178
179
==== attributes ====
180
181
 '''default_start_options''' (class attribute)::
182
  This dictionary is a class attribute that describes the default values for the initialization options passed as keyword arguments to the {{{start()}}} method.
183
  Consult this method for documentation of the contents.
184
185
==== methods ====
186
187
 '''!__init!__'''(''self'')::
188
  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.
189
 '''start'''(''self'', '''**kwargs''')::
190
  Initialize all PJSIP libraries based on the keyword parameters provited and start the PJSIP worker thread.
191
  If this fails an appropriate exception is raised.
192
  After the {{{Engine}}} has been started successfully, it can never be started again after being stopped.
193
  The keyword arguments will be discussed here.
194
  Many of these values are also readable as (proxied) attributes on the Engine once the {{{start()}}} method has been called.
195
  Many of them can also be set at runtime, either by modifying the attribute or by calling a particular method.
196
  This will also be documented for each argument in the following list of options.
197
  [[BR]]''auto_sound'':[[BR]]
198
  A boolean indicating if PJSIP should automatically select and enable a soundcard to use for for recording and playing back sound.
199
  If this is set to {{{False}}} the application will have to select a sound device manually through either the {{{set_sound_devices}}} or the {{{auto_set_sound_devices}}} method.
200
  This option is not accessible as an attribute on the object, as it is transitory.
201
  [[BR]]''local_ip'': (Default: {{{None}}})[[BR]]
202
  IP address of a local interface to bind to.
203
  If this is {{{None}}} on start, the {{{Engine}}} will try to determine the default outgoing interface and bind to it.
204
  Setting this to {{{0.0.0.0}}} will cause PJSIP to listen for traffic on any interface, but this is not recommended.
205
  As an attribute, this value is read-only.
206
  [[BR]]''local_udp_port'': (Default: {{{0}}})[[BR]]
207
  The local UDP port to listen on for UDP datagrams.
208
  If this is 0, a random port will be chosen.
209
  If it is {{{None}}}, the UDP transport is disabled, both for incoming and outgoing traffic.
210
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_udp_port()}}} method.
211
  [[BR]]''local_tcp_port'': (Default: {{{0}}})[[BR]]
212
  The local TCP port to listen on for new TCP connections.
213
  If this is 0, a random port will be chosen.
214
  If it is {{{None}}}, the TCP transport is disabled, both for incoming and outgoing traffic.
215
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_tcp_port()}}} method.
216
  [[BR]]''local_tls_port'': (Default: {{{0}}})[[BR]]
217
  The local TCP port to listen on for new TLS over TCP connections.
218
  If this is 0, a random port will be chosen.
219
  If it is {{{None}}}, the TLS transport is disabled, both for incoming and outgoing traffic.
220
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_tls_port()}}} method.
221
  [[BR]]''tls_verify_server'': (Default: {{{False}}})[[BR]]
222
  This boolean indicates whether PJSIP should verify the certificate of the server against the local CA list when making an outgoing TLS connection.
223
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_verify_server()}}} method, as internally the TLS transport needs to be restarted for this operation.
224
  [[BR]]''tls_ca_file'': (Default: {{{None}}})[[BR]]
225
  This string indicates the location of the file containing the local list of CA certificates, to be used for TLS connections.
226
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_tls_ca_file()}}} method, as internally the TLS transport needs to be restarted for this operation.
227
  [[BR]]''ec_tail_length'': (Default: {{{50}}})[[BR]]
228
  Echo cancellation tail length in milliseconds.
229
  A longer value should provide better echo cancellation but incurs more processing cost.
230
  Setting this to 0 will disable echo cancellation.
231
  As an attribute, this value is read-only, but it can be set as an argument to either the {{{set_sound_devices}}} or the {{{auto_set_sound_devices}}} method.
232
  [[BR]]''user_agent'': (Default: {{{"ag-projects/sipclient-%version-pjsip-%pjsip-version"}}})[[BR]]
233
  This value indicates what should be set in the {{{User-Agent}}} header, which is included in each request or response sent.
234
  It can be read and set directly as an attribute at runtime.
235
  [[BR]]''log_level'': (Default: 5)[[BR]]
236
  This integer dictates the maximum log level that may be reported to the application by PJSIP through the {{{SCEngineLog}}} notification.
237
  By default the maximum amount of logging information is reported.
238
  This value can be read and set directly as an attribute at runtime.
239
  [[BR]]''trace_sip'': (Default: {{{False}}})[[BR]]
240
  This boolean indicates if the SIP core should send the application SIP messages as seen on the wire through the {{{SCEngineSIPTrace}}} notification.
241
  It can be read and set directly as an attribute at runtime.
242
  [[BR]]''sample_rate'': (Default: {{{32}}})[[BR]]
243
  The sample rate in kHz at which the sound card should operate.
244
  Higher values allow some codecs (such as speex) to achieve better quality but will incur higher processing cost, particularly in combination with echo cancellation.
245
  This parameter should be either 8, 16 or 32.
246
  The corresponding attribute of this value is read-only.
247
  [[BR]]''playback_dtmf'': (Default: {{{True}}})[[BR]]
248
  If this boolean is set to {{{True}}}, both incoming and outgoing DTMF signals have their corresponding audio tones played back on the sound card.
249
  This value can be read and set directly as an attribute at runtime.
250
  [[BR]]''rtp_port_range'': (Default: (40000, 40100))[[BR]]
251
  This tuple of two ints indicates the range to select UDP ports from when creating a new {{{RTPTransport}}} object, which is used to transport media.
252
  It can be read and set directly as an attribute at runtime, but the ports of previously created {{{RTPTransport}}} objects remain unaffected.
253
  [[BR]]''codecs'': (Default: {{{["speex", "g711", "ilbc", "gsm", "g722"]}}})[[BR]]
254
  This list specifies the codecs to use for audio sessions and their preferred order.
255
  It can be read and set directly as an attribute at runtime.
256
  [[BR]]''events'': (Default: <some sensible events>)[[BR]]
257
  PJSIP needs a mapping between SIP SIMPLE event packages and content types.
258
  This dictionary provides some default packages and their event types.
259
  As an attribute, this value is read-only, but it can be changed at runtime using the {{{set_local_tls_port()}}} method.
260
 '''start'''(''self'', '''auto_sound'''={{{True}}})::
261
  Initialize all PJSIP libraries based on parameters of the {{{init_options}}} attribute and start the PJSIP worker thread.
262
  If this fails an appropriate exception is raised.
263
  [[BR]]''auto_sound'':[[BR]]
264
  A boolean indicating if PJSIP should automatically select and enable a soundcard to use for for recording and playing back sound.
265
  If this is set to {{{False}}} the application will have to select a sound device manually through either the {{{set_sound_devices}}} or the {{{auto_set_sound_devices}}} method.
266
 '''stop'''(''self'')::
267
  Stop the PJSIP worker thread and unload all PJSIP libraries.
268
  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}}}.
269
  Also note that, once stopped the {{{Engine}}} cannot be started again.
270
  This method is automatically called when the Python interpreter exits.
271
272
==== proxied attributes ====
273
274
Besides all the proxied attributes described for the {{{__init__}}} method above, two other attributes are provided once the {{{Engine}}} has been started.
275
276
 '''playback_devices'''::
277
  This read-only attribute is a list of audio playback devices that can be used.
278
  The list contains {{{PJMEDIASoundDevice}}} objects, which only have a {{{name}}} attribute to distinguish them.
279
  These objects can be passed as arguments to the {{{set_sound_devices}}} method.
280
 '''recording_devices'''::
281
  Like the {{{playback_devices}}} attribute, but for recording devices.
282
283
> These should be passable on start() as well to support persistent storing of soundcard preferences.
284
285
==== proxied methods ====
286
287
 '''add_event'''(''self'', '''event''', '''accept_types''')::
288
  Couple a certain event package to a list of content types.
289
  Once added it cannot be removed or modified.
290
 '''set_sound_devices'''(''self'', '''playback_device''', '''recording_device''', '''tail_length'''=50)::
291
  Set and open the playback and recording device, using the specified echo cancellation tail length in milliseconds.
292
  A {{{tail_length}}} of 0 disables echo cancellation.
293
  The device attributes need to be {{{PJMEDIASoundDevice}}} objects and should be obtained from the {{{playback_devices}}} and {{{recording_devices}}} attributes respectively.
294
  If sound devices were already opened these will be closed first.
295
 '''auto_set_sound_devices'''(''self'', '''tail_length'''=50)::
296
  Automatically select and open sound devices using the specified echo cancellation.
297
 '''connect_audio_transport'''(''self'', '''transport''')::
298
  Connect a started audio transport, in the form of a {{{AudioTransport}}} object, to the recording and playback audio devices and other connected audio transports.
299
  This means that when more than one audio stream is connected they will form a conference.
300
 '''disconnect_audio_transport'''(''self'', '''transport''')::
301
  Disconnect a previously connected audio transport, in the form of a {{{AudioTransport}}} object.
302
  Stopped audio streams are disconnected automatically.
303
 '''detect_nat_type'''(''self'', '''stun_server_address''', '''stun_server_port'''=3478)::
304
  Will start a series of STUN requests which detect the type of NAT this host is behind.
305
  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.
306
  When the type of NAT is detected, this will be reported back to the application by means of a {{{SCEngineDetectedNATType}}} notification.
307
 '''set_local_udp_port'''(''self'', '''value''')::
308
  Update the {{{local_udp_port}}} attribute to the newly specified value.
309
 '''set_local_tcp_port'''(''self'', '''value''')::
310
  Update the {{{local_tcp_port}}} attribute to the newly specified value.
311
 '''set_local_tls_port'''(''self'', '''value''')::
312
  Update the {{{local_tls_port}}} attribute to the newly specified value.
313
 '''set_tls_verify_server'''(''self'', '''value''')::
314
  Update the {{{tls_verify_server}}} attribute to the newly specified value.
315
 '''set_tls_ca_file'''(''self'', '''value''')::
316
  Update the {{{tls_ca_file}}} attribute to the newly specified value.
317
 '''parse_sip_uri(''self'', '''uri_string''')::
318
  Will parse the provided SIP URI string using the PJSIP parsing capabilities and return a {{{SIPURI}}} object, or raise an exception if there was an error parsing the URI.
319
320
==== notifications ====
321
322 16 Ruud Klaver
Notifications sent by the {{{Engine}}} are notifications that are related to the {{{Engine}}} itself or unrelated to any SIP primitive object.
323 1 Adrian Georgescu
They are described here including the data attributes that is included with them.
324
325 16 Ruud Klaver
 '''SCEngineWillStart'''::
326
  This notification is sent when the {{{Engine}}} is about to start.
327
  [[BR]]''timestamp'':[[BR]]
328
  A {{{datetime.datetime}}} object indicating when the notification was sent.
329
 '''SCEngineDidStart'''::
330
  This notification is sent when the {{{Engine}}} is has just been started.
331
  [[BR]]''timestamp'':[[BR]]
332
  A {{{datetime.datetime}}} object indicating when the notification was sent.
333
 '''SCEngineDidFail'''::
334
  This notification is sent whenever the {{{Engine}}} has failed fatally and either cannot start or is about to stop.
335
  It is not recommended to call any methods on the {{{Engine}}} at this point.
336
  [[BR]]''timestamp'':[[BR]]
337
  A {{{datetime.datetime}}} object indicating when the notification was sent.
338
 '''SCEngineWillEnd'''::
339
  This notification is sent when the {{{Engine}}} is about to stop because the application called the {{{stop()}}} method.
340
  Methods on the {{{Engine}}} can be called at this point, but anything that has a delayed result will probably not return any notification.
341
  [[BR]]''timestamp'':[[BR]]
342
  A {{{datetime.datetime}}} object indicating when the notification was sent.
343
 '''SCEngineDidEnd'''::
344
  This notification is sent when the {{{Engine}}} was running and is now stopped, either because of failure or because the application requested it.
345
  [[BR]]''timestamp'':[[BR]]
346
  A {{{datetime.datetime}}} object indicating when the notification was sent.
347 1 Adrian Georgescu
 '''SCEngineLog'''::
348
  This notification is a wrapper for PJSIP logging messages.
349
  It can be used by the application to output PJSIP logging to somewhere meaningful, possibly doing filtering based on log level.
350
  [[BR]]''timestamp'':[[BR]]
351
  A {{{datetime.datetime}}} object representing the time when the log message was output by PJSIP.
352
  [[BR]]''sender'':[[BR]]
353
  The PJSIP module that originated this log message.
354
  [[BR]]''level'':[[BR]]
355
  The logging level of the message as an integer.
356
  Currently this is 1 through 5, 1 being the most critical.
357
  [[BR]]''message'':[[BR]]
358
  The actual log message.
359
 '''SCEngineSIPTrace'''::
360
  Will be sent only when the {{{do_siptrace}}} attribute of the {{{Engine}}} instance is set to {{{True}}}.
361
  The notification data attributes will contain the SIP messages as they are sent and received on the wire.
362
  [[BR]]''timestamp'':[[BR]]
363
  A {{{datetime.datetime}}} object indicating when the notification was sent.
364
  [[BR]]''received'':[[BR]]
365
  A boolean indicating if this message was sent from or received by PJSIP (i.e. the direction of the message).
366
  [[BR]]''source_ip'':[[BR]]
367
  The source IP address as a string.
368
  [[BR]]''source_port'':[[BR]]
369
  The source port of the message as an integer.
370
  [[BR]]''destination_ip'':[[BR]]
371
  The destination IP address as a string.
372
  [[BR]]''source_port'':[[BR]]
373
  The source port of the message as an integer.
374
  [[BR]]''data'':[[BR]]
375
  The contents of the message as a string.
376
377
> For received message the destination_ip and for sent messages the source_ip may not be reliable.
378
379
 '''SCEngineGotMessage'''::
380
  This notification is sent when there is an incoming {{{MESSAGE}}} request.
381
  Since this is a one-shot occurrence, it is not modeled as an object.
382
  [[BR]]''timestamp'':[[BR]]
383
  A {{{datetime.datetime}}} object indicating when the notification was sent.
384
  [[BR]]''to_uri'':[[BR]]
385
  The contents of the {{{To:}}} header of the received {{{MESSAGE}}} request represented as a {{{SIPURI}}} object.
386
  [[BR]]''from_uri'':[[BR]]
387
  The contents of the {{{From:}}} header of the received {{{MESSAGE}}} request represented as a {{{SIPURI}}} object.
388
  [[BR]]''content_type'':[[BR]]
389
  The first part of the {{{Content-Type:}}} header of the received {{{MESSAGE}}} request (before the {{{/}}}).
390
  [[BR]]''content_subtype'':[[BR]]
391
  The second part of the {{{Content-Type:}}} header of the received {{{MESSAGE}}} request (after the {{{/}}}).
392
  [[BR]]''body'':[[BR]]
393
  The body of the {{{MESSAGE}}} request.
394
395
> content_type and content_subtype should be combined in a single argument, also in other places where this occurs.
396
397
 '''SCEngineGotMessageResponse'''::
398
  When sending a {{{MESSAGE}}} through the {{{send_message}}} function, this notification will be sent whenever there is a final response to the sent {{{MESSAGE}}} request (which may be an internally generated timeout).
399
  [[BR]]''timestamp'':[[BR]]
400
  A {{{datetime.datetime}}} object indicating when the notification was sent.
401
  [[BR]]''to_uri'':[[BR]]
402
  The original {{{to_uri}}} parameter used when calling the {{{send_message}}} function.
403
  [[BR]]''code'':[[BR]]
404
  The status code of the response as integer.
405
  [[BR]]''reason'':[[BR]]
406
  The reason text of the response.
407
 '''SCEngineDetectedNATType'''::
408
  This notification is sent some time after the application request the NAT type this host behind to be detected using a STUN server.
409
  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.
410
  [[BR]]''timestamp'':[[BR]]
411
  A {{{datetime.datetime}}} object indicating when the notification was sent.
412
  [[BR]]''succeeded'':[[BR]]
413
  A boolean indicating if the NAT detection succeeded.
414
  [[BR]]''nat_type'':[[BR]]
415
  A string describing the type of NAT found.
416
  This value is only present if NAT detection succeeded.
417
  [[BR]]''error'':[[BR]]
418
  A string indicating the error that occurred while attempting to detect the type of NAT.
419
  This value only present if NAT detection did not succeed.
420
 '''SCEngineGotException'''::
421 16 Ruud Klaver
  This notification is sent whenever there is an unexpected exception within the PJSIP working thread.
422
  The application should show the traceback to the user somehow.
423
  An exception need not be fatal, but if it is it will be followed by a '''SCEngineDidFail''' notification.
424 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
425
  A {{{datetime.datetime}}} object indicating when the notification was sent.
426
  [[BR]]''traceback'':[[BR]]
427
  A string containing the traceback of the exception.
428
  In general this should be printed on the console.
429
430
=== send_message ===
431
432
> In the future, this function will probably be implemented as a class or as a method of PJSIPUA.
433
434
The only function of the API is {{{send_message}}}, which sends a {{{MESSAGE}}} request containing a body to the specified SIP URI.
435
As described above, a {{{message_response}}} is generated when the final response is received.
436
Until the final response is received it is not allowed to send a new {{{MESSAGE}}} request to the {{{to_uri}}} used, a {{{SIPCoreError}}} exception will be thrown if the application tries this.
437
It has the following format and arguments:
438
{{{
439
send_message(credentials, to_uri, content_type, content_subtype, body, route = None)
440
}}}
441
 '''credentials'''::
442
  Credentials to be used if authentication is needed at the proxy in the form of a {{{Credentials}}} object.
443
  This object also contains the From URI.
444
 '''to_uri'''::
445
  The SIP URI to send the {{{MESSAGE}}} request to in the form of a {{{SIPURI}}} object.
446
 '''content_type'''::
447
  The first part of the {{{Content-Type:}}} header (before the {{{/}}}).
448
 '''content_subtype'''::
449
  The first part of the {{{Content-Type:}}} header (before the {{{/}}}).
450
 '''body'''::
451
  The body of the {{{MESSAGE}}} request that is to be sent.
452
 '''route'''::
453
  This represents the first host to send the request to in the form of a {{{Route}}} object.
454
455
> The exception thrown when the application tries to send a MESSAGE too fast should be customized.
456
> In this way the application may keep a queue of MESSAGE requests and send the next one when the last one was answered.
457
458
=== SIPURI ===
459
460
This is a helper object for representing a SIP URI.
461
This object needs to be used whenever a SIP URI should be specified to the SIP core.
462
It supports comparison to other {{{SIPURI}}} objects using the == and != expressions.
463
As all of its attributes are set by the {{{__init__}}} method, the individual attributes will not be documented here.
464
465
==== methods ====
466
467
 '''!__init!__'''(''self'', '''host''', '''user'''={{{None}}}, '''port'''={{{None}}}, '''display'''={{{None}}}, '''secure'''={{{False}}}, '''parameters'''=dict(), '''headers'''=dict())::
468
  Creates the SIPURI object with the specified parameters as attributes.
469
  Each of these attributes can be accessed and changed on the object once instanced.
470
  {{{host}}} is the only mandatory attribute.
471
  [[BR]]''host'':[[BR]]
472
  The host part of the SIP URI as a string.
473
  [[BR]]''user'':[[BR]]
474
  The username part of the SIP URI as a string, or None if not set.
475
  [[BR]]''port'':[[BR]]
476
  The port part of the SIP URI as an int, or None or 0 if not set.
477
  [[BR]]''display'':[[BR]]
478
  The optional display name of the SIP URI as a string, or None if not set.
479
  [[BR]]''secure'':[[BR]]
480
  A boolean indicating whether this is a SIP or SIPS URI, the latter being indicated by a value of {{{True}}}.
481
  [[BR]]''parameters'':[[BR]]
482
  The URI parameters. represented by a dictionary.
483
  [[BR]]''headers'':[[BR]]
484
  The URI headers, represented by a dictionary.
485
 '''!__str!__'''(''self'')::
486
  The special Python method to represent this object as a string, the output is the properly formatted SIP URI.
487
 '''copy'''(''self'')::
488
  Returns a copy of the {{{SIPURI}}} object.
489
490
=== Credentials ===
491
492
This object represents authentication credentials for a particular SIP account.
493
These should be included whenever creating a SIP primitive object that originates SIP requests.
494
As with the {{{SIPURI}}} object, the attributes of this object are the same as the arguments to the {{{__init__}}} method.
495
496
==== methods ====
497
498
 '''!__init!__'''(''self'', '''uri''', '''password'''={{{None}}}, '''token'''={{{None}}})::
499
  Creates the Credentials object with the specified parameters as attributes.
500
  Each of these attributes can be accessed and changed on the object once instanced.
501
  [[BR]]''uri'':[[BR]]
502
  A {{{SIPURI}}} object representing the account for which these are the credentials.
503
  [[BR]]''password'':[[BR]]
504
  The password for this SIP account as a string.
505
  If a password is not needed, for example when sending SIP messages without a proxy, this can be {{{None}}}.
506
  [[BR]]''token'':[[BR]]
507
  A string token which will be added as the username part of the {{{Contact}}} header.
508
  This token will allow matching of incoming messages to a particular SIP account by the application.
509
  Note that the SIP core itself does not have an object representing a SIP account, this should be the responsibility of the application.
510
  If {{{None}}} is specified, the {{{Credentials}}} object will generate a random string as token, which will be accessible as object attribute.
511
 '''copy'''(''self'')::
512
  Returns a copy of the {{{Credentials}}} object.
513
514
=== Route ===
515
516
This class provides a means for the application using the SIP core to set the destination host for a particular request, i.e. the outbound proxy.
517
This will be included in the {{{Route}}} header if the request.
518
If a {{{Route}}} object is specified, the internal DNS lookup mechanism of PJSIP is bypassed.
519
This object also serves as the mechanism to choose the transport to be used.
520
As with the {{{SIPURI}}} object, the attributes of this object are the same as the arguments to the {{{__init__}}} method.
521
522
> The internal lookup mechanism of PJSIP should be disabled completely and passing Route objects will be mandatory.
523
> This enables a greater degree of control over the lookup procedure and allows requests destined for foreign domains to be routed through the local proxy.
524
525
==== methods ====
526
527
 '''!__init!__'''(''self'', '''host''', '''port'''=5060, '''transport'''={{{None}}})::
528
  Creates the Route object with the specified parameters as attributes.
529
  Each of these attributes can be accessed on the object once instanced.
530
  [[BR]]''host'':[[BR]]
531
  The host that the request in question should be sent to as a string
532
  Typically this should be a IP address, although this is not explicitly checked.
533
  [[BR]]''port'':[[BR]]
534
  The UDP port to send the requests to, represented by an int.
535
  [[BR]]''transport'':[[BR]]
536
  The transport to use, this can be a string saying either "udp", "tcp" or "tls" (case insensitive), depending on what transports are enabled on the {{{PJSIPUA}}} object.
537
 '''copy'''(''self'')::
538
  Returns a copy of the {{{Route}}} object.
539
540
=== Registration ===
541
542
A {{{Registration}}} object represents a SIP endpoint's registration for a particular SIP account using the {{{REGISTER}}} method at its SIP registrar.
543
In effect, the SIP endpoint can send a {{{REGISTER}}} to the registrar to indicate that it is a valid endpoint for the specified SIP account.
544
After the {{{REGISTER}}} request is successfully received, the SIP proxy will be able to contact the SIP endpoint whenever there is an {{{INVITE}}} or other relevant request sent to the SIP account.
545
In short, unless a SIP endpoint is registered, it cannot be contacted.
546
Internally it uses a state machine to represent the registration process.
547
The states of this state machine can be seen in the following diagram:
548
549 2 Adrian Georgescu
[[Image(sipsimple-registration-state-machine.png, nolink)]]
550 1 Adrian Georgescu
551
State changes are triggered by the following events:
552
 1. The initial state.
553
 2. User requests in the form of the {{{register()}}} and {{{unregister()}}} methods.
554
 3. A final response for a {{{REGISTER}}} is received from the network.
555
 4. The refresh timer expires.
556
The state machine of a {{{Registration}}} object has a queue, which means that for example when the object is in the {{{registering}}} state and the application calls the {{{unregister()}}} method, the object will unregister itself once a final response has been received for the registering {{{REGISTER}}}.
557
558
> The implementation of this object needs to be revised.
559
560
==== attributes ====
561
562
 '''state'''::
563
  Indicates which state the internal state machine is in.
564
  This is one of {{{unregistered}}}, {{{registering}}}, {{{registered}}}, {{{unregistering}}}.
565
 '''credentials'''::
566
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object, including the SIP account for which we want to register.
567
  This attribute is set on object instantiation and is read-only.
568
 '''route'''::
569
  The outbound proxy to use in the form of a {{{Route}}} object.
570
  This attribute is set on object instantiation and is read-only.
571
 '''extra_headers'''::
572
  A dictionary of extra headers that should be added to any outgoing {{{REGISTER}}} request.
573
  This attribute is set on object instantiation and is read-only.
574
 '''expires'''::
575
  The amount of seconds to request the registration for, i.e. the value that should be put in the {{{Expires}}} header.
576
  This attribute is set on object instantiation and can be modified at runtime.
577
  A new value will be used during the next refreshing {{{REGISTER}}}.
578
 '''expires_received'''::
579
  The amount of seconds the last successful {{{REGISTER}}} is valid for.
580
  This value is read-only.
581
582
==== methods ====
583
584
 '''!__init!__'''(''self'', '''credentials''', '''route'''={{{None}}}, '''expires'''=300, '''extra_headers'''=dict())::
585
  Creates a new {{{Registration}}} object.
586
  [[BR]]''credentials'':[[BR]]
587
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object, including the SIP account for which we want to register.
588
  [[BR]]''route'':[[BR]]
589
  The outbound proxy to use in the form of a {{{Route}}} object
590
  [[BR]]''expires'':[[BR]]
591
  The amount of seconds to request the registration for, i.e. the value that should be put in the {{{Expires}}} header.
592
  [[BR]]''extra_headers'':[[BR]]
593
  A dictionary of extra headers that should be added to any outgoing request.
594
 '''register'''(''self'')::
595
  Whenever the object is ready to send a {{{REGISTER}}} for the specified SIP account it will do so, moving the state machine into the {{{registering}}} state.
596
  If the {{{REGISTER}}} succeeds the state machines moves into the {{{registered}}} state and the object will automatically refresh the registration before it expires (again moving into the {{{registering}}} state).
597
  If it is unsuccessful the state machine reverts to the {{{unregistered}}} state.
598
 '''unregister'''(''self'')::
599
  If the object is registered it will send a {{{REGISTER}}} with an {{{Expires}}} header of 0, effectively unregistering the contact from the SIP account.
600
601
==== notifications ====
602
603
 '''SCRegistrationChangedState'''::
604
  This notification will be sent every time the internal state machine of a {{{Registeration}}} object changes state.
605
  [[BR]]''timestamp'':[[BR]]
606
  A {{{datetime.datetime}}} object indicating when the notification was sent.
607
  [[BR]]''state'':[[BR]]
608
  The new state the state machine moved into.
609
  [[BR]]''code'': (only on SIP response triggered state change)[[BR]]
610
  The status code of the response that caused the state change.
611
  This may be internally generated by PJSIP, e.g. on timeout.
612
  [[BR]]''reason'': (only on SIP response triggered state change)[[BR]]
613
  The status text of the response that caused the state change.
614
  This may be internally generated by PJSIP, e.g. on timeout.
615
  [[BR]]''contact_uri'': (only on successful registration)[[BR]]
616
  The {{{Contact}}} URI used to register as a string.
617
  [[BR]]''expires'': (only on successful registration)[[BR]]
618
  How many seconds until this registration expires.
619
  [[BR]]''contact_uri_list'': (only on successful registration)[[BR]]
620
  The full list of {{{Contact}}} URIs registered for this SIP account, including the one just performed by this object.
621
622
==== example code ====
623
624
This code shows how to make a {{{Registration}}} object for a particular SIP account and have it register.
625
626
{{{
627
accnt = SIPURI(user="username", host="domain.com")
628
creds = Credentials(accnt, "password")
629
reg = Registration(creds)
630
reg.register()
631
}}}
632
633
After executing this code, the application will have to wait until the {{{Registration}}} object sends the {{{SCRegistrationChangedState}}} notification, which includes the result of the requested operation.
634
635
=== Publication ===
636
637
Publication of SIP events is an Internet standard published at [http://tools.ietf.org/html/rfc3903 RFC 3903]. 
638
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.
639
640
A {{{Publication}}} object represents publishing some content for a particular SIP account and a particular event type at the SIP presence agent through a {{{PUBLISH}}} request.
641
The state machine of this object is very similar to that of the {{{Registration}}} object, as can be seen in the following diagram:
642
643 2 Adrian Georgescu
[[Image(sipsimple-publication-state-machine.png, nolink)]]
644 1 Adrian Georgescu
645
State changes are triggered by the following events:
646
 1. The initial state.
647
 2. User requests in the form of the {{{publish()}}} and {{{unpublish()}}} methods.
648
 3. A final response for a {{{PUBLISH}}} is received from the network.
649
 4. The refresh timer expires.
650
Like the {{{Registration}}} state machine, the {{{Publication}}} state machine is queued.
651
This means that the application may call either the {{{publish()}}} or {{{unpublish()}}} method at any point in the state machine.
652
The object will perform the requested action when ready.
653
When some content is published and the application wants to update the contents, it can directly call the {{{publish()}}} method with the new content.
654
655
> The implementation of this object needs to be revised.
656
657
> If this object is re-used after unpublication, the etag value is not reset by PJSIP.
658
> This needs to be fixed.
659
660
==== attributes ====
661
662
 '''state'''::
663
  Indicates which state the internal state machine is in.
664
  This is one of {{{unpublished}}}, {{{publishing}}}, {{{published}}}, {{{unpublishing}}}.
665
 '''credentials'''::
666
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object, including the SIP account for which we want to register.
667
  This attribute is set on object instantiation and is read-only.
668
 '''route'''::
669
  The outbound proxy to use in the form of a {{{Route}}} object.
670
  This attribute is set on object instantiation and is read-only.
671
 '''extra_headers'''::
672
  A dictionary of extra headers that should be added to any outgoing {{{PUBLISH}}} request.
673
  This attribute is set on object instantiation and is read-only.
674
 '''expires'''::
675
  The amount of seconds the contents of the {{{PUBLISH}}} are valid, i.e. the value that should be put in the {{{Expires}}} header.
676
  This attribute is set on object instantiation and can be modified at runtime.
677
  A new value will be used during the next refreshing {{{PUBLISH}}}.
678
679
==== methods ====
680
681
 '''!__init!__'''(''self'', '''credentials''', '''event''', '''route'''={{{None}}}, '''expires'''=300, '''extra_headers'''=dict())::
682
  Creates a new {{{Publication}}} object.
683
  [[BR]]''credentials'':[[BR]]
684
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object, including the SIP account that we want to publish the content for.
685
  [[BR]]''event'':[[BR]]
686
  The event package for which we want to publish content.
687
  [[BR]]''route'':[[BR]]
688
  The outbound proxy to use in the form of a {{{Route}}} object
689
  [[BR]]''expires'':[[BR]]
690
  The amount of seconds the contents of the {{{PUBLISH}}} are valid, i.e. the value that should be put in the {{{Expires}}} header.
691
  [[BR]]''extra_headers'':[[BR]]
692
  A dictionary of extra headers that should be added to any outgoing {{{PUBLISH}}} request.
693
 '''publish'''(''self'', '''content_type''', '''content_subtype''', '''body''')::
694
  Whenever the object is ready to send a {{{PUBLISH}}} for the specified SIP account it will do so, moving the state machine into the {{{publishing}}} state.
695
  If the {{{PUBLISH}}} succeeds the state machines moves into the {{{published}}} state and the object will automatically refresh the publication before it expires (again moving into the {{{publishing}}} state).
696
  If it is unsuccessful the state machine reverts to the {{{unregistered}}} state.
697
  [[BR]]''content_type'':[[BR]]
698
  The first part of the {{{Content-Type:}}} header of the {{{PUBLISH}}} request that is to be sent (before the {{{/}}}), indicating the type of content of the body.
699
  [[BR]]''content_subtype'':[[BR]]
700
  The second part of the {{{Content-Type:}}} header of the {{{PUBLISH}}} request that is to be sent (after the {{{/}}}), indicating the type of content of the body.
701
 '''unpublish'''(''self'')::
702
  If the object has some content published, it will send a {{{PUBLISH}}} with an {{{Expires}}} header of 0, effectively unpublishing the content for the specified SIP account.
703
704
==== notifications ====
705
706
 '''SCPublicationChangedState'''::
707
  This notification will be sent every time the internal state machine of a {{{Publication}}} object changes state.
708
  [[BR]]''timestamp'':[[BR]]
709
  A {{{datetime.datetime}}} object indicating when the notification was sent.
710
  [[BR]]''state'':[[BR]]
711
  The new state the state machine moved into.
712
  [[BR]]''code'': (only on SIP response triggered state change)[[BR]]
713
  The status code of the response that caused the state change.
714
  This may be internally generated by PJSIP, e.g. on timeout.
715
  [[BR]]''reason'': (only on SIP response triggered state change)[[BR]]
716
  The status text of the response that caused the state change.
717
  This may be internally generated by PJSIP, e.g. on timeout.
718
719
> On init the event package is not checked with known event packages, this is only used for {{{Subscription}}} objects.
720
> This could be done for the sake of consistency.
721
722
==== example code ====
723
724
This code shows how to make a {{{Publication}}} object for a particular SIP account and have it attempt to publish its presence.
725
726
{{{
727
accnt = SIPURI(user="username", host="domain.com")
728
creds = Credentials(accnt, "password")
729
pub = Publication(creds, "presence")
730
pub.publish("text", "plain", "hi!")
731
}}}
732
733
After executing this code, the application will have to wait until the {{{Publication}}} object sends the {{{SCPublicationChangedState}}} notification, which includes the result of the requested operation.
734
In this case the presence agent will most likely reply with "Unsupported media type", as the code tries to submit Content-Type which is not valid for the presence event package.
735
736
=== Subscription ===
737
738
Subscription and notifications for SIP events is an Internet standard published at [http://tools.ietf.org/html/rfc3856 RFC 3856].
739
740
This SIP primitive class represents a subscription to a specific event type of a particular SIP URI.
741
This means that the application should instance this class for each combination of event and SIP URI that it wishes to subscribe to.
742
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.
743
Whenever a {{{NOTIFY}}} is received, the application will receive the {{{Subcription_notify}}} event.
744
745
Internally a {{{Subscription}}} object has a state machine, which reflects the state of the subscription.
746
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}}}.
747
The last three states are directly copied from the contents of the {{{Subscription-State}}} header of the received {{{NOTIFY}}} request.
748
Also, the state can be an arbitrary string if the contents of the {{{Subscription-State}}} header are not one of the three above.
749
The state machine of the {{{Subscription}}} object is not queued, meaning that if an action is performed that is not allowed in the state the state machine is currently in, an exception will be raised.
750
751
> The implementation of this object needs to be revised.
752
753
==== attributes ====
754
755
 '''state'''::
756
  Indicates which state the internal state machine is in.
757
  See the previous section for a list of states the state machine can be in.
758
 '''credentials'''::
759
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
760
  The {{{SIPURI}}} object included in the {{{Credentials}}} object is used for the {{{From}}} header of the {{{SUBSCRIBE}}} request.
761
  This attribute is set on object instantiation and is read-only.
762
 '''to_uri'''::
763
  The SIP URI we want to subscribe to a particular event of represented as a {{{SIPURI}}} object.
764
  This attribute is set on object instantiation and is read-only.
765
 '''event'''::
766
  The event package to which we want to subscribe at the given SIP URI.
767
  This attribute is set on object instantiation and is read-only.
768
 '''route'''::
769
  The outbound proxy to use in the form of a {{{Route}}} object.
770
  This attribute is set on object instantiation and is read-only.
771
 '''expires'''::
772
  The expires value that was requested on object instantiation.
773
  This attribute is read-only.
774
 '''extra_headers'''::
775
  A dictionary of extra headers that should be added to any outgoing {{{SUBSCRIBE}}} request.
776
  This attribute is set on object instantiation and is read-only.
777
778
==== methods ====
779
780
 '''!__init!__'''(''self'', '''credentials''', '''to_uri''', '''event''', '''route'''={{{None}}}, '''expires'''=300, '''extra_headers'''=dict())::
781
  Creates a new {{{Subscription}}} object.
782
  [[BR]]''credentials'':[[BR]]
783
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
784
  The {{{SIPURI}}} object included in the {{{Credentials}}} object is used for the {{{From}}} header of the {{{SUBSCRIBE}}} request.
785
  [[BR]]''to_uri'':[[BR]]
786
  The SIP URI we want to subscribe to a particular event of represented as a {{{SIPURI}}} object.
787
  [[BR]]''event'':[[BR]]
788
  The event package to which we want to subscribe at the given SIP URI.
789
  [[BR]]''route'':[[BR]]
790
  The outbound proxy to use in the form of a {{{Route}}} object
791
  [[BR]]''expires'':[[BR]]
792
  The amount of seconds  the {{{SUBSCRIBE}}} is valid, i.e. the value that should be put in the {{{Expires}}} header.
793
  [[BR]]''extra_headers'':[[BR]]
794
  A dictionary of extra headers that should be added to any outgoing {{{SUBSCRIBE}}} request.
795
 '''subscribe'''(''self'')::
796
  This method activates the subscription and causes the object to send a {{{SUBSCRIBE}}} request to the relevant presence agent.
797
  It can only be used when the object is in the {{{TERMINATED}}} state.
798
 '''unsubscribe'''(''self'')::
799
  This method causes the object to send a {{{SUBSCRIBE}}} request with an {{{Expires}}} value of 0, effectively canceling the active subscription.
800
  It can be used when the object is not in the {{{TERMINATED}}} state.
801
802
==== notifications ====
803
804
 '''SCSubscriptionChangedState'''::
805
  This notification will be sent every time the internal state machine of a {{{Subscription}}} object changes state.
806
  [[BR]]''timestamp'':[[BR]]
807
  A {{{datetime.datetime}}} object indicating when the notification was sent.
808
  [[BR]]''state'':[[BR]]
809
  The new state the state machine moved into.
810
  [[BR]]''code'': (only on SIP response triggered state change)[[BR]]
811
  The status code of the response that caused the state change.
812
  This may be internally generated by PJSIP, e.g. on timeout.
813
  [[BR]]''reason'': (only on SIP response triggered state change)[[BR]]
814
  The status text of the response that caused the state change.
815
  This may be internally generated by PJSIP, e.g. on timeout.
816
 '''SCSubscriptionGotNotify'''::
817
  This notification will be sent when a {{{NOTIFY}}} is received that corresponds to a particular {{{Subscription}}} object.
818
  Note that this notification will not be sent when a {{{NOTIFY}}} with an empty body is received.
819
  [[BR]]''timestamp'':[[BR]]
820
  A {{{datetime.datetime}}} object indicating when the notification was sent.
821
  [[BR]]''content_type'':[[BR]]
822
  The first part of the {{{Content-Type:}}} header of the received {{{NOTIFY}}} request (before the {{{/}}}), indicating the type of the body.
823
  [[BR]]''content_subtype'':[[BR]]
824
  The second part of the {{{Content-Type:}}} header of the received {{{NOTIFY}}} request (after the {{{/}}}), indicating the type of the body.
825
  [[BR]]''body'':[[BR]]
826
  The body of the {{{NOTIFY}}} request.
827
828
==== example code ====
829
830
This code shows how to make a {{{Subscription}}} object that subscribes to the presence of another SIP account.
831
832
{{{
833
accnt = SIPURI(user="watcher", host="domain.com")
834
creds = Credentials(accnt, "password")
835
to_uri = SIPURI(user="watched", host="domain.com")
836
sub = Subscription(creds, to_uri, "presence")
837
sub.subscribe()
838
}}}
839
840
After executing this code, the application will have to wait until the {{{Subscription}}} object sends the {{{SCSubscriptionChangedState}}} notification, which includes the result of the requested operation.
841
Independently of this, the object sends a {{{SCSubscriptionGotNotify}}} notification anytime it receives a {{{NOTIFY}}} request for this subscription, as long as the subscription is active.
842
843
=== Invitation ===
844
845
The {{{Invitation}}} class represents an {{{INVITE}}} session, which governs a complete session of media exchange between two SIP endpoints from start to finish.
846
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.
847
The {{{Invitation}}} class represents both incoming and outgoing sessions.
848
849
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.
850
In order to represent re-{{{INVITE}}}s and user-requested disconnections, three more states have been added to this state machine.
851
The progression through this state machine is fairly linear and is dependent on whether this is an incoming or an outgoing session.
852
State changes are triggered either by incoming or by outgoing SIP requests and responses.
853
The states and the transitions between them are shown in the following diagram:
854
855
[[Image(sipsimple-core-invite-state-machine.png, nolink)]]
856
857
The state changes of this machine are triggered by the following:
858
 1. An {{{Invitation}}} object is newly created, either by the application for an outgoing session, or by the core for an incoming session.
859
 2. The application requested an outgoing session by calling the {{{send_invite()}}} method and and initial {{{INVITE}}} request is sent.
860
 3. A new incoming session is received by the core.
861
    The application should look out for state change to this state in order to be notified of new incoming sessions.
862
 4. A provisional response (1xx) is received from the remove party.
863
 5. A provisional response (1xx) is sent to the remote party, after the application called the {{{respond_to_invite_provisionally()}}} method.
864
 6. A positive final response (2xx) is received from the remote party.
865
 7. A positive final response (2xx) is sent to the remote party, after the application called the {{{accept_invite()}}} method.
866
 8. A positive final response (2xx) is sent or received, depending on the orientation of the session.
867
 9. An {{{ACK}}} is sent or received, depending on the orientation of the session.
868
    If the {{{ACK}}} is sent from the local to the remote party, it is initiated by PJSIP, not by a call from the application.
869
 10. The local party sent a re-{{{INVITE}}} to the remote party by calling the {{{send_reinvite()}}} method.
870
 11. The remote party has sent a final response to the re-{{{INVITE}}}.
871
 12. The remote party has sent a re-{{{INVITE}}}.
872
 13. The local party has responded to the re-{{{INVITE}}} by calling the {{{respond_to_reinvite()}}} method.
873
 14. The application requests that the session ends by calling the {{{disconnect()}}} method.
874
 15. A response is received from the remote party to whichever message was sent by the local party to end the session.
875
 16. A message is received from the remote party which ends the session.
876
877
The application is notified of a state change in either state machine through the {{{SCInvitationChangedState}}} notification, which has as data the current and previous states.
878
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.
879
The application should compare the previous and current states and perform the appropriate action.
880
881
An {{{Invitiation}}} object also emits the {{{SCInvitationGotSDPUpdate}}} notification, which indicates that SDP negotiation between the two parties has been completed.
882
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.
883
In the last case, the {{{Invitation}}} object will automatically include the current local SDP in the response.
884
885
==== attributes ====
886
887
 '''state'''::
888
  The state the {{{Invitation}}} state machine is currently in.
889
  See the diagram above for possible states.
890
  This attribute is read-only.
891
 '''is_outgoing'''::
892
  Boolean indicating if the original {{{INVITE}}} was outgoing, or incoming if set to {{{False}}}.
893
 '''credentials'''::
894
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
895
  If this {{{Invitation}}} object represents an incoming {{{INVITE}}} session this attribute will be {{{None}}}.
896
  This attribute is set on object instantiation and is read-only.
897
 '''caller_uri'''::
898
  The SIP URI of the caller represented by a {{{SIPURI}}} object.
899
  If this is in an outgoing {{{INVITE}}} session, the caller_uri is taken from the supplied {{{Credentials}}} object.
900
  Otherwise the URI is taken from the {{{From:}}} header of the initial {{{INVITE}}}.
901
  This attribute is set on object instantiation and is read-only.
902
 '''callee_uri'''::
903
  The SIP URI of the callee represented by a {{{SIPURI}}} object.
904
  If this is an outgoing {{{INVITE}}} session, this is the callee_uri from the !__init!__ method.
905
  Otherwise the URI is taken from the {{{To:}}} header of the initial {{{INVITE}}}.
906
  This attribute is set on object instantiation and is read-only.
907
 '''local_uri'''::
908
  The local SIP URI used in this session.
909
  If the original {{{INVITE}}} was incoming, this is the same as {{{callee_uri}}}, otherwise it will be the same as {{{caller_uri}}}.
910
 '''remote_uri'''::
911
  The SIP URI of the remote party in this session.
912
  If the original {{{INVITE}}} was incoming, this is the same as {{{caller_uri}}}, otherwise it will be the same as {{{callee_uri}}}.
913
 '''route'''::
914
  The outbound proxy that was requested to be used in the form of a {{{Route}}} object, including the desired transport.
915
  If this {{{Invitation}}} object represents an incoming {{{INVITE}}} session this attribute will always be {{{None}}}.
916
  This attribute is set on object instantiation and is read-only.
917 14 Ruud Klaver
 '''call_id'''::
918
  The call ID of the {{{INVITE}}} session as a read-only string.
919
  In the {{{NULL}}} and {{{DISCONNECTED}}} states, this attribute is {{{None}}}.
920 1 Adrian Georgescu
921
==== methods ====
922
923
 '''!__init!__'''(''self'', '''credentials''', '''callee_uri''', '''route'''={{{None}}})::
924
  Creates a new {{{Invitation}}} object for an outgoing session.
925
  [[BR]]''credentials'':[[BR]]
926
  The SIP credentials needed to authenticate at the SIP proxy in the form of a {{{Credentials}}} object.
927
  The {{{SIPURI}}} object included in the {{{Credentials}}} object is used for the {{{From}}} header of the {{{INVITE}}} request.
928
  [[BR]]''callee_uri'':[[BR]]
929
  The SIP URI we want to send the {{{INVITE}}} to, represented as a {{{SIPURI}}} object.
930
  [[BR]]''route'':[[BR]]
931
  The outbound proxy to use in the form of a {{{Route}}} object.
932
  This includes the desired transport to use.
933
 '''get_active_local_sdp'''(''self'')::
934
  Returns a new {{{SDPSession}}} object representing the currently active local SDP.
935
  If no SDP was negotiated yet, this returns {{{None}}}.
936
 '''get_active_remote_sdp'''(''self'')::
937
  Returns a new {{{SDPSession}}} object representing the currently active local SDP.
938
  If no SDP was negotiated yet, this returns {{{None}}}.
939
 '''get_offered_local_sdp'''(''self'')::
940
  Returns a new {{{SDPSession}}} object representing the currently proposed local SDP.
941
  If no local offered SDP has been set, this returns {{{None}}}.
942
 '''set_offered_local_sdp'''(''self'', '''local_sdp''')::
943
  Sets the offered local SDP, either for an initial {{{INVITE}}} or re-{{{INVITE}}}, or as an SDP answer in response to an initial {{{INVITE}}} or re-{{{INVITE}}}.
944
  [[BR]]''local_sdp'':[[BR]]
945
  The SDP to send as offer or answer to the remote party.
946
 '''get_offered_remote_sdp'''(''self'')::
947
  Returns a new {{{SDPSession}}} object representing the currently proposed remote SDP.
948
  If no remote SDP has been offered in the current state, this returns {{{None}}}.
949
 '''send_invite'''(''self'', '''extra_headers'''={{{None}}})::
950
  This tries to move the state machine into the {{{CALLING}}} state by sending the initial {{{INVITE}}} request.
951
  It may only be called from the {{{NULL}}} state on an outgoing {{{Invitation}}} object.
952
  [[BR]]''extra_headers'':[[BR]]
953
  Any extra headers that should be included in the {{{INVITE}}} request in the form of a dict.
954
 '''respond_to_invite_provisionally'''(''self'', '''response_code'''=180, '''extra_headers'''={{{None}}})::
955
  This tries to move the state machine into the {{{EARLY}}} state by sending a provisional response to the initial {{{INVITE}}}.
956
  It may only be called from the {{{INCOMING}}} state on an incoming {{{Invitation}}} object.
957
  [[BR]]''response_code'':[[BR]]
958
  The code of the provisional response to use as an int.
959
  This should be in the 1xx range.
960
  [[BR]]''extra_headers'':[[BR]]
961
  Any extra headers that should be included in the response in the form of a dict.
962
 '''accept_invite'''(''self'', '''extra_headers'''={{{None}}})::
963
  This tries to move the state machine into the {{{CONNECTING}}} state by sending a 200 OK response to the initial {{{INVITE}}}.
964
  It may only be called from the {{{INCOMING}}} or {{{EARLY}}} states on an incoming {{{Invitation}}} object.
965
  [[BR]]''extra_headers'':[[BR]]
966
  Any extra headers that should be included in the response in the form of a dict.
967
 '''disconnect'''(''self'', '''response_code'''=486, '''extra_headers'''={{{None}}})::
968
  This moves the {{{INVITE}}} state machine into the {{{DISCONNECTING}}} state by sending the necessary SIP message.
969
  When a response from the remote party is received, the state machine will go into the {{{DISCONNECTED}}} state.
970
  Depending on the current state, this could be a CANCEL or BYE request or a negative response.
971
  [[BR]]''response_code'':[[BR]]
972
  The code of the response to use as an int, if transmission of a response is needed.
973
  [[BR]]''extra_headers'':[[BR]]
974
  Any extra headers that should be included in the request or response in the form of a dict.
975
 '''respond_to_reinvite'''(''self'', '''response_code'''=180, '''extra_headers'''={{{None}}})::
976
  Respond to a received re-{{{INVITE}}} with a response that is either provisional (1xx), positive (2xx) or negative (3xx and upwards).
977
  This method can be called by the application when the state machine is in the {{{REINVITED}}} state and will move the state machine back into the {{{CONFIRMED}}} state.
978
  Before giving a positive final response, the SDP needs to be set using the {{{set_offered_local_sdp()}}} method.
979
  [[BR]]''response_code'':[[BR]]
980
  The code of the response to use as an int.
981
  This should be a 3 digit number.
982
  [[BR]]''extra_headers'':[[BR]]
983
 '''send_reinvite'''(''self'', '''extra_headers'''={{{None}}})::
984
  The application may only call this method when the state machine is in the {{{CONFIRMED}}} state to induce sending a re-{{{INVITE}}}.
985
  Before doing this it needs to set the new local SDP offer by calling the {{{set_offered_local_sdp()}}} method.
986
  After this method is called, the state machine will be in the {{{REINVITING}}} state, until a final response from the remote party is received.
987
  [[BR]]''extra_headers'':[[BR]]
988
  Any extra headers that should be included in the re-{{{INVITE}}} in the form of a dict.
989
990
==== notifications ====
991
992
 '''SCInvitationChangedState'''::
993
  This notification is sent by an {{{Invitation}}} object whenever its state machine changes state.
994
  [[BR]]''timestamp'':[[BR]]
995
  A {{{datetime.datetime}}} object indicating when the notification was sent.
996
  [[BR]]''prev_state'':[[BR]]
997
  The previous state of the INVITE state machine.
998
  [[BR]]''state'':[[BR]]
999
  The new state of the INVITE state machine, which may be the same as the previous state.
1000
  [[BR]]''method'': (only if the state change got triggered by an incoming SIP request)[[BR]]
1001
  The method of the SIP request as a string.
1002
  [[BR]]''request_uri'': (only if the state change got triggered by an incoming SIP request)[[BR]]
1003
  The request URI of the SIP request as a {{{SIPURI}}} object.
1004
  [[BR]]''code'': (only if the state change got triggered by an incoming SIP response or internal timeout or error)[[BR]]
1005
  The code of the SIP response or error as an int.
1006
  [[BR]]''reason'': (only if the state change got triggered by an incoming SIP response or internal timeout or error)[[BR]]
1007
  The reason text of the SIP response or error as an int.
1008
  [[BR]]''headers'': (only if the state change got triggered by an incoming SIP request or response)[[BR]]
1009
  The headers of the SIP request or response as a dict.
1010
  Each SIP header is represented in its parsed for as long as PJSIP supports it.
1011
  The format of the parsed value depends on the header.
1012
  [[BR]]''body'': (only if the state change got triggered by an incoming SIP request or response)[[BR]]
1013
  The body of the SIP request or response as a string, or {{{None}}} if no body was included.
1014
  The content type of the body can be learned from the {{{Content-Type:}}} header in the headers argument.
1015
 '''SCInvitationGotSDPUpdate'''::
1016
  This notification is sent by an {{{Invitation}}} object whenever SDP negotation has been perfomed.
1017
  It should be used by the application as an indication to start, change or stop any associated media streams.
1018
  [[BR]]''timestamp'':[[BR]]
1019
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1020
  [[BR]]''succeeded'':[[BR]]
1021
  A boolean indicating if the SDP negotation has succeeded.
1022
  [[BR]]''error'': (only if SDP negotation did not succeed)[[BR]]
1023
  A string indicating why SDP negotation failed.
1024
  [[BR]]''local_sdp'': (only if SDP negotation succeeded)[[BR]]
1025
  A SDPSession object indicating the local SDP that was negotiated.
1026
  [[BR]]''remote_sdp'': (only if SDP negotation succeeded)[[BR]]
1027
  A SDPSession object indicating the remote SDP that was negotiated.
1028
1029
=== SDPSession ===
1030
1031
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. 
1032
1033
SDPSession object directly represents the contents of a SDP body, as carried e.g. in a INVITE request, and is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__session.htm pjmedia_sdp_session] structure.
1034
It can be passed to those methods of an {{{Invitation}}} object that result in transmission of a message that includes SDP, or is passed to the application through a notification that is triggered by reception of a message that includes SDP.
1035
A {{{SDPSession}}} object may contain {{{SDPMedia}}}, {{{SDPConnection}}} and {{{SDPAttribute}}} objects.
1036
It supports comparison to other {{{SDPSession}}} objects using the == and != expressions.
1037
As all the attributes of the {{{SDPSession}}} class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1038
1039
==== methods ====
1040
1041
 '''!__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'''=list(), '''media'''=list())::
1042
  Creates the SDPSession object with the specified parameters as attributes.
1043
  Each of these attributes can be accessed and changed on the object once instanced.
1044
  [[BR]]''address'':[[BR]]
1045
  The address that is contained in the "o" (origin) line of the SDP as a string.
1046
  [[BR]]''id'':[[BR]]
1047
  The session identifier contained in the "o" (origin) line of the SDP as an int.
1048
  If this is set to {{{None}}} on init, a session identifier will be generated.
1049
  [[BR]]''version'':[[BR]]
1050
  The version identifier contained in the "o" (origin) line of the SDP as an int.
1051
  If this is set to {{{None}}} on init, a version identifier will be generated.
1052
  [[BR]]''user'':[[BR]]
1053
  The user name contained in the "o" (origin) line of the SDP as a string.
1054
  [[BR]]''net_type'':[[BR]]
1055
  The network type contained in the "o" (origin) line of the SDP as a string.
1056
  [[BR]]''address_type'':[[BR]]
1057
  The address type contained in the "o" (origin) line of the SDP as a string.
1058
  [[BR]]''name'':[[BR]]
1059
  The contents of the "s" (session name) line of the SDP as a string.
1060
  [[BR]]''info'':[[BR]]
1061
  The contents of the session level "i" (information) line of the SDP as a string.
1062
  If this is {{{None}}} or an empty string, the SDP has no "i" line.
1063
  [[BR]]''connection'':[[BR]]
1064
  The contents of the "c" (connection) line of the SDP as a {{{SDPConnection}}} object.
1065
  If this is set to {{{None}}}, the SDP has no session level "c" line.
1066
  [[BR]]''start_time'':[[BR]]
1067
  The first value of the "t" (time) line of the SDP as an int.
1068
  [[BR]]''stop_time'':[[BR]]
1069
  The second value of the "t" (time) line of the SDP as an int.
1070
  [[BR]]''attributes'':[[BR]]
1071
  The session level "a" lines (attributes) in the SDP represented by a list of {{{SDPAttribute}}} objects.
1072
  [[BR]]''media'':[[BR]]
1073
  The media sections of the SDP represented by a list of {{{SDPMedia}}} objects.
1074
1075
=== SDPMedia ===
1076
1077
This object represents the contents of a media section of a SDP body, i.e. a "m" line and everything under it until the next "m" line.
1078
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__media.htm pjmedia_sdp_media] structure.
1079
One or more {{{SDPMedia}}} objects are usually contained in a {{{SDPSession}}} object.
1080
It supports comparison to other {{{SDPMedia}}} objects using the == and != expressions.
1081
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1082
1083
==== methods ====
1084
1085
 '''!__init!__'''(''self'', '''media''', '''port''', '''transport''', '''port_count'''=1, '''formats'''=list(), '''info'''={{{None}}}, '''connection'''={{{None}}}, '''attributes'''=list())::
1086
  Creates the SDPMedia object with the specified parameters as attributes.
1087
  Each of these attributes can be accessed and changed on the object once instanced.
1088
  [[BR]]''media'':[[BR]]
1089
  The media type contained in the "m" (media) line as a string.
1090
  [[BR]]''port'':[[BR]]
1091
  The transport port contained in the "m" (media) line as an int.
1092
  [[BR]]''transport'':[[BR]]
1093
  The transport protocol in the "m" (media) line as a string.
1094
  [[BR]]''port_count'':[[BR]]
1095
  The port count in the "m" (media) line as an int.
1096
  If this is set to 1, it is not included in the SDP.
1097
  [[BR]]''formats'':[[BR]]
1098
  The media formats in the "m" (media) line represented by a list of strings.
1099
  [[BR]]''info'':[[BR]]
1100
  The contents of the "i" (information) line of this media section as a string.
1101
  If this is {{{None}}} or an empty string, the media section has no "i" line.
1102
  [[BR]]''connection'':[[BR]]
1103
  The contents of the "c" (connection) line that is somewhere below the "m" line of this section as a {{{SDPConnection}}} object.
1104
  If this is set to {{{None}}}, this media section has no "c" line.
1105
  [[BR]]''attributes'':[[BR]]
1106
  The "a" lines (attributes) that are somewhere below the "m" line of this section represented by a list of {{{SDPAttribute}}} objects.
1107
 '''get_direction'''(''self'')::
1108
  This is a convenience methods that goes through all the attributes of the media section and returns the direction, which is either "sendrecv", "sendonly", "recvonly" or "inactive".
1109
  If none of these attributes is present, the default direction is "sendrecv".
1110
1111
=== SDPConnection ===
1112
1113
This object represents the contents of a "c" (connection) line of a SDP body, either at the session level or for an individual media stream.
1114
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__conn.htm pjmedia_sdp_conn] structure.
1115
A {{{SDPConnection}}} object can be contained in a {{{SDPSession}}} object or {{{SDPMedia}}} object.
1116
It supports comparison to other {{{SDPConnection}}} objects using the == and != expressions.
1117
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1118
1119
==== methods ====
1120
1121
 '''!__init!__'''(''self'', '''address''', '''net_type'''="IN", '''address_type'''="IP4")::
1122
  Creates the SDPConnection object with the specified parameters as attributes.
1123
  Each of these attributes can be accessed and changed on the object once instanced.
1124
  [[BR]]''address'':[[BR]]
1125
  The address part of the connection line as a string.
1126
  [[BR]]''net_type'':[[BR]]
1127
  The network type part of the connection line as a string.
1128
  [[BR]]''address_type'':[[BR]]
1129
  The address type part of the connection line as a string.
1130
1131
=== SDPAttribute ===
1132
1133
This object represents the contents of a "a" (attribute) line of a SDP body, either at the session level or for an individual media stream.
1134
It is a simple wrapper for the PJSIP [http://www.pjsip.org/pjmedia/docs/html/structpjmedia__sdp__attr.htm pjmedia_sdp_attr] structure.
1135
One or more {{{SDPAttribute}}} objects can be contained in a {{{SDPSession}}} object or {{{SDPMedia}}} object.
1136
It supports comparison to other {{{SDPAttribute}}} objects using the == and != expressions.
1137
As all the attributes of this class are set by attributes of the {{{__init__}}} method, they will be documented along with that method.
1138
1139
==== methods ====
1140
1141
 '''!__init!__'''(''self'', '''name''', '''value''')::
1142
  Creates the SDPAttribute object with the specified parameters as attributes.
1143
  Each of these attributes can be accessed and changed on the object once instanced.
1144
  [[BR]]''name'':[[BR]]
1145
  The name part of the attribute line as a string.
1146
  [[BR]]''value'':[[BR]]
1147
  The value part of the attribute line as a string.
1148
1149
=== RTPTransport ===
1150
1151
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.
1152
Internally it wraps a [http://www.pjsip.org/pjmedia/docs/html/group__PJMEDIA__TRANSPORT.htm pjmedia_transport] object.
1153
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].
1154
For this reason the {{{AudioTransport}}} and {{{RTPTransport}}} are two distinct objects.
1155
1156
The {{{RTPTransport}}} object also allows support for ICE and SRTP functionality from PJSIP.
1157
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.
1158
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.
1159
This process of SDP negotiation is represented by the internal state machine of the object, as shown in the following diagram:
1160
1161
> The Real-time Transport Protocol (or RTP) defines a standardized packet format for delivering audio and video over the Internet.
1162
> It was developed by the Audio-Video Transport Working Group of the IETF and published in [http://tools.ietf.org/html/rfc3550 RFC 3550].
1163
> RTP is used in streaming media systems (together with the RTSP) as well as in videoconferencing and push to talk systems.
1164
> 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.
1165
1166 18 Adrian Georgescu
[[Image(sipsimple-rtp-transport-state-machine.png, nolink)]]
1167 1 Adrian Georgescu
1168
State changes are triggered by the following events:
1169 17 Ruud Klaver
 1. The application calls the {{{set_INIT()}}} method after object creation and ICE+STUN is not used.
1170
 2. The application calls the {{{set_INIT()}}} method after object creation and ICE+STUN is used.
1171
 3. A successful STUN response is received from the STUN server.
1172
 4. The {{{set_LOCAL()}}} method is called.
1173
 5. The {{{set_ESTABLISHED()}}} method is called.
1174
 6. The {{{set_INIT()}}} method is called while the object is in the {{{LOCAL}}} or {{{ESTABLISHED}}} state.
1175
 7. A method is called on the application, but in the meantime the {{{Engine}}} has stopped.
1176
    The object can no longer be used.
1177
 8. There was an error in getting the STUN candidates from the STUN server.
1178 1 Adrian Georgescu
1179
> 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 negotation has failed.
1180
> This means that the RTPTransport object is also unusable once it has reached the STUN_FAILED state.
1181
> A workaround would be destroy the RTPTransport object and create a new one that uses ICE without STUN.
1182
1183
These states allow for two SDP negotiation scenarios to occur, represented by two paths that can be followed through the state machine.
1184
In this example we will assume that ICE with STUN is not used, as it is independent of the SDP negotiation procedure.
1185
 * The first scenario is where the local party generates the SDP offer.
1186
   For a stream that it wishes to include in this SDP offer, it instantiates a {{{RTPTransport}}} object.
1187 17 Ruud Klaver
   After instantiation the object is initialized by calling the {{{set_INIT()}}} method and the local RTP address and port can be fetched from it using the {{{local_rtp_address}}} and {{{local_rtp_port}}} respectively, which can be used to generate the local SDP in the form of a {{{SDPSession}}} object (note that it needs the full object, not just the relevant {{{SDPMedia}}} object).
1188 1 Adrian Georgescu
   This local SDP then needs to be passed to the {{{set_LOCAL()}}} method, which moves the state machine into the {{{LOCAL}}} state.
1189
   Depending on the options used for the {{{RTPTransport}}} instantiation (such as ICE and SRTP), this may change the {{{SDPSession}}} object.
1190
   This (possibly changed) {{{SDPSession}}} object then needs to be passed to the {{{Invitation}}} object.
1191
   After SDP negotiation is completed, the application needs to pass both the local and remote SDP, in the form of {{{SDPSession}}} objects, to the {{{RTPTransport}}} object using the {{{set_ESTABLISHED()}}} method, moving the state machine into the {{{ESTABLISHED}}} state.
1192
   This will not change either of the {{{SDPSession}}} objects.
1193
 * The second scenario is where the local party is offered a media stream in SDP and wants to accept it.
1194 17 Ruud Klaver
   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.
1195 1 Adrian Georgescu
   Directly after this it should pass the generated local SDP and received remote SDP, in the form of {{{SDPSession}}} objects, to the {{{set_ESTABLISHED()}}} method.
1196
   In this case the local SDP object may be changed, after which it can be passed to the {{{Invitation}}} object.
1197
1198
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.
1199
Before doing this however, the internal transport object must no longer be in use.
1200
1201
==== attributes ====
1202
1203
 '''state'''::
1204
  Indicates which state the internal state machine is in.
1205
  See the previous section for a list of states the state machine can be in.
1206
  This attribute is read-only.
1207
 '''local_rtp_address'''::
1208
  The local IPv4 or IPv6 address of the interface the {{{RTPTransport}}} object is listening on and the address that should be included in the SDP.
1209
  If no address was specified during object instantiation, PJSIP will take guess out of the IP addresses of all interfaces.
1210
  This attribute is read-only and will be {{{None}}} if PJSIP is not listening on the transport.
1211
 '''local_rtp_port'''::
1212
  The UDP port PJSIP is listening on for RTP traffic.
1213
  RTCP traffic will always be this port plus one.
1214
  This attribute is read-only and will be {{{None}}} if PJSIP is not listening on the transport.
1215
 '''remote_rtp_address_sdp'''::
1216
  The remote IP address that was seen in the SDP.
1217
  This attribute is read-only and will be {{{None}}} unless the object is in the {{{ESTABLISHED}}} state.
1218
 '''remote_rtp_port_sdp'''::
1219
  The remote UDP port for RTP that was seen in the SDP.
1220
  This attribute is read-only and will be {{{None}}} unless the object is in the {{{ESTABLISHED}}} state.
1221
 '''remote_rtp_address_received'''::
1222
  The remote IP address from which RTP data was received.
1223
  This attribute is read-only and will be {{{None}}} unless RTP was actually received.
1224
 '''remote_rtp_port_received'''::
1225
  The remote UDP port from which RTP data was received.
1226
  This attribute is read-only and will be {{{None}}} unless RTP was actually received.
1227
 '''use_srtp'''::
1228
  A boolean indicating if the use of SRTP was requested when the object was instantiated.
1229
  This attribute is read-only.
1230
 '''force_srtp'''::
1231
  A boolean indicating if SRTP being mandatory for this transport if it is enabled was requested when the object was instantiated.
1232
  This attribute is read-only.
1233
 '''srtp_active'''::
1234
  A boolean indicating if SRTP encryption and decryption is running.
1235
  Querying this attribute only makes sense once the object is in the {{{ESTABLISHED}}} state and use of SRTP was requested.
1236
  This attribute is read-only.
1237
 '''use_ice'''::
1238
  A boolean indicating if the use of ICE was requested when the object was instantiated.
1239
  This attribute is read-only.
1240
 '''ice_stun_address'''::
1241
  A string indicating the address (IP address or hostname) of the STUN server that was requested to be used.
1242
  This attribute is read-only.
1243
 '''ice_stun_port'''::
1244
  A string indicating the UDP port of the STUN server that was requested to be used.
1245
  This attribute is read-only.
1246
1247
==== methods ====
1248
1249
 '''!__init!__'''(''self'', '''local_rtp_address'''={{{None}}}, '''use_srtp'''={{{False}}}, '''srtp_forced'''={{{False}}}, '''use_ice'''={{{False}}}, '''ice_stun_address'''={{{None}}}, '''ice_stun_port'''=3478)::
1250
  Creates a new {{{RTPTransport}}} object and opens the RTP and RTCP UDP sockets.
1251
  If aditional features are requested, they will be initialized.
1252
  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.
1253
  [[BR]]''local_rtp_address'':[[BR]]
1254
  Optionally contains the local IP address to listen on, either in IPv4 or IPv6 form.
1255
  If this is not specified, PJSIP will listen on all network interfaces.
1256
  [[BR]]''use_srtp'':[[BR]]
1257
  A boolean indicating if SRTP should be used.
1258
  If this is set to {{{True}}}, SRTP information will be added to the SDP when it passes this object.
1259
  [[BR]]''srtp_forced'':[[BR]]
1260
  A boolean indicating if use of SRTP is set to mandatory in the SDP.
1261
  If this is set to {{{True}}} and the remote party does not support SRTP, the SDP negotation for this stream will fail.
1262
  This argument is relevant only if {{{use_srtp}}} is set to {{{True}}}.
1263
  [[BR]]''use_ice'':[[BR]]
1264
  A boolean indicating if ICE should be used.
1265
  If this is set to {{{True}}}, ICE candidates will be added to the SDP when it passes this object.
1266
  [[BR]]''ice_stun_address'':[[BR]]
1267
  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.
1268
  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.
1269
  When this happens a {{{SCRTPTransportGotSTUNResponse}}} notification is sent.
1270
  This argument is relevant only if {{{use_ice}}} is set to {{{True}}}.
1271
  [[BR]]''ice_stun_address'':[[BR]]
1272
  An int indicating the UDP port of the STUN server that should be used to add a STUN candidate to the ICE candidates.
1273
  This argument is relevant only if {{{use_ice}}} is set to {{{True}}} and {{{ice_stun_address}}} is not {{{None}}}.
1274
 '''!__set_LOCAL!__'''(''self'', '''local_sdp''', '''sdp_index''')::
1275
  This moves the the internal state machine into the {{{LOCAL}}} state.
1276
  [[BR]]''local_sdp'':[[BR]]
1277
  The local SDP to be proposed in the form of a {{{SDPSession}}} object.
1278
  Note that this object may be modified by this method.
1279
  [[BR]]''sdp_index'':[[BR]]
1280
  The index in the SDP for the media stream for which this object was created.
1281
 '''!__set_ESTABLISHED!__'''(''self'', '''local_sdp''', '''remote_sdp''', '''sdp_index''')::
1282
  This moves the the internal state machine into the {{{ESTABLISHED}}} state.
1283
  [[BR]]''local_sdp'':[[BR]]
1284
  The local SDP to be proposed in the form of a {{{SDPSession}}} object.
1285
  Note that this object may be modified by this method, but only when moving from the {{{LOCAL}}} to the {{{ESTABLISHED}}} state.
1286
  [[BR]]''remote_sdp'':[[BR]]
1287
  The remote SDP that was received in in the form of a {{{SDPSession}}} object.
1288
  [[BR]]''sdp_index'':[[BR]]
1289
  The index in the SDP for the media stream for which this object was created.
1290
 '''!__set_INIT!__'''(''self'')::
1291 17 Ruud Klaver
  This moves the internal state machine into the {{{INIT}}} state.
1292
  If the state machine is in the {{{LOCAL}}} or {{{ESTABLISHED}}} states, this effectively resets the {{{RTPTransport}}} object for re-use.
1293 1 Adrian Georgescu
1294
==== notifications ====
1295
1296 17 Ruud Klaver
 '''SCRTPTransportDidInitialize'''::
1297
  This notification is sent when a {{{RTPTransport}}} object has successfully initialized.
1298
  If STUN+ICE is not requested, this is sent immediately on {{{set_INIT()}}}, otherwise it is sent after the STUN query has succeeded.
1299 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
1300
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1301 17 Ruud Klaver
 '''SCRTPTransportDidFail'''::
1302
  This notification is sent by a {{{RTPTransport}}} object that fails to retrieve ICE candidates from the STUN server after {{{set_INIT()}}} is called.
1303
  [[BR]]''timestamp'':[[BR]]
1304
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1305
  [[BR]]''reason'':[[BR]]
1306
  A string describing the failure reason.
1307 1 Adrian Georgescu
1308
=== AudioTransport ===
1309
1310
This object represent an audio stream as it is transported over the network.
1311
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.
1312
It also generates a {{{SDPMedia}}} object to be included in the local SDP.
1313
1314
Like the {{{RTPTransport}}} object there are two usage scenarios.
1315
 * In the first scenario, only the {{{RTPTransport}}} instance to be used is passed to the AudioTransport object.
1316
   The application can then generate the {{{SDPMedia}}} object by calling the {{{get_local_media()}}} method and should include it in the SDP offer.
1317
   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.
1318
   The stream can then be connected to the conference bridge.
1319
 * 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.
1320
   The local {{{SDPMedia}}} object can again be generated by calling the {{{get_local_media()}}} method and is to be included in the SDP answer.
1321
   The audio stream is started directly when the object is created.
1322
1323
Unlike the {{{RTPTransport}}} object, this object cannot be reused.
1324
1325
==== attributes ====
1326
1327
 '''transport'''::
1328
  The {{{RTPTransport}}} object that was passed when the object got instatiated.
1329
  This attribute is read-only.
1330
 '''is_active'''::
1331
  A boolean indicating if the object is currently sending and receiving audio.
1332
  This attribute is read-only.
1333
 '''is_started'''::
1334
  A boolean indicating if the object has been started.
1335
  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.
1336
  This is to prevent the object from being re-used.
1337
  This attribute is read-only.
1338
 '''codec'''::
1339
  Once the SDP negotiation is complete, this attribute indicates the audio codec that was negotiated, otherwise it will be {{{None}}}.
1340
  This attribute is read-only.
1341
 '''sample_rate'''::
1342
  Once the SDP negotiation is complete, this attribute indicates the sample rate of the audio codec that was negotiated, otherwise it will be {{{None}}}.
1343
  This attribute is read-only.
1344
 '''direction'''::
1345
  The current direction of the audio transport, which is one of "sendrecv", "sendonly", "recvonly" or "inactive".
1346
  This attribute is read-only, although it can be set using the {{{update_direction()}}} method.
1347
1348
==== methods ====
1349
1350
 '''!__init!__'''(''self'', '''transport''', '''remote_sdp'''={{{None}}}, '''sdp_index'''=0, '''enable_silence_detection'''=True)::
1351
  Creates a new {{{AudioTransport}}} object and start the underlying stream if the remote SDP is already known.
1352
  [[BR]]''transport'':[[BR]]
1353
  The transport to use in the form of a {{{RTPTransport}}} object.
1354
  [[BR]]''remote_sdp'':[[BR]]
1355
  The remote SDP that was received in the form of a {{{SDPSession}}} object.
1356
  [[BR]]''sdp_index'':[[BR]]
1357
  The index within the SDP of the audio stream that should be created.
1358
  [[BR]]''enable_silence_detection''[[BR]]
1359
  Boolean that indicates if silence detection should be used for this audio stream.
1360
  When enabled, this {{{AudioTransport}}} object will stop sending audio to the remote party if the input volume is below a certain threshold.
1361
 '''get_local_media'''(''self'', '''is_offer''', '''direction'''="sendrecv")::
1362
  Generates a {{{SDPMedia}}} object which describes the audio stream.
1363
  This object should be included in a {{{SDPSession}}} object that gets passed to the {{{Invitation}}} object.
1364
  This method should also be used to obtain the SDP to include in re-INVITEs and replies to re-INVITEs.
1365
  [[BR]]''is_offer'':[[BR]]
1366
  A boolean indicating if the SDP requested is to be included in an offer.
1367
  If this is {{{False}}} it is to be included in an answer.
1368
  [[BR]]''direction'':[[BR]]
1369
  The direction attribute to put in the SDP.
1370
 '''start'''(''self'', '''local_sdp''', '''remote_sdp''', '''sdp_index''')::
1371
  This method should only be called once, when the application has previously sent an SDP offer and the answer has been received.
1372
  [[BR]]''local_sdp'':[[BR]]
1373
  The full local SDP that was included in the SDP negotiation in the form of a {{{SDPSession}}} object.
1374
  [[BR]]''remote_sdp'':[[BR]]
1375
  The remote SDP that was received in the form of a {{{SDPSession}}} object.
1376
  [[BR]]''sdp_index'':[[BR]]
1377
  The index within the SDP of the audio stream.
1378
 '''stop'''(''self'')::
1379
  This method stops and destroys the audio stream encapsulated by this object.
1380
  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.
1381
  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.
1382
 '''send_dtmf'''(''self'', '''digit''')::
1383
  For a negotiated audio transport this sends one DTMF digit to the other party
1384
  [[BR]]''digit'':[[BR]]
1385
  A string of length one indicating the DTMF digit to send.
1386
  This can be either a number or letters A through D.
1387
 '''update_direction'''(''self'', '''direction''')::
1388
  This method should be called after SDP negotiation has completed to update the direction of the media stream.
1389
  [[BR]]''direction'':[[BR]]
1390
  The direction that has been negotiated.
1391
1392
==== notifications ====
1393
1394
 '''SCAudioTransportGotDTMF'''::
1395
  This notification will be sent when an incoming DTMF digit is received from the remote party.
1396
  [[BR]]''timestamp'':[[BR]]
1397
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1398
  [[BR]]''digit'':[[BR]]
1399
  The DTMF digit that was received, in the form of a string of length one.
1400
  This can be either a number or letters A through D.
1401
1402
=== WaveFile ===
1403
1404
This is a simple object that allows playing back of a {{{.wav}}} file over the PJSIP conference bridge, possibly looping a number of times.
1405
Only 16-bit PCM and A-law/U-law formats are supported.
1406
Its main purpose is the playback of ringtones.
1407
1408
This class can be instantiated by the application before the {{{Engine}}} is running, but in order to actually start playback, through the {{{start()}}} method, the {{{Engine}}} must have been started as well.
1409
Once the {{{start()}}} method is called, the {{{.wav}}} file will continue playing until the loop count specified is reached( or forever if the specified loop count is 0), or until the {{{stop()}}} method is called.
1410
When playback stops for either of these reasons, a {{{SCWaveFileDidEnd}}} notification is sent by the object.
1411
After this the {{{start()}}} method may be called again in order to re-use the object.
1412
1413
It is the application's responsibility to keep a reference to the {{{WaveFile}}} object for the duration of playback.
1414
If the reference count of the object reaches 0, playback will be stopped.
1415
In this case no notification will be sent.
1416
1417
==== attributes ====
1418
1419
 '''file_name'''::
1420
  The name of the {{{.wav}}} file, as specified when the object was created.
1421
 '''is_active'''::
1422
  A boolean read-only property that indicates if the file is currently being played back.
1423
  Note that if the playback loop is currently in a pause between playbacks, this attribute will also be {{{True}}}.
1424
1425
==== methods ====
1426
1427
 '''!__init!__'''(''self'', '''file_name''')::
1428
  Creates a new {{{WaveFile}}} object.
1429
  [[BR]]''file_name'':[[BR]]
1430
  The name of the {{{.wav}}} file to be played back as a string.
1431
  This should include the full path to the file.
1432
 '''start'''(''self'', '''level'''=100, '''loop_count'''=1, '''pause_time'''=0)::
1433
  Start playback of the {{{.wav}}} file, optionally looping it.
1434
  [[BR]]''level'':[[BR]]
1435
  The level to play the file back at, in percentage.
1436
  A percentage lower than 100 means playback will be attenuated, a percentage higher than 100 means it will amplified.
1437
  [[BR]]''loop_count'':[[BR]]
1438
  The number of time to loop playing this file.
1439
  A value of 0 means looping infinitely.
1440
  [[BR]]''pause_time'':[[BR]]
1441
  The number of seconds to pause between consecutive loops.
1442
  This can be either an int or a float.
1443
 '''stop'''(''self'')::
1444
  Stop playback of the file.
1445
1446
==== notifications ====
1447
1448
 '''SCWaveFileDidEnd'''::
1449
  This notification will be sent whenever the {{{.wav}}} file has been played back the specified number of times.
1450
  After sending this event, the playback may be re-started.
1451
  [[BR]]''timestamp'':[[BR]]
1452
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1453
1454
=== RecordingWaveFile ===
1455
1456
This is a simple object that allows recording whatever is heard on the PJSIP conference bridge to a PCM {{{.wav}}} file.
1457
1458
This class can be instantiated by the application before the {{{Engine}}} is running, but in order to actually start playback, through the {{{start()}}} method, the {{{Engine}}} must have been started as well.
1459
Recording to the file can be stopped either by calling the {{{stop()}}} method or by removing all references to the object.
1460
Once the {{{stop()}}} method has been called, the {{{start()}}} method may not be called again.
1461
It is the application's responsibility to keep a reference to the {{{RecordingWaveFile}}} object for the duration of the recording.
1462
1463
==== attributes ====
1464
1465
 '''file_name'''::
1466 15 Ruud Klaver
  The name of the {{{.wav}}} file, as specified when the object was created.
1467
 '''is_active'''::
1468
  A boolean read-only attribute that indicates if the file is currently being written to.
1469 1 Adrian Georgescu
 '''is_paused'''::
1470
  A boolean read-only attribute that indicates if the active recording is currently paused.
1471
1472
==== methods ====
1473
1474
 '''!__init!__'''(''self'', '''file_name''')::
1475
  Creates a new {{{RecordingWaveFile}}} object.
1476
  [[BR]]''file_name'':[[BR]]
1477
  The name of the {{{.wav}}} file to record to as a string.
1478
  This should include the full path to the file.
1479 15 Ruud Klaver
 '''start'''(''self'')::
1480
  Start recording the sound on the conference bridge to the {{{.wav}}} file.
1481
 '''pause'''(''self'')::
1482
  Pause recording to the {{{.wav}}} file.
1483 1 Adrian Georgescu
 '''resume'''(''self'')::
1484
  Resume a previously paused recording.
1485
 '''stop'''(''self'')::
1486
  Stop recording to the file.