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