SipMiddlewareApi

Version 72 (Luci Stanescu, 03/26/2010 03:31 pm)

1 1 Adrian Georgescu
= Middleware API =
2 1 Adrian Georgescu
3 1 Adrian Georgescu
[[TOC(WikiStart, Sip*, depth=3)]]
4 1 Adrian Georgescu
5 60 Adrian Georgescu
This chapter describes the event driven ''Middleware API'' that can be used by a developer to build a user interface for SIP SIMPLE client SDK.  
6 14 Adrian Georgescu
7 54 Adrian Georgescu
 * For sub-systems communications the Middleware uses the [http://pypi.python.org/pypi/python-application/ Notification Bus] provided by [http://pypi.python.org/pypi/python-application/ python-application]
8 49 Adrian Georgescu
 * For configuration the Middleware uses the [wiki:SipConfigurationAPI Configuration API] to access General and SIP account  settings
9 1 Adrian Georgescu
10 59 Adrian Georgescu
To see a working example for how to use Middleware, see the [http://sipsimpleclient.com/wiki/SipTesting#TestingGuide Command Line Tools] provided with the library.
11 59 Adrian Georgescu
12 53 Adrian Georgescu
[[Image(sipsimple-middleware.png, align=center, width=800)]]
13 1 Adrian Georgescu
14 64 Luci Stanescu
== Lookup support ==
15 64 Luci Stanescu
16 64 Luci Stanescu
The SIP SIMPLE middleware offers the {{{sipsimple.lookup}}} module which contains an implementation for doing DNS lookups for SIP proxies, MSRP relays and STUN servers. The interface offers both an asynchronous and synchronous interface. The asynchronous interface is based on notifications, while the synchronous one on green threads. In order to call the methods in a asynchronous manner, you just need to call the method and wait for the notification which is sent on behalf of the DNSLookup instance. The notifications sent by the DNSLookup object are DNSLookupDidSucceed and DNSLookupDidFail. In order to call the methods in a synchronous manner, you need to call the wait method on the object returned by the methods of DNSLookup. This wait method needs to be called from a green thread and will either return the result of the lookup or raise an exception.
17 64 Luci Stanescu
18 64 Luci Stanescu
=== DNS Lookup ===
19 64 Luci Stanescu
20 64 Luci Stanescu
This object implements DNS lookup support for SIP proxies according to RFC3263 and MSRP relay and STUN server lookup using SRV records. The object initially does NS record queries in order to determine the authoritative nameservers for the domain requested; these authoritative nameservers will then be used for NAPTR, SRV and A record queries. If this fails, the locally configured nameservers are used. The reason for doing this is that some home routers have broken NAPTR and/or SRV query support.
21 64 Luci Stanescu
22 64 Luci Stanescu
==== methods ====
23 64 Luci Stanescu
24 64 Luci Stanescu
 '''!__init!__'''(''self'')::
25 64 Luci Stanescu
  Instantiate a new DNSLookup object.
26 64 Luci Stanescu
 '''lookup_service'''(''self'', '''uri''', '''service''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}})::
27 64 Luci Stanescu
  Perform an SRV lookup followed by A lookups for MSRP relays or STUN servers depending on the {{{service}}} parameter. If SRV queries on the {{{uri.host}}} domain fail, an A lookup is performed on it and the default port for the service is returned. Only the {{{uri.host}}} attribute is used. The return value is a list of (host, port) tuples.
28 64 Luci Stanescu
  [[BR]]uri:[[BR]]
29 64 Luci Stanescu
  A {{{(Frozen)SIPURI}}} from which the {{{host}}} attribute is used for the query domain.
30 64 Luci Stanescu
  [[BR]]service:[[BR]]
31 64 Luci Stanescu
  The service to lookup servers for, {{{"msrprelay"}}} or {{{"stun"}}}.
32 64 Luci Stanescu
  [[BR]]timeout:[[BR]]
33 64 Luci Stanescu
  How many seconds to wait for a response from a nameserver.
34 64 Luci Stanescu
  [[BR]]lifetime:[[BR]]
35 64 Luci Stanescu
  How many seconds to wait for a response from all nameservers in total.
36 64 Luci Stanescu
 '''lookup_sip_proxy'''(''self'', '''uri''', '''supported_transports''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}})::
37 64 Luci Stanescu
  Perform a RFC3263 compliant DNS lookup for a SIP proxy using the URI which is considered to point to a host if either the {{{host}}} attribute is an IP address, or the {{{port}}} is present. Otherwise, it is considered a domain for which NAPTR, SRV and A lookups are performed. If NAPTR or SRV queries fail, they fallback to using SRV and A queries. If the transport parameter is present in the URI, this will be used as far as it is part of the supported transports. If the URI has a {{{sips}}} schema, then only the TLS transport will be used as far as it doesn't conflict with the supported transports or the transport parameter. The return value is a list of {{{Route}}} objects containing the IP address, port and transport to use for routing in the order of preference given by the supported_transports argument.
38 64 Luci Stanescu
  [[BR]]uri:[[BR]]
39 64 Luci Stanescu
  A {{{(Frozen)SIPURI}}} from which the {{{host}}}, {{{port}}}, {{{parameters}}} and {{{secure}}} attributes are used.
40 64 Luci Stanescu
  [[BR]]supported_transports:[[BR]]
41 64 Luci Stanescu
  A sublist of {{{['udp', 'tcp', 'tls']}}} in the application's order of preference.
42 64 Luci Stanescu
  [[BR]]timeout:[[BR]]
43 64 Luci Stanescu
  How many seconds to wait for a response from a nameserver.
44 64 Luci Stanescu
  [[BR]]lifetime:[[BR]]
45 64 Luci Stanescu
  How many seconds to wait for a response from all nameservers in total.
46 64 Luci Stanescu
47 64 Luci Stanescu
==== notifications ====
48 64 Luci Stanescu
49 64 Luci Stanescu
 '''DNSLookupDidSucceed'''::
50 64 Luci Stanescu
  This notification is sent when one of the lookup methods succeeds in finding a result.
51 64 Luci Stanescu
  [[BR]]timestamp:[[BR]]
52 64 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
53 64 Luci Stanescu
  [[BR]]result:[[BR]]
54 64 Luci Stanescu
  The result of the DNS lookup in the format described in each method.
55 64 Luci Stanescu
 '''DNSLookupDidFail'''::
56 64 Luci Stanescu
  This notification is sent when one of the lookup methods fails in finding a result.
57 64 Luci Stanescu
  [[BR]]timestamp:[[BR]]
58 64 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
59 64 Luci Stanescu
  [[BR]]error:[[BR]]
60 64 Luci Stanescu
  A {{{str}}} object describing the error which resulted in the DNS lookup failure.
61 64 Luci Stanescu
 '''DNSLookupTrace'''::
62 64 Luci Stanescu
  This notification is sent several times during a lookup process for each individual DNS query.
63 64 Luci Stanescu
  [[BR]]timestamp:[[BR]]
64 64 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
65 64 Luci Stanescu
  [[BR]]query_type:[[BR]]
66 64 Luci Stanescu
  The type of the query, {{{"NAPTR"}}}, {{{"SRV"}}}, {{{"A"}}}, {{{"NS"}}} etc.
67 64 Luci Stanescu
  [[BR]]query_name:[[BR]]
68 64 Luci Stanescu
  The name which was queried.
69 64 Luci Stanescu
  [[BR]]answer:[[BR]]
70 64 Luci Stanescu
  The answer returned by dnspython, or {{{None}}} if an error occurred.
71 64 Luci Stanescu
  [[BR]]error:[[BR]]
72 64 Luci Stanescu
  The exception which caused the query to fail, or {{{None}}} if no error occurred.
73 64 Luci Stanescu
  [[BR]]context:[[BR]]
74 64 Luci Stanescu
  The name of the method which was called on the {{{DNSLookup}}} object.
75 64 Luci Stanescu
  [[BR]]service:[[BR]]
76 64 Luci Stanescu
  The service which was queried for, only available when context is {{{"lookup_service"}}}.
77 64 Luci Stanescu
  [[BR]]uri:[[BR]]
78 64 Luci Stanescu
  The uri which was queried for. 
79 64 Luci Stanescu
80 64 Luci Stanescu
=== Route ===
81 64 Luci Stanescu
82 64 Luci Stanescu
This is a convinience object which contains sufficient information to identify a route to a SIP proxy. This object is returned by {{{DNSLookup.lookup_sip_proxy}}} and can be used with the {{{Session}}} or a {{{(Frozen)RouteHeader}}} can be easily constructed from it to pass to one of the objects in the SIP core handling SIP dialogs/transactions ({{{Invitation}}}, {{{Subscription}}}, {{{Request}}}, {{{Registration}}}, {{{Message}}}, {{{Publication}}}). This object has three attributes which can be set in the constructor or after it was instantiated. They will only be documented as arguments to the constructor.
83 64 Luci Stanescu
84 64 Luci Stanescu
==== methods ====
85 64 Luci Stanescu
86 64 Luci Stanescu
 '''!__init!__'''(''self'', '''address''', '''port'''=None, '''transport'''={{{'udp'}}})::
87 64 Luci Stanescu
  Creates the Route object with the specified parameters as attributes.
88 64 Luci Stanescu
  Each of these attributes can be accessed on the object once instanced.
89 64 Luci Stanescu
  [[BR]]''address'':[[BR]]
90 64 Luci Stanescu
  The IPv4 address that the request in question should be sent to as a string.
91 64 Luci Stanescu
  [[BR]]''port'':[[BR]]
92 64 Luci Stanescu
  The port to send the requests to, represented as an int, or None if the default port is to be used.
93 64 Luci Stanescu
  [[BR]]''transport'':[[BR]]
94 64 Luci Stanescu
  The transport to use, this can be a string of either "udp", "tcp" or "tls" (case insensitive).
95 64 Luci Stanescu
 '''get_uri'''(''self'')::
96 64 Luci Stanescu
  Returns a {{{SIPURI}}} object which contains the adress, port and transport as parameter. This can be used to easily construct a {{{RouteHeader}}}:
97 64 Luci Stanescu
  {{{
98 64 Luci Stanescu
    route = Route("1.2.3.4", port=1234, transport="tls")
99 64 Luci Stanescu
    route_header = RouteHeader(route.get_uri())
100 64 Luci Stanescu
  }}}
101 64 Luci Stanescu
102 62 Luci Stanescu
== High-level audio API ==
103 62 Luci Stanescu
104 62 Luci Stanescu
The high-level audio API hides the complexity of using the low-level PJMEDIA interface. This is implemented in the {{{sipsimple.audio}}} module and contains the following components:
105 62 Luci Stanescu
 * IAudioPort: an interface describing an object capable of producing and/or consuming audio data.
106 62 Luci Stanescu
 * AudioDevice: an object conforming to the IAudioPort interface which describes a physical audio device.
107 62 Luci Stanescu
 * AudioBridge: a collection of objects conforming to IAudioPort which connects all of them in a full mesh.
108 62 Luci Stanescu
 * WavePlayer: an object conforming to the IAudioPort interface which can playback the audio data from a {{{.wav}}} file.
109 62 Luci Stanescu
 * WaveRecorder: an object conforming to the IAudioPort interface which can record audio data to a {{{.wav}}} file.
110 62 Luci Stanescu
111 62 Luci Stanescu
=== IAudioPort ===
112 62 Luci Stanescu
113 62 Luci Stanescu
The IAudioPort interface describes an object capable of producing and/or consuming audio data. This can be a dynamic object, which changes its role during its lifetime and notifies such changes using a notification, which is part of the interface.
114 62 Luci Stanescu
115 62 Luci Stanescu
==== attributes ====
116 62 Luci Stanescu
117 62 Luci Stanescu
 '''mixer'''::
118 62 Luci Stanescu
  The {{{AudioMixer}}} this audio object is connected to. Only audio objects connected to the same mixer will be able to send audio data from one to another.
119 62 Luci Stanescu
 '''consumer_slot'''::
120 62 Luci Stanescu
  An integer representing the slot (see [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to consume audio data, or {{{None}}} if this object is not a consumer.
121 62 Luci Stanescu
 '''producer_slot'''::
122 62 Luci Stanescu
  An integer representing the slot (see [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to produce audio data, or {{{None}}} if this object is not a producer.
123 62 Luci Stanescu
124 62 Luci Stanescu
==== notifications ====
125 62 Luci Stanescu
 
126 62 Luci Stanescu
 '''AudioPortDidChangeSlots'''::
127 62 Luci Stanescu
  This notification needs to be sent by implementations of this interface when the slots it has change, so as to let the {{{AudioBridges}}} it is part of know that reconnections need to be made.
128 62 Luci Stanescu
  [[BR]]consumer_slot_changed:[[BR]]
129 62 Luci Stanescu
  A bool indicating whether the consumer slot was changed.
130 62 Luci Stanescu
  [[BR]]producer_slot_changed:[[BR]]
131 62 Luci Stanescu
  A bool indicating whether the producer slot was changed.
132 62 Luci Stanescu
  [[BR]]old_consumer_slot:[[BR]]
133 62 Luci Stanescu
  The old slot for consuming audio data. Only required if consumer_slot_changed is {{{True}}}.
134 62 Luci Stanescu
  [[BR]]new_consumer_slot:[[BR]]
135 62 Luci Stanescu
  The new slot for consuming audio data. Only required if consumer_slot_changed is {{{True}}}.
136 62 Luci Stanescu
  [[BR]]old_producer_slot:[[BR]]
137 62 Luci Stanescu
  The old slot for producing audio data. Only required if producer_slot_changed is {{{True}}}.
138 62 Luci Stanescu
  [[BR]]new_producer_slot:[[BR]]
139 62 Luci Stanescu
  The new slot for producing audio data. Only required if producer_slot_changed is {{{True}}}.
140 62 Luci Stanescu
141 62 Luci Stanescu
=== AudioDevice ===
142 62 Luci Stanescu
143 62 Luci Stanescu
The AudioDevice represents the physical audio device which is part of a {{{AudioMixer}}}, implementing the {{{IAudioPort}}} interface. As such, it can be uniquely identified by the mixer it represents.
144 62 Luci Stanescu
145 62 Luci Stanescu
==== methods ====
146 62 Luci Stanescu
147 62 Luci Stanescu
 '''!__init!__'''(''self'', '''mixer''', '''input_muted'''={{{False}}}, '''output_muted'''={{{False}}}):
148 62 Luci Stanescu
  Instantiates a new AudioDevice which represents the physical device associated with the specified {{{AudioMixer}}}.
149 62 Luci Stanescu
  [[BR]]mixer:[[BR]]
150 62 Luci Stanescu
  The {{{AudioMixer}}} whose physical device this object represents.
151 62 Luci Stanescu
  [[BR]]input_muted:[[BR]]
152 62 Luci Stanescu
  A boolean which indicates whether this object should act as a producer of audio data.
153 62 Luci Stanescu
  [[BR]]output_muted:[[BR]]
154 62 Luci Stanescu
  A boolean which indicates whether this object should act as a consumer of audio data.
155 62 Luci Stanescu
156 62 Luci Stanescu
==== attributes ====
157 62 Luci Stanescu
158 62 Luci Stanescu
 '''input_muted'''::
159 62 Luci Stanescu
  A writable property which controls whether this object should act as a producer of audio data. An {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within the {{{AudioBridges}}} this object is part of.
160 62 Luci Stanescu
 '''output_muted'''::
161 62 Luci Stanescu
  A writable property which controls whether this object should act as a consumer of audio data. An {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within  the {{{AudioBridges}}} this object is part of.
162 62 Luci Stanescu
163 62 Luci Stanescu
=== AudioBridge ===
164 62 Luci Stanescu
165 62 Luci Stanescu
The {{{AudioBridge}}} is the basic component which is able to connect {{{IAudioPort}}} implementations. It acts as a container which connects as the producers to all the consumers which are part of it. An object which is both a producer and a consumer of audio data will not be connected to itself. Being an implementation of {{{IAudioPort}}} itself, an {{{AudioBridge}}} can be part of another {{{AudioBridge}}}. The {{{AudioBridge}}} does not keep strong references to the ports it contains and once the port's reference count reaches 0, it is automatically removed from the {{{AudioBridge}}}.
166 62 Luci Stanescu
> Note: although this is not enforced, there should never be any cycles when connecting {{{AudioBridges}}}.
167 62 Luci Stanescu
168 62 Luci Stanescu
==== methods ====
169 62 Luci Stanescu
170 62 Luci Stanescu
 '''!__init!__'''(''self'', '''mixer''')::
171 62 Luci Stanescu
  Instantiate a new {{{AudioBridge}}} which uses the specified {{{AudioMixer}}} for mixing.
172 62 Luci Stanescu
 '''add'''(''self'', '''port''')::
173 62 Luci Stanescu
  Add an implementation of {{{IAudioPort}}} to this AudioBridge. This will connect the new port to all the existing ports of the bridge. A port cannot be added more than once to an {{{AudioBridge}}}; thus, this object acts like a set.
174 62 Luci Stanescu
 '''remove'''(''self'', '''port''')::
175 62 Luci Stanescu
  Remove a port from this {{{AudioBridge}}}. The port must have previously been added to the {{{AudioBridge}}}, otherwise a {{{ValueError}}} is raised.
176 62 Luci Stanescu
177 62 Luci Stanescu
=== WavePlayer ===
178 62 Luci Stanescu
179 62 Luci Stanescu
A {{{WavePlayer}}} is an implementation of {{{IAudioPort}}} which is capable of producing audio data read from a {{{.wav}}} file. This object is completely reusable, as it can be started and stopped any number of times.
180 62 Luci Stanescu
181 62 Luci Stanescu
==== methods ====
182 62 Luci Stanescu
183 62 Luci Stanescu
 '''!__init!__'''(''self'', '''mixer''', '''filename''', '''volume'''={{{100}}}, '''loop_count'''={{{1}}}, '''pause_time'''={{{0}}}, '''initial_play'''={{{True}}})::
184 62 Luci Stanescu
  Instantiate a new {{{WavePlayer}}} which is capable of playing a {{{.wav}}} file repeatedly. All the parameters are available as attributes of the object, but should not be changed once the object has been started.
185 62 Luci Stanescu
  [[BR]]mixer:[[BR]]
186 62 Luci Stanescu
  The {{{AudioMixer}}} this object is connected to.
187 62 Luci Stanescu
  [[BR]]filename:[[BR]]
188 62 Luci Stanescu
  The full path to the {{{.wav}}} file from which audio data is to be read.
189 62 Luci Stanescu
  [[BR]]volume:[[BR]]
190 62 Luci Stanescu
  The volume at which the file should be played.
191 62 Luci Stanescu
  [[BR]]loop_count:[[BR]]
192 62 Luci Stanescu
  The number of times the file should be played, or {{{0}}} for infinity.
193 62 Luci Stanescu
  [[BR]]pause_time:[[BR]]
194 62 Luci Stanescu
  How many seconds to wait between successive plays of the file. 
195 62 Luci Stanescu
  [[BR]]initial_play:[[BR]]
196 62 Luci Stanescu
  Whether or not the file to play once the {{{WavePlayer}}} is started, or to wait {{{pause_time}}} seconds before the first play.
197 62 Luci Stanescu
 '''start'''(''self'')::
198 62 Luci Stanescu
  Start playing the {{{.wav}}} file.
199 62 Luci Stanescu
 '''stop'''(''self'')::
200 62 Luci Stanescu
  Stop playuing the {{{.wav}}} file immediately.
201 62 Luci Stanescu
202 62 Luci Stanescu
==== attributes ====
203 62 Luci Stanescu
204 62 Luci Stanescu
 '''is_active'''::
205 62 Luci Stanescu
  A boolean indicating whether or not this {{{WavePlayer}}} is currently playing.
206 62 Luci Stanescu
207 62 Luci Stanescu
==== notifications ====
208 62 Luci Stanescu
209 62 Luci Stanescu
 '''WavePlayerDidStart'''::
210 62 Luci Stanescu
  This notification is sent when the {{{WavePlayer}}} starts playing the file the first time after the {{{start()}}} method has been called.
211 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
212 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
213 62 Luci Stanescu
 '''WavePlayerDidEnd'''::
214 62 Luci Stanescu
  This notification is sent when the {{{WavePlayer}}} is done playing either as a result of playing the number of times it was told to, or because the {{{stop()}}} method has been called.
215 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
216 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
217 62 Luci Stanescu
 '''WavePlayerDidFail'''::
218 62 Luci Stanescu
  This notification is sent when the {{{WavePlayer}}} is not capable of playing the {{{.wav}}} file.
219 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
220 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
221 62 Luci Stanescu
  [[BR]]error:[[BR]]
222 62 Luci Stanescu
  The exception raised by the {{{WaveFile}}} which identifies the cause for not being able to play the {{{.wav}}} file.
223 62 Luci Stanescu
224 62 Luci Stanescu
=== WaveRecorder ===
225 62 Luci Stanescu
226 62 Luci Stanescu
A {{{WaveRecorder}}} is an implementation of {{{IAudioPort}}} is is capable of consuming audio data and writing it to a {{{.wav}}} file. Just like {{{WavePlayer}}}, this object is reusable: once stopped it can be started again, but if the filename attribute is not changed, the previously written file will be overwritten.
227 62 Luci Stanescu
228 62 Luci Stanescu
==== methods ====
229 62 Luci Stanescu
230 62 Luci Stanescu
 '''!__init!__'''(''self'', '''mixer''', '''filename''')::
231 62 Luci Stanescu
  Instantiate a new {{{WaveRecorder}}}.
232 62 Luci Stanescu
  [[BR]]mixer:[[BR]]
233 62 Luci Stanescu
  The {{{AudioMixer}}} this {{{WaveRecorder}}} is connected to.
234 62 Luci Stanescu
  [[BR]]filename:[[BR]]
235 62 Luci Stanescu
  The full path to the {{{.wav}}} file where this object should write the audio data. The file must be writable. The directories up to the file will be created if possible when the {{{start()}}} method is called.
236 62 Luci Stanescu
 '''start'''(''self'')::
237 62 Luci Stanescu
  Start consuming audio data and writing it to the {{{.wav}}} file. If this object is not part of an {{{AudioBridge}}}, not audio data will be written.
238 62 Luci Stanescu
 '''stop'''(''self'')::
239 62 Luci Stanescu
  Stop consuming audio data and close the {{{.wav}}} file.
240 62 Luci Stanescu
241 62 Luci Stanescu
==== attributes ====
242 62 Luci Stanescu
243 62 Luci Stanescu
 '''is_active'''::
244 62 Luci Stanescu
  A boolean indicating whether or not this {{{WaveRecorder}}} is currently recording audio data.
245 62 Luci Stanescu
246 1 Adrian Georgescu
== SIPApplication ==
247 1 Adrian Georgescu
248 62 Luci Stanescu
Implemented in [browser:sipsimple/application.py]
249 1 Adrian Georgescu
250 62 Luci Stanescu
Implements a high-level application responsable for starting and stopping various sub-systems required to implement a fully featured SIP User Agent application. The SIPApplication class is a Singleton and can be instantiated from any part of the code, obtaining a reference to the same object. The SIPApplication takes care of initializing the following components:
251 62 Luci Stanescu
 * the twisted thread
252 62 Luci Stanescu
 * the configuration system, via the [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager].
253 62 Luci Stanescu
 * the core [wiki:SipCoreApiDocumentation#Engine Engine] using the settings in the configuration
254 62 Luci Stanescu
 * the [wiki:SipMiddlewareApi#AccountManager AccountManager], using the accounts in the configuration
255 63 Luci Stanescu
 * the [wiki:SipMiddlewareApi#SessionManager SessionManager], in order to handle incoming sessions
256 62 Luci Stanescu
 * two [wiki:SipMiddlewareApi#AudioBridge AudioBridges], using the settings in the configuration
257 1 Adrian Georgescu
258 62 Luci Stanescu
The attributes in this class can be set and accessed on both this class and its subclasses, as they are implemented using descriptors which keep single value for each attribute, irrespective of the class from which that attribute is set/accessed. Usually, all attributes should be considered read-only.
259 1 Adrian Georgescu
260 62 Luci Stanescu
=== Methods  ===
261 62 Luci Stanescu
262 62 Luci Stanescu
 '''!__init!__'''(''self'')::
263 62 Luci Stanescu
  Instantiates a new SIPApplication.
264 62 Luci Stanescu
 '''start'''(''self'', '''config_backend''')::
265 62 Luci Stanescu
  Starts the {{{SIPApplication}}} which initializes all the components in the correct order. The {{{config_backend}}} is used to start the {{{ConfigurationManager}}}. If any error occurs with loading the configuration, the exception raised by the {{{ConfigurationManager}}} is propagated by this method and {{{SIPApplication}}} can be started again. After this, any fatal errors will result in the SIPApplication being stopped and unusable, which means the whole application will need to stop. This method returns as soon as the twisted thread has been started, which means the application must wait for the {{{SIPApplicationDidStart}}} notification in order to know that the application started.
266 62 Luci Stanescu
 '''stop'''(''self'')::
267 62 Luci Stanescu
  Stop all the components started by the SIPApplication. This method returns immediately, but a {{{SIPApplicationDidEnd}}} notification is sent when all the components have been stopped.
268 62 Luci Stanescu
269 1 Adrian Georgescu
=== Attributes ===
270 1 Adrian Georgescu
271 62 Luci Stanescu
 '''running'''::
272 62 Luci Stanescu
  {{{True}}} if the SIPApplication is running (it has been started and it has not been told to stop), {{{False}}} otherwise.
273 62 Luci Stanescu
 '''alert_audio_mixer'''::
274 62 Luci Stanescu
  The {{{AudioMixer}}} object created on the alert audio device as defined by the configuration (by SIPSimpleSettings.audio.alert_device).
275 62 Luci Stanescu
 '''alert_audio_bridge'''::
276 62 Luci Stanescu
  An {{{AudioBridge}}} where {{{IAudioPort}}} objects can be added to playback sound to the alert device.
277 62 Luci Stanescu
 '''alert_audio_device'''::
278 62 Luci Stanescu
  An {{{AudioDevice}}} which corresponds to the alert device as defined by the configuration. This will always be part of the alert_audio_bridge.
279 62 Luci Stanescu
 '''voice_audio_mixer'''::
280 62 Luci Stanescu
  The {{{AudioMixer}}} object created on the voice audio device as defined by the configuration (by SIPSimpleSettings.audio.input_device and SIPSimpleSettings.audio.output_device).
281 62 Luci Stanescu
 '''voice_audio_bridge'''::
282 62 Luci Stanescu
  An {{{AudioBridge}}} where {{{IAudioPort}}} objects can be added to playback sound to the output device or record sound from the input device.
283 62 Luci Stanescu
 '''voice_audio_device'''::
284 62 Luci Stanescu
  An {{{AudioDevice}}} which corresponds to the voice device as defined by the configuration. This will always be part of the voice_audio_bridge.
285 1 Adrian Georgescu
286 1 Adrian Georgescu
=== Notifications  ===
287 62 Luci Stanescu
288 62 Luci Stanescu
 '''SIPApplicationWillStart'''::
289 62 Luci Stanescu
  This notification is sent just after the configuration has been loaded and the twisted thread started, but before any other components have been initialized.
290 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
291 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
292 62 Luci Stanescu
 '''SIPApplicationDidStart'''::
293 62 Luci Stanescu
  This notification is sent when all the components have been initialized. Note: it doesn't mean that all components have succeeded, for example, the account might not have registered by this time, but the registration process will have started.
294 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
295 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
296 62 Luci Stanescu
 '''SIPApplicationWillEnd'''::
297 62 Luci Stanescu
  This notification is sent as soon as the {{{stop()}}} method has been called.
298 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
299 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
300 62 Luci Stanescu
 '''SIPApplicationDidEnd'''::
301 62 Luci Stanescu
  This notification is sent when all the components have been stopped. All components have been given reasonable time to shutdown gracefully, such as the account unregistering. However, because of factors outside the control of the middleware, such as network problems, some components might not have actually shutdown gracefully; this is needed because otherwise the SIPApplication could hang indefinitely (for example because the system is no longer connected to a network and it cannot be determined when it will be again).
302 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
303 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
304 62 Luci Stanescu
 '''SIPApplicationFailedToStartTLS'''::
305 62 Luci Stanescu
  This notification is sent when a problem arises with initializing the TLS transport. In this case, the Engine will be started without TLS support and this notification contains the error which identifies the cause for not being able to start the TLS transport.
306 62 Luci Stanescu
  [[BR]]timestamp:[[BR]]
307 62 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
308 62 Luci Stanescu
  [[BR]]error:[[BR]]
309 62 Luci Stanescu
  The exception raised by the Engine which identifies the cause for not being able to start the TLS transport.
310 50 Adrian Georgescu
311 1 Adrian Georgescu
312 63 Luci Stanescu
== SIP Sessions ==
313 1 Adrian Georgescu
314 63 Luci Stanescu
SIP sessions are supported by the {{{sipsimple.session.Session}}} class and independent stream classes, which need to implement the {{{sipsimple.streams.IMediaStream}}} interface. The {{{Session}}} class takes care of the signalling, while the streams offer the actual media support which is negotiated by the {{{Session}}}. The streams which are implemented in the SIP SIMPLE middleware are provided in modules within the {{{sipsimple.streams}}} package, but they are accessible for import directly from {{{sipsimple.streams}}}. Currently, the middleware implements two types of streams, one for RTP data, with a concrete implementation in the {{{AudioStream}}} class, and one for MSRP sessions, with concrete implementations in the {{{ChatStream}}}, {{{FileTransferStream}}} and {{{DesktopSharingStream}}} classes. However, the application can provide its own stream implementation, provided they respect the {{{IMediaStream}}} interface.
315 63 Luci Stanescu
316 65 Luci Stanescu
The {{{sipsimple.streams}}} module also provides a mechanism for automatically registering media streams in order for them to be used for incoming sessions. This is explained in more detail in [wiki:SpMiddlewareApi#MediaStreamRegistry MediaStreamRegistry].
317 65 Luci Stanescu
318 63 Luci Stanescu
=== Session ===
319 51 Adrian Georgescu
320 44 Adrian Georgescu
[[Image(sipsimple-session-state-machine.png, align=right, width=400)]]
321 1 Adrian Georgescu
322 1 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
323 26 Luci Stanescu
324 1 Adrian Georgescu
A {{{sipsimple.session.Session}}} object represents a complete SIP session between the local and a remote endpoints. Both incoming and outgoing sessions are represented by this class.
325 1 Adrian Georgescu
326 1 Adrian Georgescu
A {{{Session}}} instance is a stateful object, meaning that it has a {{{state}}} attribute and that the lifetime of the session traverses different states, from session creation to termination.
327 2 Adrian Georgescu
State changes are triggered by methods called on the object by the application or by received network events.
328 1 Adrian Georgescu
These states and their transitions are represented in the following diagram:
329 63 Luci Stanescu
330 1 Adrian Georgescu
Although these states are crucial to the correct operation of the {{{Session}}} object, an application using this object does not need to keep track of these states, as a set of notifications is also emitted, which provide all the necessary information to the application.
331 63 Luci Stanescu
332 63 Luci Stanescu
The {{{Session}}} is completely independent of the streams it contains, which need to be implementations of the {{{sipsimple.streams.IMediaStream}}} interface. This interface provides the API by which the {{{Session}}} communicates with the streams. This API should not be used by the application, unless it also provides stream implementations or a SIP INVITE session implementation.
333 63 Luci Stanescu
334 63 Luci Stanescu
==== methods ====
335 63 Luci Stanescu
336 63 Luci Stanescu
 '''!__init!__'''(''self'', '''account''')::
337 63 Luci Stanescu
  Creates a new {{{Session}}} object in the {{{None}}} state.
338 63 Luci Stanescu
  [[BR]]''account'':[[BR]]
339 63 Luci Stanescu
  The local account to be associated with this {{{Session}}}.
340 63 Luci Stanescu
 '''connect'''(''self'', '''to_header''', '''routes''', '''streams''')::
341 63 Luci Stanescu
  Will set up the {{{Session}}} as outbound and propose the new session to the specified remote party and move the state machine to the {{{outgoing}}} state.
342 63 Luci Stanescu
  Before contacting the remote party, a {{{SIPSessionNewOutgoing}}} notification will be emitted.
343 63 Luci Stanescu
  If there is a failure or the remote party rejected the offer, a {{{SIPSessionDidFail}}} notification will be sent.
344 63 Luci Stanescu
  Any time a ringing indication is received from the remote party, a {{{SIPSessionGotRingIndication}}} notification is sent.
345 63 Luci Stanescu
  If the remote party accepted the session, a {{{SIPSessionWillStart}}} notification will be sent, followed by a {{{SIPSessionDidStart}}} notification when the session is actually established.
346 63 Luci Stanescu
  This method may only be called while in the {{{None}}} state.
347 63 Luci Stanescu
  [[BR]]''to_header'':[[BR]]
348 63 Luci Stanescu
  A {{{sipsimple.core.ToHeader}}} object representing the remote identity to initiate the session to.
349 63 Luci Stanescu
  [[BR]]''routes'':[[BR]]
350 63 Luci Stanescu
  An iterable of {{{sipsimple.util.Route}}} objects, specifying the IP, port and transport to the outbound proxy.
351 63 Luci Stanescu
  These routes will be tried in order, until one of them succeeds.
352 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
353 63 Luci Stanescu
  A list of stream objects which will be offered to the remote endpoint.
354 63 Luci Stanescu
 '''send_ring_indication'''(''self'')::
355 63 Luci Stanescu
  Sends a 180 provisional response in the case of an incoming session.
356 63 Luci Stanescu
 '''accept'''(''self'', '''streams''')::
357 63 Luci Stanescu
  Calling this methods will accept an incoming session and move the state machine to the {{{accepting}}} state.
358 63 Luci Stanescu
  When there is a new incoming session, a {{{SIPSessionNewIncoming}}} notification is sent, after which the application can call this method on the sender of the notification.
359 63 Luci Stanescu
  After this method is called, {{{SIPSessionWillStart}}} followed by {{{SIPSessionDidStart}}} will be emitted, or {{{SIPSessionDidFail}}} on an error.
360 63 Luci Stanescu
  This method may only be called while in the {{{incoming}}} state.
361 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
362 63 Luci Stanescu
  A list of streams which needs to be a subset of the proposed streams which indicates which streams are to be accepted. All the other proposed streams will be rejected.
363 63 Luci Stanescu
 '''reject'''(''self'', '''code'''={{{603}}}, '''reason'''={{{None}}})::
364 63 Luci Stanescu
  Reject an incoming session and move it to the {{{terminaing}}} state, which eventually leads to the {{{terminated}}} state.
365 63 Luci Stanescu
  Calling this method will cause the {{{Session}}} object to emit a {{{SIPSessionDidFail}}} notification once the session has been rejected.
366 63 Luci Stanescu
  This method may only be called while in the {{{incoming}}} state.
367 63 Luci Stanescu
  [[BR]]''code'':[[BR]]
368 63 Luci Stanescu
  An integer which represents the SIP status code in the response which is to be sent. Usually, this is either 486 (Busy) or 603 (Decline/Busy Everywhere).
369 63 Luci Stanescu
  [[BR]]''reason'':[[BR]]
370 63 Luci Stanescu
  The string which is to be sent as the SIP status reason in the response, or None if PJSIP's default reason for the specified code is to be sent.
371 63 Luci Stanescu
 '''accept_proposal'''(''self'', '''streams''')::
372 63 Luci Stanescu
  When the remote party proposes to add some new streams, signaled by the {{{SIPSessionGotProposal}}} notification, the application can use this method to accept the stream(s) being proposed.
373 63 Luci Stanescu
  After calling this method a {{{SIPSessionGotAcceptProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a {{{SIPSessionHadProposalFailure}}} notification is sent and a rejection is sent to the remote party. As with any action which causes the streams in the session to change, a {{{SIPSessionDidRenegotiateStreams}}} notification is also sent.
374 63 Luci Stanescu
  This method may only be called while in the {{{received_proposal}}} state.
375 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
376 63 Luci Stanescu
  A list of streams which needs to be a subset of the proposed streams which indicates which streams are to be accepted. All the other proposed streams will be rejected.
377 63 Luci Stanescu
 '''reject_proposal'''(''self'', '''code'''={{{488}}}, '''reason'''={{{None}}})::
378 63 Luci Stanescu
  When the remote party proposes new streams that the application does not want to accept, this method can be used to reject the proposal, after which a {{{SIPSessionGotRejectProposal}}} or {{{SIPSessionHadProposalFailure}}} notification is sent.
379 63 Luci Stanescu
  This method may only be called while in the {{{received_proposal}}} state.
380 63 Luci Stanescu
  [[BR]]''code'':[[BR]]
381 63 Luci Stanescu
  An integer which represents the SIP status code in the response which is to be sent. Usually, this is 488 (Not Acceptable Here).
382 63 Luci Stanescu
  [[BR]]''reason'':[[BR]]
383 63 Luci Stanescu
  The string which is to be sent as the SIP status reason in the response, or None if PJSIP's default reason for the specified code is to be sent.
384 63 Luci Stanescu
 '''add_stream'''(''self'', '''stream''')::
385 63 Luci Stanescu
  Proposes a new stream to the remote party.
386 63 Luci Stanescu
  Calling this method will cause a {{{SIPSessionGotProposal}}} notification to be emitted.
387 63 Luci Stanescu
  After this, the state machine will move into the {{{sending_proposal}}} state until either a {{{SIPSessionGotAcceptProposal}}}, {{{SIPSessionGotRejectProposal}}} or {{{SIPSessionHadProposalFailure}}} notification is sent, informing the application if the remote party accepted the proposal. As with any action which causes the streams in the session to change, a {{{SIPSessionDidRenegotiateStreams}}} notification is also sent.
388 63 Luci Stanescu
  This method may only be called while in the {{{connected}}} state.
389 63 Luci Stanescu
 '''remove_stream'''(''self'', '''stream''')::
390 63 Luci Stanescu
  Stop the stream and remove it from the session, informing the remote party of this. Although technically this is also done via an SDP negotiation which may fail, the stream will always get remove (if the remote party refuses the re-INVITE, the result will be that the remote party will have a different view of the active streams than the local party).
391 63 Luci Stanescu
  This method may only be called while in the {{{connected}}} state.
392 63 Luci Stanescu
 '''cancel_proposal'''(''self'')::
393 63 Luci Stanescu
  This method cancels a proposal of adding a stream to the session by sending a CANCEL request. A {{{SIPSessionGotRejectProposal}}} notification will be sent with code 487.
394 63 Luci Stanescu
 '''hold'''(''self'')::
395 63 Luci Stanescu
  Put the streams of the session which support the notion of hold on hold.
396 63 Luci Stanescu
  This will cause a {{{SIPSessionDidChangeHoldState}}} notification to be sent.
397 63 Luci Stanescu
  This method may be called in any state and will send the re-INVITE as soon as it is possible.
398 63 Luci Stanescu
 '''unhold'''(''self'')::
399 63 Luci Stanescu
  Take the streams of the session which support the notion of hold out of hold.
400 63 Luci Stanescu
  This will cause a {{{SIPSessionDidChangeHoldState}}} notification to be sent.
401 63 Luci Stanescu
  This method may be called in any state and will send teh re-INVITE as soon as it is possible.
402 63 Luci Stanescu
 '''end'''(''self'')::
403 63 Luci Stanescu
  This method may be called any time after the {{{Session}}} has started in order to terminate the session by sending a BYE request.
404 1 Adrian Georgescu
  Right before termination a {{{SIPSessionWillEnd}}} notification is sent, after termination {{{SIPSessionDidEnd}}} is sent.
405 1 Adrian Georgescu
406 64 Luci Stanescu
==== attributes ====
407 1 Adrian Georgescu
408 1 Adrian Georgescu
 '''state'''::
409 1 Adrian Georgescu
  The state the object is currently in, being one of the states from the diagram above.
410 1 Adrian Georgescu
 '''account'''::
411 19 Ruud Klaver
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object that the {{{Session}}} is associated with.
412 1 Adrian Georgescu
  On an outbound session, this is the account the application specified on object instantiation.
413 1 Adrian Georgescu
 '''direction'''::
414 32 Adrian Georgescu
  A string indicating the direction of the initial negotiation of the session.
415 63 Luci Stanescu
  This can be either {{{None}}}, "incoming" or "outgoing".
416 63 Luci Stanescu
 '''transport'''::
417 1 Adrian Georgescu
  A string representing the transport this {{{Session}}} is using: {{{"udp"}}}, {{{"tcp"}}} or {{{"tls"}}}.
418 1 Adrian Georgescu
 '''start_time'''::
419 1 Adrian Georgescu
  The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started.
420 1 Adrian Georgescu
 '''stop_time'''::
421 1 Adrian Georgescu
  The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated.
422 1 Adrian Georgescu
 '''on_hold'''::
423 1 Adrian Georgescu
  Boolean indicating whether the session was put on hold, either by the local or the remote party.
424 1 Adrian Georgescu
 '''remote_user_agent'''::
425 1 Adrian Georgescu
  A string indicating the remote user agent, if it provided one.
426 63 Luci Stanescu
  Initially this will be {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never).
427 63 Luci Stanescu
 '''local_identity'''::
428 63 Luci Stanescu
  The {{{sipsimple.core.FrozenFromHeader}}} or {{{sipsimple.core.FrozenToHeader}}} identifying the local party, if the session is active, {{{None}}} otherwise.
429 63 Luci Stanescu
 '''remote_identity'''::
430 63 Luci Stanescu
  The {{{sipsimple.core.FrozenFromHeader}}} or {{{sipsimple.core.FrozenToHeader}}} identifying the remote party, if the session is active, {{{None}}} otherwise.
431 63 Luci Stanescu
 '''streams'''::
432 63 Luci Stanescu
  A list of the currently active streams in the {{{Session}}}.
433 63 Luci Stanescu
 '''proposed_streams'''::
434 1 Adrian Georgescu
  A list of the currently proposed streams in the {{{Session}}}, or {{{None}}} if there is no proposal in progress.
435 1 Adrian Georgescu
436 64 Luci Stanescu
==== notifications ====
437 1 Adrian Georgescu
438 1 Adrian Georgescu
 '''SIPSessionNewIncoming'''::
439 26 Luci Stanescu
  Will be sent when a new incoming {{{Session}}} is received.
440 63 Luci Stanescu
  The application should listen for this notification to get informed of incoming sessions.
441 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
442 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
443 1 Adrian Georgescu
  [[BR]]''streams'':[[BR]]
444 63 Luci Stanescu
  A list of streams that were proposed by the remote party.
445 1 Adrian Georgescu
 '''SIPSessionNewOutgoing'''::
446 1 Adrian Georgescu
  Will be sent when the applcation requests a new outgoing {{{Session}}}.
447 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
448 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
449 1 Adrian Georgescu
  [[BR]]''streams'':[[BR]]
450 63 Luci Stanescu
  A list of streams that were proposed to the remote party.
451 1 Adrian Georgescu
 '''SIPSessionGotRingIndication'''::
452 1 Adrian Georgescu
  Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing.
453 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
454 26 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
455 63 Luci Stanescu
 '''SIPSessionGotProvisionalResponse'''::
456 63 Luci Stanescu
  Will be sent whenever the {{{Session}}} receives a provisional response as a result of sending a (re-)INVITE.
457 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
458 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
459 63 Luci Stanescu
  [[BR]]''code'':[[BR]]
460 63 Luci Stanescu
  The SIP status code received.
461 63 Luci Stanescu
  [[BR]]''reason'':[[BR]]
462 63 Luci Stanescu
  The SIP status reason received.
463 1 Adrian Georgescu
 '''SIPSessionWillStart'''::
464 1 Adrian Georgescu
  Will be sent just before a {{{Session}}} completes negotiation.
465 1 Adrian Georgescu
  In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}.
466 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
467 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
468 1 Adrian Georgescu
 '''SIPSessionDidStart'''::
469 63 Luci Stanescu
  Will be sent when a {{{Session}}} completes negotiation and all the streams have started.
470 26 Luci Stanescu
  In terms of SIP this is sent after the {{{ACK}}} was sent or received.
471 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
472 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
473 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
474 63 Luci Stanescu
  The list of streams which now form the active streams of the {{{Session}}}.
475 1 Adrian Georgescu
 '''SIPSessionDidFail'''::
476 63 Luci Stanescu
  This notification is sent whenever the session fails before it starts.
477 5 Redmine Admin
  The failure reason is included in the data attributes.
478 63 Luci Stanescu
  This notification is never followed by {{{SIPSessionDidEnd}}}.
479 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
480 26 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
481 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
482 63 Luci Stanescu
  A string indicating the originator of the {{{Session}}}. This will either be "local" or "remote".
483 1 Adrian Georgescu
  [[BR]]''code'':[[BR]]
484 1 Adrian Georgescu
  The SIP error code of the failure.
485 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
486 63 Luci Stanescu
  A SIP status reason.
487 63 Luci Stanescu
  [[BR]]''failure_reason'':[[BR]]
488 63 Luci Stanescu
  A string which represents the reason for the failure, such as {{{"user_request"}}}, {{{"missing ACK"}}}, {{{"SIP core error..."}}}.
489 1 Adrian Georgescu
 '''SIPSessionWillEnd'''::
490 63 Luci Stanescu
  Will be sent just before terminating a {{{Session}}}.
491 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
492 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
493 1 Adrian Georgescu
 '''SIPSessionDidEnd'''::
494 63 Luci Stanescu
  Will be sent always when a {{{Session}}} ends as a result of remote or local session termination.
495 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
496 19 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
497 19 Ruud Klaver
  [[BR]]''originator'':[[BR]]
498 63 Luci Stanescu
  A string indicating who originated the termination. This will either be "local" or "remote".
499 63 Luci Stanescu
  [[BR]]''end_reason'':[[BR]]
500 63 Luci Stanescu
  A string representing the termination reason, such as {{{"user_request"}}}, {{{"SIP core error..."}}}.
501 63 Luci Stanescu
 '''SIPSessionDidChangeHoldState'''::
502 63 Luci Stanescu
  Will be sent when the session got put on hold or removed from hold, either by the local or the remote party.
503 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
504 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
505 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
506 1 Adrian Georgescu
  A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
507 63 Luci Stanescu
  [[BR]]''on_hold'':[[BR]]
508 63 Luci Stanescu
  {{{True}}} if there is at least one stream which is on hold and {{{False}}} otherwise.
509 63 Luci Stanescu
  [[BR]]''partial'':[[BR]]
510 63 Luci Stanescu
  {{{True}}} if there is at least one stream which is on hold and one stream which supports hold but is not on hold and {{{False}}} otherwise.
511 63 Luci Stanescu
 '''SIPSessionGotProposal'''::
512 63 Luci Stanescu
  Will be sent when either the local or the remote party proposes to add streams to the session.
513 26 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
514 23 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
515 23 Ruud Klaver
  [[BR]]''originator'':[[BR]]
516 63 Luci Stanescu
  The party that initiated the stream proposal, can be either "local" or "remote".
517 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
518 63 Luci Stanescu
  A list of streams that were proposed.
519 63 Luci Stanescu
 '''SIPSessionGotRejectProposal'''::
520 63 Luci Stanescu
  Will be sent when either the local or the remote party rejects a proposal to have streams added to the session.
521 6 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
522 6 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
523 63 Luci Stanescu
  [[BR]]''originator'':[[BR]]
524 63 Luci Stanescu
  The party that initiated the stream proposal, can be either "local" or "remote".
525 6 Ruud Klaver
  [[BR]]''code'':[[BR]]
526 63 Luci Stanescu
  The code with which the proposal was rejected.
527 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
528 63 Luci Stanescu
  The reason for rejecting the stream proposal.
529 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
530 63 Luci Stanescu
  The list of streams which were rejected.
531 63 Luci Stanescu
 '''SIPSessionGotAcceptProposal'''::
532 63 Luci Stanescu
  Will be sent when either the local or the remote party accepts a proposal to have stream( added to the session.
533 24 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
534 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
535 63 Luci Stanescu
  [[BR]]''originator'':[[BR]]
536 63 Luci Stanescu
  The party that initiated the stream proposal, can be either "local" or "remote".
537 1 Adrian Georgescu
  [[BR]]''streams'':[[BR]]
538 63 Luci Stanescu
  The list of streams which were accepted.
539 63 Luci Stanescu
 '''SIPSessionHadProposalFailure'''::
540 24 Ruud Klaver
  Will be sent when a re-INVITE fails because of an internal reason (such as a stream not being able to start).
541 24 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
542 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
543 63 Luci Stanescu
  [[BR]]''failure_reason'':[[BR]]
544 63 Luci Stanescu
  The error which caused the proposal to fail.
545 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
546 63 Luci Stanescu
  THe streams which were part of this proposal.
547 24 Ruud Klaver
 '''SIPSessionDidRenegotiateStreams'''::
548 6 Ruud Klaver
  Will be sent when a media stream is either activated or deactivated.
549 26 Luci Stanescu
  An application should listen to this notification in order to know when a media stream can be used.
550 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
551 6 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
552 63 Luci Stanescu
  [[BR]]''action'':[[BR]]
553 63 Luci Stanescu
  A string which is either {{{"add"}}} or {{{"remove"}}} which specifies what happened to the streams the notificaton referes to
554 63 Luci Stanescu
  [[BR]]''streams'':[[BR]]
555 63 Luci Stanescu
  A list with the streams which were added or removed.
556 63 Luci Stanescu
 '''SIPSessionDidProcessTransaction'''::
557 63 Luci Stanescu
  Will be sent whenever a SIP transaction is complete in order to provide low-level details of the progress of the INVITE dialog.
558 37 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
559 37 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
560 37 Luci Stanescu
  [[BR]]''originator'':[[BR]]
561 37 Luci Stanescu
  The initiator of the transaction, {{{"local"}}} or {{{"remote"}}}.
562 37 Luci Stanescu
  [[BR]]''method'':[[BR]]
563 37 Luci Stanescu
  The method of the request.
564 37 Luci Stanescu
  [[BR]]''code'':[[BR]]
565 37 Luci Stanescu
  The SIP status code of the response.
566 37 Luci Stanescu
  [[BR]]''reason'':[[BR]]
567 37 Luci Stanescu
  The SIP status reason of the response.
568 37 Luci Stanescu
  [[BR]]''ack_received'':[[BR]]
569 37 Luci Stanescu
  This attribute is only present for INVITE transactions and has one of the values {{{True}}}, {{{False}}} or {{{"unknown"}}}. The last value may occur then PJSIP does not let us know whether the ACK was received or not.
570 1 Adrian Georgescu
571 37 Luci Stanescu
As an example for how to use the {{{Session}}} object, the following provides a basic Python program that initiates an outgoing SIP session request:
572 37 Luci Stanescu
573 37 Luci Stanescu
{{{
574 37 Luci Stanescu
from threading import Event
575 50 Adrian Georgescu
576 48 Adrian Georgescu
from application.notification, NotificationCenter
577 37 Luci Stanescu
578 37 Luci Stanescu
from sipsimple.core import SIPURI, ToHeader
579 50 Adrian Georgescu
580 38 Luci Stanescu
from sipsimple.account import AccountManager
581 38 Luci Stanescu
from sipsimple.application import SIPApplication
582 38 Luci Stanescu
from sipsimple.session import Session
583 50 Adrian Georgescu
from sipsimple.streams import AudioStream
584 38 Luci Stanescu
from sipsimple.util import Route
585 1 Adrian Georgescu
586 38 Luci Stanescu
587 38 Luci Stanescu
class SimpleCallApplication(SIPApplication):
588 1 Adrian Georgescu
    def __init__(self, callee, route):
589 1 Adrian Georgescu
        SIPApplication.__init__(self)
590 1 Adrian Georgescu
        self.ended = Event()
591 1 Adrian Georgescu
        self.callee = calee
592 38 Luci Stanescu
        self.route = route
593 38 Luci Stanescu
        self.session = None
594 38 Luci Stanescu
        notification_center = NotificationCenter()
595 38 Luci Stanescu
        notification_center.add_observer(self)
596 1 Adrian Georgescu
597 1 Adrian Georgescu
    def _NH_SIPApplicationDidStart(self, notification):
598 1 Adrian Georgescu
        account = AccountManager().default_account
599 38 Luci Stanescu
        self.session = Session(account)
600 38 Luci Stanescu
        self.session.connect(self.callee, self.route, AudioStream(account))
601 1 Adrian Georgescu
602 38 Luci Stanescu
    def _NH_SIPSessionGotRingIndication(self, notification):
603 38 Luci Stanescu
        print 'Ringing!'
604 38 Luci Stanescu
605 38 Luci Stanescu
    def _NH_SIPSessionDidStart(self, notification):
606 38 Luci Stanescu
        print 'Session started!'
607 38 Luci Stanescu
608 38 Luci Stanescu
    def _NH_SIPSessionDidFail(self, notification):
609 38 Luci Stanescu
        print 'Failed to connect'
610 1 Adrian Georgescu
        self.stop()
611 38 Luci Stanescu
612 38 Luci Stanescu
    def _NH_SIPSessionDidEnd(self, notification):
613 38 Luci Stanescu
        print 'Session ended'
614 1 Adrian Georgescu
        self.stop()
615 1 Adrian Georgescu
616 39 Luci Stanescu
    def _NH_SIPApplicationDidEnd(self, notification):
617 50 Adrian Georgescu
        self.ended.set()
618 39 Luci Stanescu
619 39 Luci Stanescu
# place an audio call from the specified account to the specified URI, through
620 39 Luci Stanescu
# the specified SIP proxy
621 39 Luci Stanescu
application = SimpleCallApplication(ToHeader(SIPURI(user="bob", host="example.com")), Route("1.2.3.4"))
622 39 Luci Stanescu
# block waiting for user input
623 39 Luci Stanescu
print "Placing call, press enter to quit program"
624 39 Luci Stanescu
raw_input()
625 39 Luci Stanescu
application.session.end()
626 39 Luci Stanescu
# block until the SIPApplication has stopped
627 1 Adrian Georgescu
application.ended.wait()
628 50 Adrian Georgescu
}}}
629 48 Adrian Georgescu
630 64 Luci Stanescu
=== SessionManager ===
631 39 Luci Stanescu
632 39 Luci Stanescu
Implemented in [browser:sipsimple/session.py]
633 39 Luci Stanescu
634 1 Adrian Georgescu
The {{{sipsimple.session.SessionManager}}} class is a singleton, which acts as the central aggregation point for sessions within the middleware.
635 50 Adrian Georgescu
Although it is mainly used internally, the application can use it to query information about all active sessions.
636 39 Luci Stanescu
The SessionManager is implemented as a singleton, meaning that only one instance of this class exists within the middleware. The SessionManager is started by the SIPApplication and takes care of handling incoming sessions.
637 39 Luci Stanescu
638 64 Luci Stanescu
==== attributes ====
639 39 Luci Stanescu
640 39 Luci Stanescu
 '''sessions'''::
641 39 Luci Stanescu
  A property providing a copy of the list of all active {{{Sesssion}}} objects within the application, meaning any {{{Session}}} object that exists globally within the application and is not in the {{{NULL}}} or {{{TERMINATED}}} state.
642 39 Luci Stanescu
643 64 Luci Stanescu
==== methods ====
644 39 Luci Stanescu
645 39 Luci Stanescu
 '''!__init!__'''(''self'')::
646 39 Luci Stanescu
  Instantiate a new {{{SessionManager}}} object.
647 39 Luci Stanescu
648 39 Luci Stanescu
 '''start'''(''self'')::
649 39 Luci Stanescu
  Start the {{{SessionManager}}} in order to be able to handle incoming sessions.
650 1 Adrian Georgescu
651 65 Luci Stanescu
=== IMediaStream ===
652 39 Luci Stanescu
653 39 Luci Stanescu
Implemented in [browser:sipsimple/streams/__init__.py]
654 1 Adrian Georgescu
655 65 Luci Stanescu
This interface describes the API which the {{{Session}}} uses to communicate with the streams. All streams used by the {{{Session}}} __must__ respect this interface.
656 1 Adrian Georgescu
657 66 Luci Stanescu
==== methods ====
658 1 Adrian Georgescu
659 1 Adrian Georgescu
 '''!__init!__'''(''self'', ''account'')::
660 65 Luci Stanescu
  Initializes the generic stream instance.
661 1 Adrian Georgescu
 '''new_from_sdp'''(''cls'', ''account'', ''remote_sdp'', ''stream_index'')::
662 65 Luci Stanescu
  A classmethod which returns an instance of this stream implementation if the sdp is accepted by the stream or None otherwise.
663 65 Luci Stanescu
  [[BR]]account:[[BR]]
664 65 Luci Stanescu
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object the session which this stream would be part of is associated with.
665 65 Luci Stanescu
  [[BR]]remote_sdp:[[BR]]
666 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which was received by the remote offer.
667 65 Luci Stanescu
  [[BR]]stream_index:[[BR]]
668 65 Luci Stanescu
  An integer representing the index within the list of media streams within the whole SDP which this stream would be instantiated for. 
669 1 Adrian Georgescu
 '''get_local_media'''(''self'', ''for_offer'')::
670 65 Luci Stanescu
  Return an {{{SDPMediaStream}}} which represents an offer for using this stream if {{{for_offer}}} is {{{True}}} and a response to an SDP proposal otherwise.
671 65 Luci Stanescu
  [[BR]]for_offer:[[BR]]
672 65 Luci Stanescu
  {{{True}}} if the {{{SDPMediaStream}}} will be used for an SDP proposal and {{{False}}} if for a response.
673 1 Adrian Georgescu
 '''initialize'''(''self'', ''session'', ''direction'')::
674 65 Luci Stanescu
  Initializes the stream. This method will get called as soon as the stream is known to be at least offered as part of the {{{Session}}}. If initialization goes fine, the stream must send a {{{MediaStreamDidInitialize}}} notification or a {{{MediaStreamDidFail}}} notification otherwise.
675 65 Luci Stanescu
  [[BR]]session:[[BR]]
676 65 Luci Stanescu
  The {{{Session}}} object this stream will be part of.
677 65 Luci Stanescu
  [[BR]]direction:[[BR]]
678 65 Luci Stanescu
  {{{"incoming"}}} if the stream was created because of a received proposal and {{{"outgoing"}}} if a proposal was sent. Note that this need not be the same as the initial direction of the {{{Session}}} since streams can be proposed in either way using re-INVITEs.
679 1 Adrian Georgescu
 '''start'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
680 65 Luci Stanescu
  Starts the stream. This method will be called as soon is known to be used in the {{{Session}}} (eg. only called for an incoming proposal if the local party accepts the proposed stream). If starting succeeds, the stream must send a {{{MediaStreamDidStart}}} notification or a {{{MediaStreamDidFail}}} notification otherwise.
681 65 Luci Stanescu
  [[BR]]local_sdp:[[BR]]
682 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which is used by the local endpoint.
683 65 Luci Stanescu
  [[BR]]remote_sdp:[[BR]]
684 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which is used by the remote endpoint.
685 65 Luci Stanescu
  [[BR]]stream_index:[[BR]]
686 65 Luci Stanescu
  An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
687 1 Adrian Georgescu
 '''validate_update'''(''self'', ''remote_sdp'', ''stream_index'')::
688 65 Luci Stanescu
  This method will be called when a re-INVITE is received which changes the parameters of the stream within the SDP. The stream must return {{{True}}} if the changes are acceptable or {{{False}}} otherwise. If any changed streams return {{{False}}} for a re-INVITE, the re-INVITE will be refused with a negative response. This means that streams must not changed any internal data when this method is called as the update is not guaranteed to be applied even if the stream returns {{{True}}}. 
689 65 Luci Stanescu
  [[BR]]remote_sdp:[[BR]]
690 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which is used by the remote endpoint.
691 65 Luci Stanescu
  [[BR]]stream_index:[[BR]]
692 65 Luci Stanescu
  An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
693 1 Adrian Georgescu
 '''update'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
694 65 Luci Stanescu
  This method is called when the an SDP negotiation initiated by either the local party or the remote party succeeds. The stream must update its internal state according to the new SDP in use.
695 65 Luci Stanescu
  [[BR]]local_sdp:[[BR]]
696 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which is used by the local endpoint.
697 65 Luci Stanescu
  [[BR]]remote_sdp:[[BR]]
698 65 Luci Stanescu
  The {{{FrozenSDPSession}}} which is used by the remote endpoint.
699 65 Luci Stanescu
  [[BR]]stream_index:[[BR]]
700 65 Luci Stanescu
  An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
701 55 Adrian Georgescu
 '''hold'''(''self'')::
702 65 Luci Stanescu
  Puts the stream on hold if supported by the stream. Typically used by audio and video streams. The stream must immediately stop sending/receiving data and calls to {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state.
703 55 Adrian Georgescu
 '''unhold'''(''self'')::
704 65 Luci Stanescu
  Takes the stream off hold. Typically used by audio and video streams. Calls to {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state.
705 65 Luci Stanescu
 '''deactivate'''(''self'')::
706 65 Luci Stanescu
  This method is called on a stream just before the stream will be removed from the {{{Session}}} (either as a result of a re-INVITE or a BYE). This method is needed because it avoids a race condition with streams using stateful protocols such as TCP: the stream connection might be terminated before the SIP signalling announces this due to network routing inconsistencies and the other endpoint would not be able to distinguish between this case and an error which caused the stream transport to fail. The stream must not take any action, but must consider that the transport being closed by the other endpoint after this method was called as a normal situation rather than an error condition.
707 65 Luci Stanescu
 '''end'''(''self'')::
708 65 Luci Stanescu
  Ends the stream. This must close the underlying transport connection. The stream must send a {{{MediaStreamWillEnd}}} just after this method is called and a {{{MediaStreamDidEnd}}} as soon as the operation is complete. This method is always be called by the {{{Session}}} on the stream if at least the {{{initialize()}}} method has been called. This means that once a stream sends the {{{MediaStreamDidFail}}} notification, the {{{Session}}} will still call this method.
709 55 Adrian Georgescu
710 65 Luci Stanescu
==== atributes ====
711 55 Adrian Georgescu
712 65 Luci Stanescu
 '''type''' (class attribute)::
713 65 Luci Stanescu
  A string identifying the stream type (eg: {{{"audio"}}}, {{{"video"}}}).
714 65 Luci Stanescu
 '''priority''' (class attribute)::
715 65 Luci Stanescu
  An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority).
716 65 Luci Stanescu
 '''hold_supported'''::
717 65 Luci Stanescu
  True if the stream supports hold
718 65 Luci Stanescu
 '''on_hold_by_local'''::
719 65 Luci Stanescu
  True if the stream is on hold by the local party
720 65 Luci Stanescu
 '''on_hold_by_remote'''::
721 65 Luci Stanescu
  True if the stream is on hold by the remote
722 65 Luci Stanescu
 '''on_hold'''::
723 65 Luci Stanescu
  True if either on_hold_by_local or on_hold_by_remote is true
724 55 Adrian Georgescu
725 65 Luci Stanescu
==== notifications ====
726 65 Luci Stanescu
727 65 Luci Stanescu
These notifications must be generated by all streams in order for the {{{Session}}} to know the state of the stream.
728 65 Luci Stanescu
729 55 Adrian Georgescu
 '''MediaStreamDidInitialize'''::
730 65 Luci Stanescu
  Sent when the stream has been successfully initialized.
731 55 Adrian Georgescu
 '''MediaStreamDidStart'''::
732 65 Luci Stanescu
  Sent when the stream has been successfully started.
733 55 Adrian Georgescu
 '''MediaStreamDidFail'''::
734 65 Luci Stanescu
  Sent when the stream has failed either as a result of calling one of its methods, or during the normal operation of the stream (such as the transport connection being closed).
735 55 Adrian Georgescu
 '''MediaStreamWillEnd'''::
736 65 Luci Stanescu
  Sent immediately after the {{{end()}}} method is called.
737 55 Adrian Georgescu
 '''MediaStreamDidEnd'''::
738 65 Luci Stanescu
  Sent when the {{{end()}}} method finished closing the stream.
739 55 Adrian Georgescu
740 66 Luci Stanescu
=== MediaStreamRegistry ===
741 55 Adrian Georgescu
742 66 Luci Stanescu
The MediaStream registry is a collection of classes which implement {{{IMediaStream}}}. This collection is used by the {{{Session}}} to select a stream class for instantiation in the case of an incomming session. The streams are included in the collection in the descending order of their priority. Thus, streams with a higher priority will be tried first by the {{{Session}}}. This object is a Singleton so references to the same object can be obtained by a simple instantiation.
743 1 Adrian Georgescu
744 66 Luci Stanescu
There are several pre-built streams based on the {{{IMediaStream}}} API:
745 66 Luci Stanescu
 * {{{sipsimple.streams.rtp.AudioStream}}} - Audio stream based on RTP
746 1 Adrian Georgescu
 * {{{sipsimple.streams.msrp.ChatStream}}} - Chat stream based on MSRP 
747 1 Adrian Georgescu
 * {{{sipsimple.streams.msrp.FileTransferStream}}} - File Transfer stream based on MSRP 
748 66 Luci Stanescu
 * {{{sipsimple.streams.msrp.DesktopSharingStream}}} -  Desktop Sharing stream based on VNC over MSRP
749 1 Adrian Georgescu
750 66 Luci Stanescu
Other streams which are created by the application must be registered in this registry. For a simple way of doing this, see [wiki:SipMiddlewareApi#MediaStreamRegistrar MediaStreamRegistrar].
751 66 Luci Stanescu
752 66 Luci Stanescu
==== methods ====
753 66 Luci Stanescu
754 66 Luci Stanescu
 '''!__init!__'''(''self'')::
755 66 Luci Stanescu
  Instantiate the MediaStreamRegistry. This will be called just once when first (and only) instance is created.
756 66 Luci Stanescu
 '''!__iter!__'''(''self'')::
757 66 Luci Stanescu
  This method allows the registry to be iterated through and will return classes which were registered to it.
758 66 Luci Stanescu
 '''add'''(''self'', '''cls''')::
759 66 Luci Stanescu
  Add {{{cls}}} to the registry of streams. The class must implement the {{{IMediaStream}}} interface.
760 66 Luci Stanescu
761 66 Luci Stanescu
=== MediaStreamRegistrar ===
762 66 Luci Stanescu
763 66 Luci Stanescu
This is a convenience metaclass which automatically registers a defined class with the {{{MediaStreamRegistry}}}. In order to use this class, one simply needs to use it as the metaclass of the new stream.
764 66 Luci Stanescu
765 66 Luci Stanescu
{{{
766 66 Luci Stanescu
from zope.interface import implements
767 66 Luci Stanescu
768 66 Luci Stanescu
from sipsimple.streams import IMediaStream, MediaStreamRegistrar
769 66 Luci Stanescu
770 66 Luci Stanescu
771 66 Luci Stanescu
class MyStream(object):
772 66 Luci Stanescu
  __metaclass__ = MediaStreamRegistrar
773 66 Luci Stanescu
774 66 Luci Stanescu
  implements(IMediaStream)
775 66 Luci Stanescu
  
776 66 Luci Stanescu
[...] 
777 66 Luci Stanescu
}}}
778 55 Adrian Georgescu
779 67 Luci Stanescu
=== AudioStream ===
780 55 Adrian Georgescu
781 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/rtp.py]
782 55 Adrian Georgescu
783 67 Luci Stanescu
The {{{AudioStream}}} is an implementation of {{{IMediaStream}}} which supports audio data using the {{{AudioTransport}}} and {{{RTPTransport}}} of the SIP core. As such, it provides all features of these objects, including ICE negotiation. An example SDP created using the {{{AudioStream}}} is provided below:
784 55 Adrian Georgescu
785 55 Adrian Georgescu
{{{
786 55 Adrian Georgescu
Content-Type: application/sdp
787 55 Adrian Georgescu
Content-Length:  1093
788 55 Adrian Georgescu
789 55 Adrian Georgescu
v=0
790 55 Adrian Georgescu
o=- 3467525278 3467525278 IN IP4 192.168.1.6
791 55 Adrian Georgescu
s=blink-0.10.7-beta
792 55 Adrian Georgescu
c=IN IP4 80.101.96.20
793 55 Adrian Georgescu
t=0 0
794 57 Adrian Georgescu
m=audio 55328 RTP/AVP 104 103 102 3 9 0 8 101
795 57 Adrian Georgescu
a=rtcp:55329 IN IP4 80.101.96.20
796 57 Adrian Georgescu
a=rtpmap:104 speex/32000
797 57 Adrian Georgescu
a=rtpmap:103 speex/16000
798 57 Adrian Georgescu
a=rtpmap:102 speex/8000
799 57 Adrian Georgescu
a=rtpmap:3 GSM/8000
800 57 Adrian Georgescu
a=rtpmap:9 G722/8000
801 57 Adrian Georgescu
a=rtpmap:0 PCMU/8000
802 57 Adrian Georgescu
a=rtpmap:8 PCMA/8000
803 57 Adrian Georgescu
a=rtpmap:101 telephone-event/8000
804 57 Adrian Georgescu
a=fmtp:101 0-15
805 57 Adrian Georgescu
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:esI6DbLY1+Aceu0JNswN9Z10DcFx5cZwqJcu91jb
806 57 Adrian Georgescu
a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:SHuEMm1BYJqOF4udKl73EaCwnsI57pO86bYKsg70
807 57 Adrian Georgescu
a=ice-ufrag:2701ed80
808 57 Adrian Georgescu
a=ice-pwd:6f8f8281
809 57 Adrian Georgescu
a=candidate:S 1 UDP 31 80.101.96.20 55328 typ srflx raddr 192.168.1.6 rport 55328
810 57 Adrian Georgescu
a=candidate:H 1 UDP 23 192.168.1.6 55328 typ host
811 57 Adrian Georgescu
a=candidate:H 1 UDP 23 10.211.55.2 55328 typ host
812 57 Adrian Georgescu
a=candidate:H 1 UDP 23 10.37.129.2 55328 typ host
813 57 Adrian Georgescu
a=candidate:S 2 UDP 30 80.101.96.20 55329 typ srflx raddr 192.168.1.6 rport 55329
814 57 Adrian Georgescu
a=candidate:H 2 UDP 22 192.168.1.6 55329 typ host
815 57 Adrian Georgescu
a=candidate:H 2 UDP 22 10.211.55.2 55329 typ host
816 57 Adrian Georgescu
a=candidate:H 2 UDP 22 10.37.129.2 55329 typ host
817 57 Adrian Georgescu
a=sendrecv
818 57 Adrian Georgescu
}}}
819 1 Adrian Georgescu
820 67 Luci Stanescu
As an implementation of {{{IAudioPort}}}, an {{{AudioStream}}} can be added to an {{{AudioBridge}}} to send or to read audio data to/from other audio objects. It is connected to the voice {{{AudioMixer}}} ({{{SIPApplication.voice_audio_mixer}}}) so it can only be added to bridges using the same {{{AudioMixer}}}. It also contains an {{{AudioBridge}}} on the {{{bridge}}} attribute which always contains an {{{AudioDevice}}} corresponding to the input and output devices; when the stream is active (started and not on hold), the bridge also contains the stream itself and when recording is active, the stream contains a {{{WaveRecorder}}} which records audio data.
821 1 Adrian Georgescu
822 67 Luci Stanescu
==== methods ====
823 67 Luci Stanescu
824 67 Luci Stanescu
 '''start_recording'''(''self'', '''filename'''={{{None}}})::
825 67 Luci Stanescu
  If an audio stream is present within this session, calling this method will record the audio to a {{{.wav}}} file.
826 67 Luci Stanescu
  Note that when the session is on hold, nothing will be recorded to the file.
827 67 Luci Stanescu
  Right before starting the recording a {{{SIPSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SIPSessionDidStartRecordingAudio}}}.
828 67 Luci Stanescu
  This method may only be called while the stream is started.
829 67 Luci Stanescu
  [[BR]]''filename'':[[BR]]
830 67 Luci Stanescu
  The name of the {{{.wav}}} file to record to.
831 67 Luci Stanescu
  If this is set to {{{None}}}, a default file name including the session participants and the timestamp will be generated using the directory defined in the configuration.
832 67 Luci Stanescu
 '''stop_recording'''(''self'')::
833 67 Luci Stanescu
  This will stop a previously started recording.
834 67 Luci Stanescu
  Before stopping, a {{{SIPSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SIPSessionDidStopRecordingAudio}}}.
835 67 Luci Stanescu
 '''send_dtmf'''(''self'', '''digit''')::
836 67 Luci Stanescu
  If the audio stream is started, sends a DTMF digit to the remote party.
837 67 Luci Stanescu
  [[BR]]''digit'':[[BR]]
838 67 Luci Stanescu
  This should a string of length 1, containing a valid DTMF digit value (0-9, A-D, * or #).
839 67 Luci Stanescu
840 67 Luci Stanescu
==== attributes ====
841 67 Luci Stanescu
842 63 Luci Stanescu
 '''sample_rate'''::
843 63 Luci Stanescu
  If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
844 63 Luci Stanescu
 '''codec'''::
845 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
846 1 Adrian Georgescu
 '''srtp_active'''::
847 1 Adrian Georgescu
  If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
848 67 Luci Stanescu
 '''ice_active'''::
849 67 Luci Stanescu
  {{{True}}} if the ICE candidates negotiated are being used, {{{False}}} otherwise.
850 1 Adrian Georgescu
 '''local_rtp_address'''::
851 1 Adrian Georgescu
  If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
852 1 Adrian Georgescu
 '''local_rtp_port'''::
853 1 Adrian Georgescu
  If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
854 1 Adrian Georgescu
 '''remote_rtp_address_sdp'''::
855 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
856 1 Adrian Georgescu
 '''remote_rtp_port_sdp'''::
857 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
858 1 Adrian Georgescu
 '''remote_rtp_address_received'''::
859 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
860 1 Adrian Georgescu
 '''remote_rtp_port_received'''::
861 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
862 67 Luci Stanescu
 '''local_rtp_candidate_type'''::
863 67 Luci Stanescu
  The local ICE candidate type which was selected by the ICE negotiation if it succeeded and {{{None}}} otherwise.
864 67 Luci Stanescu
 '''remote_rtp_candidate_type'''::
865 67 Luci Stanescu
  The remote ICE candidate type which was selected by the ICE negotiation if it succeeded and {{{None}}} otherwise.
866 67 Luci Stanescu
 '''recording_filename'''::
867 63 Luci Stanescu
  If the audio stream is currently being recorded to disk, this property contains the name of the {{{.wav}}} file being recorded to.
868 63 Luci Stanescu
869 67 Luci Stanescu
==== notifications ====
870 55 Adrian Georgescu
871 55 Adrian Georgescu
 '''AudioStreamDidChangeHoldState'''::
872 67 Luci Stanescu
  Will be sent when the hold state is changed as a result of either a SIP message received on the network or the application calling the {{{hold()/unhold()}}} methods on the {{{Session}}} this stream is part of.
873 67 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
874 67 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
875 67 Luci Stanescu
  [[BR]]originator:[[BR]]
876 67 Luci Stanescu
  A string representing the party which requested the hold change, {{{"local"}}} or {{{"remote"}}}
877 67 Luci Stanescu
  [[BR]]on_hold:[[BR]]
878 67 Luci Stanescu
  A boolean indicating the new hold state from the point of view of the originator.
879 1 Adrian Georgescu
 '''AudioStreamWillStartRecordingAudio''::
880 67 Luci Stanescu
  Will be sent when the application requested that the audio stream be recorded to a {{{.wav}}} file, just before recording starts.
881 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
882 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
883 67 Luci Stanescu
  [[BR]]''filename'':[[BR]]
884 67 Luci Stanescu
  The full path to the {{{.wav}}} file being recorded to.
885 55 Adrian Georgescu
 '''AudioStreamDidStartRecordingAudio'''::
886 67 Luci Stanescu
  Will be sent when the application requested that the audio stream be recorded to a {{{.wav}}} file, just after recording started.
887 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
888 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
889 67 Luci Stanescu
  [[BR]]''filename'':[[BR]]
890 67 Luci Stanescu
  The full path to the {{{.wav}}} file being recorded to.
891 63 Luci Stanescu
 '''AudioStreamWillStopRecordingAudio'''::
892 63 Luci Stanescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
893 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
894 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
895 67 Luci Stanescu
  [[BR]]''filename'':[[BR]]
896 67 Luci Stanescu
  The full path to the {{{.wav}}} file being recorded to.
897 57 Adrian Georgescu
 '''AudioStreamDidStopRecordingAudio'''::
898 67 Luci Stanescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just after recording stoped.
899 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
900 63 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
901 67 Luci Stanescu
  [[BR]]''filename'':[[BR]]
902 67 Luci Stanescu
  The full path to the {{{.wav}}} file being recorded to.
903 67 Luci Stanescu
 '''AudioStreamDidChangeRTPParameters'''::
904 67 Luci Stanescu
  This notification is sent when the RTP parameters are changed, such as codec, sample rate, RTP port etc.
905 63 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
906 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
907 63 Luci Stanescu
 '''AudioStreamGotDTMF'''::
908 1 Adrian Georgescu
  Will be send if there is a DMTF digit received from the remote party on the audio stream. 
909 57 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
910 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
911 63 Luci Stanescu
  [[BR]]''digit'':[[BR]]
912 1 Adrian Georgescu
  The DTMF digit that was received, in the form of a string of length 1.
913 67 Luci Stanescu
 '''AudioStreamICENegotiationStateDidChange'''::
914 67 Luci Stanescu
  This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationStateDidChange}}}.
915 67 Luci Stanescu
 '''AudioStreamICENegotiationDidSucceed'''::
916 67 Luci Stanescu
  This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationDidSucceed}}}.
917 67 Luci Stanescu
 '''AudioStreamICENegotiationDidFail'''::
918 67 Luci Stanescu
  This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationDidFail}}}.
919 1 Adrian Georgescu
 
920 69 Luci Stanescu
=== MSRPStreamBase ===
921 1 Adrian Georgescu
922 1 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
923 1 Adrian Georgescu
924 68 Luci Stanescu
The {{{MSRPStreamBase}}} is used as a base class for streams using the MSRP protocol. Within the SIP SIMPLE middleware, this hold for the {{{ChatStream}}}, {{{FileTransferStream}}} and {{{DesktopSharingStream}}} classes, however the application can also make use of this class to implement some other streams based on the MSRP protocol as a transport.
925 1 Adrian Georgescu
926 68 Luci Stanescu
==== methods ====
927 68 Luci Stanescu
 
928 68 Luci Stanescu
Of the methods defined by the {{{IMediaStream}}} interface, only the {{{new_from_sdp}}} method is not implemented in this base class and needs to be provided by the subclasses. Also, the subclasses can defined methods of the form {{{_handle_XXX}}}, where XXX is a MSRP method name in order to handle incoming MSRP requests. Also, since this class registers as an observer for itself, it will receive the notifications it sends so subclasses can define methods having the signature {{{_NH_<notification name>(self, notification)}}} as used throughout the middleware in order to do various things at the different points within the life-cycle of the stream.
929 68 Luci Stanescu
930 69 Luci Stanescu
==== atributes ====
931 68 Luci Stanescu
932 68 Luci Stanescu
The attributes defined in the {{{IMediaStream}}} interface which are not provided by this class are:
933 68 Luci Stanescu
 * type
934 68 Luci Stanescu
 * priority
935 68 Luci Stanescu
936 68 Luci Stanescu
In addition, the following attributes need to be defined in the subclass in order for the {{{MSRPStreamBase}}} class to take the correct decisions
937 1 Adrian Georgescu
 '''media_type'''::
938 68 Luci Stanescu
  The media type as included in the SDP (eg. {{{"message"}}}, {{{"application"}}}).
939 1 Adrian Georgescu
 '''accept_types'''::
940 68 Luci Stanescu
  A list of the MIME types which should be accepted by the stream (this is also sent within the SDP).
941 1 Adrian Georgescu
 '''accept_wrapped_types'''::
942 68 Luci Stanescu
  A list of the MIME types which should be accepted by the stream while wrapped in a {{{message/cpim}}} envelope.
943 1 Adrian Georgescu
 '''use_msrp_session'''::
944 68 Luci Stanescu
  A boolean indicating whether or not an {{{MSRPSession}}} should be used.
945 1 Adrian Georgescu
946 69 Luci Stanescu
==== notifications ====
947 1 Adrian Georgescu
948 68 Luci Stanescu
While not technically notifications of {{{MSRPStreamBase}}}, these notifications are sent from the middleware on behalf of the {{{MSRPTransport}}} used by a stream in the former case, and anonymously in the latter.
949 68 Luci Stanescu
950 1 Adrian Georgescu
 '''MSRPTransportTrace'''::
951 68 Luci Stanescu
  This notification is sent when an MSRP message is received for logging purposes.
952 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
953 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
954 68 Luci Stanescu
  [[BR]]direction:[[BR]]
955 68 Luci Stanescu
  The direction of the message, {{{"incoming"}}} or {{{"outgoing"}}}.
956 68 Luci Stanescu
  [[BR]]data:[[BR]]
957 68 Luci Stanescu
  The MSRP message as a string.
958 68 Luci Stanescu
 '''MSRPLibraryLog'''::
959 68 Luci Stanescu
  This notification is sent anonymously whenever the MSRP library needs to log any information.
960 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
961 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
962 68 Luci Stanescu
  [[BR]]message:[[BR]]
963 68 Luci Stanescu
  The log message as a string.
964 68 Luci Stanescu
  [[BR]]level:[[BR]]
965 68 Luci Stanescu
  The log level at which the message was written. One of the levels {{{DEBUG}}}, {{{INFO}}}, {{{WARNING}}}, {{{ERROR}}}, {{{CRITICAL}}} from the {{{application.log.level}}} object which is part of the {{{python-application}}} library.
966 1 Adrian Georgescu
967 68 Luci Stanescu
=== ChatStream ===
968 1 Adrian Georgescu
969 1 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
970 1 Adrian Georgescu
971 68 Luci Stanescu
{{{sipsimple.streams.msrp.ChatStream}}} implements session-based Instant Messaging (IM) over MSRP. This class performs the following functions:
972 1 Adrian Georgescu
973 1 Adrian Georgescu
 * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types
974 68 Luci Stanescu
 * unwraps incoming Message/CPIM messages; for each incoming message, the {{{ChatStreamGotMessage}}} notification is posted
975 68 Luci Stanescu
 * composes iscomposing payloads and reacts to those received by sending the {{{ChatStreamGotComposingIndication}}} notification
976 1 Adrian Georgescu
977 68 Luci Stanescu
An example of an SDP created using this class follows:
978 1 Adrian Georgescu
979 1 Adrian Georgescu
{{{
980 1 Adrian Georgescu
Content-Type: application/sdp
981 1 Adrian Georgescu
Content-Length:   283
982 1 Adrian Georgescu
983 1 Adrian Georgescu
v=0
984 1 Adrian Georgescu
o=- 3467525214 3467525214 IN IP4 192.168.1.6
985 1 Adrian Georgescu
s=blink-0.10.7-beta
986 1 Adrian Georgescu
c=IN IP4 192.168.1.6
987 1 Adrian Georgescu
t=0 0
988 1 Adrian Georgescu
m=message 2855 TCP/TLS/MSRP *
989 1 Adrian Georgescu
a=path:msrps://192.168.1.6:2855/ca7940f12ddef14c3c32;tcp
990 1 Adrian Georgescu
a=accept-types:message/cpim text/* application/im-iscomposing+xml
991 1 Adrian Georgescu
a=accept-wrapped-types:*
992 1 Adrian Georgescu
}}}
993 1 Adrian Georgescu
994 68 Luci Stanescu
==== methods ====
995 1 Adrian Georgescu
996 68 Luci Stanescu
 '''!__init!__'''(''self'', '''account''', '''direction'''={{{'sendrecv'}}})::
997 68 Luci Stanescu
  Initializes the ChatStream instance.
998 1 Adrian Georgescu
999 68 Luci Stanescu
 '''send_message'''(''self'', '''content''', '''content_type'''={{{'text/plain'}}}, '''recipients'''={{{None}}}, '''courtesy_recipients'''={{{None}}}, '''subject'''={{{None}}}, ''timestamp''={{{None}}}, '''required'''={{{None}}}, '''additional_headers'''={{{None}}})::
1000 68 Luci Stanescu
  Sends an IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be
1001 68 Luci Stanescu
  queued until the stream starts.
1002 68 Luci Stanescu
  Returns the generated MSRP message ID.
1003 68 Luci Stanescu
  [[BR]]content:[[BR]]
1004 68 Luci Stanescu
  The content of the message.
1005 68 Luci Stanescu
  [[BR]]content_type:[[BR]]
1006 68 Luci Stanescu
  Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case);
1007 68 Luci Stanescu
  otherwise, Content-Type of MSRP message.
1008 68 Luci Stanescu
  [[BR]]recipients:[[BR]]
1009 68 Luci Stanescu
  The list of {{{CPIMIdentity}}} objects which will be used for the {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity.
1010 68 Luci Stanescu
  May only differ from the default one if the remote party supports private messages. If it does not, a {{{ChatStreamError}}} will be raised.
1011 68 Luci Stanescu
  [[BR]]courtesy_recipients:[[BR]]
1012 68 Luci Stanescu
  The list of {{{CPIMIdentity}}} objects which will be used for the {{{cc}}} header of the CPIM wrapper.
1013 68 Luci Stanescu
  May only be specified if the remote party supports private messages and CPIM is supported. If it does not, a {{{ChatStreamError}}} will be raised.
1014 68 Luci Stanescu
  [[BR]]subject:[[BR]]
1015 68 Luci Stanescu
  A string or {{{MultilingualText}}} which specifies the subject and its translations to be added to the CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised.
1016 68 Luci Stanescu
  [[BR]]required:[[BR]]
1017 68 Luci Stanescu
  A list of strings describing the required capabilities that the other endpoint must support in order to understand this CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised.
1018 68 Luci Stanescu
  [[BR]]additional_headers:[[BR]]
1019 68 Luci Stanescu
  A list of MSRP header objects which will be added to this CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised.
1020 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1021 1 Adrian Georgescu
  A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message.
1022 68 Luci Stanescu
  When set to {{{None}}}, a default one representing the current moment will be added.
1023 1 Adrian Georgescu
1024 1 Adrian Georgescu
 These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses:
1025 1 Adrian Georgescu
{{{
1026 1 Adrian Georgescu
Failure-Report: partial
1027 1 Adrian Georgescu
Success-Report: yes
1028 1 Adrian Georgescu
}}}
1029 1 Adrian Georgescu
1030 68 Luci Stanescu
 '''send_composing_indication'''(''self'', ''state'', ''refresh'', ''last_active=None'', ''recipients=None'')::
1031 68 Luci Stanescu
  Sends an is-composing message to the listed recipients.
1032 68 Luci Stanescu
  [[BR]]state:[[BR]]
1033 68 Luci Stanescu
  The state of the endpoint, {{{"active"}}} or {{{"idle"}}}.
1034 68 Luci Stanescu
  [[BR]]refresh:[[BR]]
1035 68 Luci Stanescu
  How often the local endpoint will send is-composing indications to keep the state from being reverted to {{{"idle"}}}.
1036 68 Luci Stanescu
  [[BR]]last_active:[[BR]]
1037 68 Luci Stanescu
  A {{{datatime.datetime}}} object representing the moment when the local endpoint was last active.
1038 68 Luci Stanescu
  [[BR]]recipients:[[BR]]
1039 68 Luci Stanescu
  The list of {{{CPIMIdentity}}} objects which will be used for the {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity.
1040 68 Luci Stanescu
  May only differ from the default one if the remote party supports private messages. If it does not, a {{{ChatStreamError}}} will be raised.
1041 1 Adrian Georgescu
1042 68 Luci Stanescu
==== notifications ====
1043 1 Adrian Georgescu
1044 1 Adrian Georgescu
 '''ChatStreamGotMessage'''::
1045 68 Luci Stanescu
  Sent whenever a new incoming message is received,
1046 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1047 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1048 68 Luci Stanescu
  [[BR]]message:[[BR]]
1049 68 Luci Stanescu
  A {{{ChatMessage}}} or {{{CPIMMessage}}} instance, depending on whether a CPIM message was received or not.
1050 1 Adrian Georgescu
 '''ChatStreamDidDeliverMessage'''::
1051 68 Luci Stanescu
  Sent when a successful report is received.
1052 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1053 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1054 68 Luci Stanescu
  [[BR]]message_id:[[BR]]
1055 1 Adrian Georgescu
  Text identifier of the message.
1056 68 Luci Stanescu
  [[BR]]code:[[BR]]
1057 68 Luci Stanescu
  The status code received. Will always be 200 for this notification.
1058 68 Luci Stanescu
  [[BR]]reason:[[BR]]
1059 68 Luci Stanescu
  The status reason received.
1060 68 Luci Stanescu
  [[BR]]chunk:[[BR]]
1061 1 Adrian Georgescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
1062 1 Adrian Georgescu
 '''ChatStreamDidNotDeliverMessage'''::
1063 68 Luci Stanescu
  Sent when a failure report is received.
1064 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1065 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1066 68 Luci Stanescu
  [[BR]]message_id:[[BR]]
1067 1 Adrian Georgescu
  Text identifier of the message.
1068 68 Luci Stanescu
  [[BR]]code:[[BR]]
1069 68 Luci Stanescu
  The status code received.
1070 68 Luci Stanescu
  [[BR]]reason:[[BR]]
1071 68 Luci Stanescu
  The status reason received.
1072 68 Luci Stanescu
  [[BR]]chunk:[[BR]]
1073 1 Adrian Georgescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
1074 1 Adrian Georgescu
 '''ChatStreamDidSendMessage'''::
1075 68 Luci Stanescu
  Sent when an outgoing message has been sent.
1076 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1077 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1078 68 Luci Stanescu
  [[BR]]message:[[BR]]
1079 68 Luci Stanescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the sent message.
1080 1 Adrian Georgescu
 '''ChatStreamGotComposingIndication'''::
1081 68 Luci Stanescu
  Sent when a is-composing payload is received.
1082 68 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1083 68 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1084 68 Luci Stanescu
  [[BR]]state:[[BR]]
1085 68 Luci Stanescu
  The state of the endpoint, {{{"active"}}} or {{{"idle"}}}.
1086 68 Luci Stanescu
  [[BR]]refresh:[[BR]]
1087 68 Luci Stanescu
  How often the remote endpoint will send is-composing indications to keep the state from being reverted to {{{"idle"}}}. May be {{{None}}}.
1088 68 Luci Stanescu
  [[BR]]last_active:[[BR]]
1089 68 Luci Stanescu
  A {{{datatime.datetime}}} object representing the moment when the remote endpoint was last active. May be {{{None}}}.
1090 68 Luci Stanescu
  [[BR]]content_type:[[BR]]
1091 68 Luci Stanescu
  The MIME type of message being composed. May be {{{None}}}.
1092 68 Luci Stanescu
  [[BR]]sender:[[BR]]
1093 68 Luci Stanescu
  The {{{ChatIdentity}}} or {{{CPIMIdentity}}} instance which identifies the sender of the is-composing indication.
1094 55 Adrian Georgescu
1095 70 Luci Stanescu
=== FileSelector ===
1096 1 Adrian Georgescu
1097 70 Luci Stanescu
The {{{FileSelector}}} is used to contain information about a file tranfer using the {{{FileTransferStream}}} documented below.
1098 70 Luci Stanescu
1099 70 Luci Stanescu
==== methods ====
1100 70 Luci Stanescu
1101 70 Luci Stanescu
 '''!__init!__'''(''self'', '''name'''={{{None}}}, '''type'''={{{None}}}, '''size'''={{{None}}}, '''hash'''={{{None}}}, '''fd'''={{{None}}})::
1102 70 Luci Stanescu
  Instantiate a new {{{FileSelector}}}. All the arguments are also available as attributes.
1103 70 Luci Stanescu
  [[BR]]name:[[BR]]
1104 70 Luci Stanescu
  The filename (should be just the base name).
1105 70 Luci Stanescu
  [[BR]]type:[[BR]]
1106 70 Luci Stanescu
  The type of the file.
1107 70 Luci Stanescu
  [[BR]]size:[[BR]]
1108 70 Luci Stanescu
  The size of the file in bytes.
1109 70 Luci Stanescu
  [[BR]]hash:[[BR]]
1110 70 Luci Stanescu
  The hash of the file in the following format: {{{hash:sha-1:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX}}}, where {{{X}}} is a hexadecimal digit. Currently, only SHA1 hashes are supported according to the RFC.
1111 70 Luci Stanescu
  [[BR]]fd:[[BR]]
1112 70 Luci Stanescu
  A file descriptor if the application has already opened the file.
1113 70 Luci Stanescu
 '''parse'''(''cls'', '''string''')::
1114 70 Luci Stanescu
  Parses a file selector from the SDP {{{file-selector}}} a attribute and returns a {{{FileSelector}}} instance.
1115 70 Luci Stanescu
 '''for_file'''(''cls'', '''path''', '''content_type''', '''compute_hash'''={{{True}}})::
1116 70 Luci Stanescu
  Returns a {{{FileSelector}}} instance for the specified file. The file identified by the path must exist. Note that if {{{compute_hash}}} is {{{True}}} this method will block while the hash is computed, a potentially long operation for large files.
1117 70 Luci Stanescu
  [[BR]]path:[[BR]]
1118 70 Luci Stanescu
  The full path to the file.
1119 70 Luci Stanescu
  [[BR]]content_type:[[BR]]
1120 70 Luci Stanescu
  An optional MIME type which is to be included in the file-selector.
1121 70 Luci Stanescu
  [[BR]]compute_hash:[[BR]]
1122 70 Luci Stanescu
  Whether or not this method should compute the hash of the file.
1123 70 Luci Stanescu
1124 70 Luci Stanescu
==== attributes ====
1125 70 Luci Stanescu
1126 70 Luci Stanescu
 '''sdp_repr'''::
1127 70 Luci Stanescu
  The SDP representation of the file-selector according to the RFC. This should be the value of the {{{file-selector}}} SDP attribute.
1128 70 Luci Stanescu
1129 70 Luci Stanescu
=== FileTransferStream ===
1130 70 Luci Stanescu
1131 1 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
1132 55 Adrian Georgescu
1133 70 Luci Stanescu
The {{{FileTransferStream}}} supports file transfer over MSRP according to RFC5547. An example of SDP constructed using this stream follows:
1134 55 Adrian Georgescu
1135 55 Adrian Georgescu
{{{
1136 55 Adrian Georgescu
Content-Type: application/sdp
1137 55 Adrian Georgescu
Content-Length:   383
1138 55 Adrian Georgescu
1139 55 Adrian Georgescu
v=0
1140 55 Adrian Georgescu
o=- 3467525166 3467525166 IN IP4 192.168.1.6
1141 55 Adrian Georgescu
s=blink-0.10.7-beta
1142 55 Adrian Georgescu
c=IN IP4 192.168.1.6
1143 55 Adrian Georgescu
t=0 0
1144 55 Adrian Georgescu
m=message 2855 TCP/TLS/MSRP *
1145 64 Luci Stanescu
a=path:msrps://192.168.1.6:2855/e593357dc9abe90754bd;tcp
1146 55 Adrian Georgescu
a=sendonly
1147 64 Luci Stanescu
a=accept-types:*
1148 55 Adrian Georgescu
a=accept-wrapped-types:*
1149 1 Adrian Georgescu
a=file-selector:name:"reblink.pdf" type:com.adobe.pdf size:268759 hash:sha1:60:A1:BE:8D:71:DB:E3:8E:84:C9:2C:62:9E:F2:99:78:9D:68:79:F6
1150 1 Adrian Georgescu
}}}
1151 1 Adrian Georgescu
1152 70 Luci Stanescu
==== methods ====
1153 70 Luci Stanescu
1154 70 Luci Stanescu
 '''!__init!__'''(''self'', '''account''', '''file_selector'''={{{None}}})::
1155 70 Luci Stanescu
  Instantiate a new {{{FileTransferStream}}}. If this is constructed by the application for an outgoing file transfer, the {{{file_selector}}} argument must be present.
1156 70 Luci Stanescu
  [[BR]]account:[[BR]]
1157 70 Luci Stanescu
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} instance which will be associated with the stream.
1158 70 Luci Stanescu
  [[BR]]file_selector:[[BR]]
1159 70 Luci Stanescu
  The {{{FileSelector}}} instance which represents the file which is to be transferred.
1160 70 Luci Stanescu
1161 71 Luci Stanescu
==== notifications ====
1162 1 Adrian Georgescu
1163 1 Adrian Georgescu
 '''FileTransferStreamDidDeliverChunk'''::
1164 70 Luci Stanescu
  This notification is sent for an outgoing file transfer when a success report is received about part of the file being transferred.
1165 70 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1166 70 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1167 70 Luci Stanescu
  [[BR]]message_id:[[BR]]
1168 70 Luci Stanescu
  The MSRP message ID of the file transfer session.
1169 70 Luci Stanescu
  [[BR]]chunk:[[BR]]
1170 70 Luci Stanescu
  An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT.
1171 70 Luci Stanescu
  [[BR]]code:[[BR]]
1172 70 Luci Stanescu
  The status code received. Will always be 200 for this notification.
1173 70 Luci Stanescu
  [[BR]]reason:[[BR]]
1174 70 Luci Stanescu
  The status reason received.
1175 70 Luci Stanescu
  [[BR]]transferred_bytes:[[BR]]
1176 70 Luci Stanescu
  The number of bytes which have currently been successfully transferred.
1177 70 Luci Stanescu
  [[BR]]file_size:[[BR]]
1178 70 Luci Stanescu
  The size of the file being transferred.
1179 1 Adrian Georgescu
 '''FileTransferStreamDidNotDeliverChunk'''::
1180 70 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1181 70 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1182 70 Luci Stanescu
  This notification is sent for an outgoing file transfer when a failure report is received about part of the file being transferred.
1183 70 Luci Stanescu
  [[BR]]message_id:[[BR]]
1184 70 Luci Stanescu
  The MSRP message ID of the file transfer session.
1185 70 Luci Stanescu
  [[BR]]chunk:[[BR]]
1186 70 Luci Stanescu
  An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT.
1187 70 Luci Stanescu
  [[BR]]code:[[BR]]
1188 70 Luci Stanescu
  The status code received.
1189 70 Luci Stanescu
  [[BR]]reason:[[BR]]
1190 70 Luci Stanescu
  The status reason received.
1191 70 Luci Stanescu
 '''FileTransferStreamDidFinish'''::
1192 70 Luci Stanescu
  This notification is sent when the incoming or outgoing file transfer is finished.
1193 70 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1194 70 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1195 1 Adrian Georgescu
 '''FileTransferStreamGotChunk'''::
1196 70 Luci Stanescu
  This notificaiton is sent for an incoming file transfer when a chunk of file data is received.
1197 70 Luci Stanescu
  [[BR]]timestamp:[[BR]]
1198 70 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1199 70 Luci Stanescu
  [[BR]]content:[[BR]]
1200 70 Luci Stanescu
  The file part which was received, as a {{{str}}}.
1201 70 Luci Stanescu
  [[BR]]content_type:[[BR]]
1202 70 Luci Stanescu
  The MIME type of the file which is being transferred.
1203 70 Luci Stanescu
  [[BR]]transferred_bytes:[[BR]]
1204 70 Luci Stanescu
  The number of bytes which have currently been successfully transferred.
1205 70 Luci Stanescu
  [[BR]]file_size:[[BR]]
1206 70 Luci Stanescu
  The size of the file being transferred.
1207 1 Adrian Georgescu
1208 1 Adrian Georgescu
1209 71 Luci Stanescu
=== IDesktopSharingHandler ===
1210 71 Luci Stanescu
1211 71 Luci Stanescu
This interface is used to describe the interface between a {{{IDesktopSharingHandler}}}, which is responsible for consuming and producing RFB data, and the {{{DesktopSharingStream}}} which is responsible for transporting the RFB data over MSRP. The middleware provides four implementations of this interface:
1212 71 Luci Stanescu
 * InternalVNCViewerHandler
1213 71 Luci Stanescu
 * InternalVNCServerHandler
1214 71 Luci Stanescu
 * ExternalVNCViewerHandler
1215 71 Luci Stanescu
 * ExternalVNCServerHandler
1216 71 Luci Stanescu
1217 71 Luci Stanescu
==== methods ====
1218 71 Luci Stanescu
 
1219 71 Luci Stanescu
 '''initialize'''(''self'', '''stream''')::
1220 71 Luci Stanescu
  This method will be called by the {{{DesktopSharingStream}}} when the stream has been started and RFB data can be transported. The stream has two attributes which are relevant to the {{{IDesktopSharingHandler}}}: incoming_queue and outgoing_queue. These attributes are {{{eventlet.coros.queue}}} instances which are used to transport RFB data between the stream and the handler.
1221 71 Luci Stanescu
1222 71 Luci Stanescu
==== attributes ====
1223 71 Luci Stanescu
1224 71 Luci Stanescu
 '''type'''::
1225 71 Luci Stanescu
  {{{"active"}}} or {{{"passive"}}} depending on whether the handler represents a VNC viewer or server respectively.
1226 71 Luci Stanescu
1227 71 Luci Stanescu
==== notifications ====
1228 71 Luci Stanescu
1229 71 Luci Stanescu
 '''DesktopSharingHandlerDidFail'''::
1230 71 Luci Stanescu
  This notification must be sent by the handler when an error occurs to notify the stream that it should fail.
1231 71 Luci Stanescu
  [[BR]]context:[[BR]]
1232 71 Luci Stanescu
  A string describing when the handler failed, such as {{{"reading"}}}, {{{"sending"}}} or {{{"connecting"}}}.
1233 71 Luci Stanescu
  [[BR]]failure:[[BR]]
1234 71 Luci Stanescu
  A {{{twisted.python.failure.Failure}}} instance describing the exception which led to the failure.
1235 71 Luci Stanescu
  [[BR]]reason:[[BR]]
1236 71 Luci Stanescu
  A string describing the failure reason.
1237 71 Luci Stanescu
1238 71 Luci Stanescu
=== InternalVNCViewerHandler and InternalVNCServerHandler ===
1239 71 Luci Stanescu
1240 71 Luci Stanescu
These are concrete implementations of the {{{IDesktopSharingHandler}}} interface which can be used for a VNC viewer or server implemented within the application. Since they have exactly the same interface as far as the application is concerned, they are documented together.
1241 71 Luci Stanescu
1242 71 Luci Stanescu
==== methods ====
1243 71 Luci Stanescu
1244 71 Luci Stanescu
 '''send'''(''self'', '''data''')::
1245 71 Luci Stanescu
  Sends the specified data to the stream in order for it to be transported over MSRP to the remote endpoint.
1246 71 Luci Stanescu
  [[BR]]data:[[BR]]
1247 71 Luci Stanescu
  The RFB data to be transported over MSRP, in the form of a {{{str}}}.
1248 71 Luci Stanescu
1249 71 Luci Stanescu
==== notifications ====
1250 71 Luci Stanescu
1251 71 Luci Stanescu
 '''DesktopSharingStreamGotData'''::
1252 71 Luci Stanescu
  This notification is sent when data is received over MSRP.
1253 71 Luci Stanescu
  [[BR]]data:[[BR]]
1254 71 Luci Stanescu
  The RFB data from the remote endpoint, in the form of a {{{str}}}.
1255 71 Luci Stanescu
1256 71 Luci Stanescu
=== ExternalVNCViewerHandler ===
1257 71 Luci Stanescu
1258 71 Luci Stanescu
This implementation of {{{IDesktopSharingHandler}}} can be used for an external VNC viewer which connects to a VNC server using TCP.
1259 71 Luci Stanescu
1260 71 Luci Stanescu
==== methods ====
1261 71 Luci Stanescu
1262 71 Luci Stanescu
 '''!__init!__'''(''self'', '''address'''={{{("localhost", 0)}}}, '''connect_timeout'''={{{3}}})::
1263 71 Luci Stanescu
  This instantiates a new {{{ExternalVNCViewerHandler}}} which is listening on the provided address, ready for the external VNC viewer to connect to it via TCP. After this method returns, the attribute {{{address}}} can be used to find out exactly on what address and port the handler is listening on. The handler will only accept one conenction on this address.
1264 71 Luci Stanescu
  [[BR]]address:[[BR]]
1265 71 Luci Stanescu
  A tuple containing an IP address/hostname and a port on which the handler should listen. Any data received on this socket will then be forwarded to the stream and any data received from the stream will be forwarded to this socket.
1266 71 Luci Stanescu
1267 71 Luci Stanescu
==== attribtues ====
1268 71 Luci Stanescu
1269 71 Luci Stanescu
 '''address'''::
1270 71 Luci Stanescu
  A tuple containing an IP address and a port on which the handler is listening.
1271 71 Luci Stanescu
1272 71 Luci Stanescu
=== ExternalVNCServerHandler ===
1273 71 Luci Stanescu
1274 71 Luci Stanescu
This implementation of {{{IDesktopSharingHandler}}} can be used for an external VNC server to which handler will connect using TCP.
1275 71 Luci Stanescu
1276 71 Luci Stanescu
==== methods ====
1277 71 Luci Stanescu
1278 71 Luci Stanescu
 '''!__init!__'''(''self'', '''address''', '''connect_timeout'''={{{3}}})::
1279 71 Luci Stanescu
  This instantiates a new {{{ExternalVNCServerHandler}}} which will connect to the provided address on which a VNC server must be listening before the stream using this handler starts.
1280 71 Luci Stanescu
  [[BR]]address:[[BR]]
1281 71 Luci Stanescu
  A tuple containing an IP address/hostname and a port on which the VNC server will be listening. Any data received on this socket will then be forwared to the stream and any data received form the stream will be forwarded to this socket.
1282 71 Luci Stanescu
  [[BR]]connect_timeout:[[BR]]
1283 71 Luci Stanescu
  How long to wait to connect to the VNC server before giving up.
1284 71 Luci Stanescu
1285 71 Luci Stanescu
1286 71 Luci Stanescu
=== DesktopSharingStream ===
1287 71 Luci Stanescu
1288 1 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
1289 64 Luci Stanescu
1290 71 Luci Stanescu
This stream implements desktop sharing using MSRP as a transport protocol for RFB data.
1291 64 Luci Stanescu
1292 71 Luci Stanescu
There is no standard defining this usage but is fairly easy to implement in clients that already support MSRP. To traverse a NAT-ed router, a [http://msrprelay.org MSRP relay] configured for the called party domain is needed. Below is an example of the Session Description Protocol used for establishing a Desktop sharing session:
1293 64 Luci Stanescu
1294 64 Luci Stanescu
{{{
1295 64 Luci Stanescu
m=application 2855 TCP/TLS/MSRP *
1296 64 Luci Stanescu
a=path:msrps://10.0.1.19:2855/b599b22d1b1d6a3324c8;tcp
1297 1 Adrian Georgescu
a=accept-types:application/x-rfb
1298 1 Adrian Georgescu
a=setup:active
1299 1 Adrian Georgescu
}}}
1300 1 Adrian Georgescu
1301 1 Adrian Georgescu
1302 71 Luci Stanescu
==== methods ====
1303 1 Adrian Georgescu
1304 71 Luci Stanescu
 '''!__init!__'''(''self'', '''acount''', '''handler''')::
1305 71 Luci Stanescu
  Instantiate a new {{{DesktopSharingStream}}}.
1306 71 Luci Stanescu
  [[BR]]account:[[BR]]
1307 71 Luci Stanescu
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} instance this stream is associated with.
1308 71 Luci Stanescu
  [[BR]]handler:[[BR]]
1309 71 Luci Stanescu
  An object implementing the {{{IDesktopSharingHandler}}} interface which will act as the handler for RFB data.
1310 1 Adrian Georgescu
1311 71 Luci Stanescu
==== attributes ====
1312 71 Luci Stanescu
1313 71 Luci Stanescu
 '''handler'''::
1314 71 Luci Stanescu
  This is a writable property which can be used to get or set the object implementing {{{IDesktopSharingHandler}}} which acts as the handler for RFB data. For incoming {{{DesktopSharingStreams}}}, this must be set by the application before the stream starts.
1315 71 Luci Stanescu
 '''incoming_queue'''::
1316 71 Luci Stanescu
  A {{{eventlet.coros.queue}}} instance on which incoming RFB data is written. The handler should wait for data on this queue.
1317 71 Luci Stanescu
 '''outgoing_queue'''::
1318 71 Luci Stanescu
  A {{{eventlet.coros.queue}}} instance on which outgoing RFB data is written. The handler should write data on this queue.
1319 71 Luci Stanescu
1320 64 Luci Stanescu
1321 72 Luci Stanescu
== Account management ==
1322 64 Luci Stanescu
1323 72 Luci Stanescu
Account Management is implemented in [browser:sipsimple/account.py] ({{{sipsimple.account}}} module) and offers support for SIP accounts registered at SIP providers and SIP bonjour accounts which are discovered using mDNS.
1324 1 Adrian Georgescu
1325 72 Luci Stanescu
=== Account ===
1326 64 Luci Stanescu
1327 72 Luci Stanescu
The {{{sipsimple.account.Account}}} objects represent the SIP accounts which are registered at SIP providers. It has a dual purpose: it acts as both a container for account-related settings and as a complex object which can be used to interact with various per-account functions, such as presence, registration etc. This page documents the latter case, while the former is explained in the [wiki:SipConfigurationAPI#Account Configuration API].
1328 72 Luci Stanescu
1329 64 Luci Stanescu
There is exactly one instance of {{{Account}}} per SIP account used and it is uniquely identifiable by its SIP ID, in the form ''user@domain''. It is a singleton, in the sense that instantiating {{{Account}}} using an already used SIP ID will return the same object. However, this is not the recommended way of accessing accounts, as this can lead to creation of new ones; the recommended way is by using the [wiki:SipMiddlewareApi#AccountManager AccountManager]. The next sections will use a lowercase, monospaced {{{account}}} to represent an instance of {{{Account}}}.
1330 64 Luci Stanescu
1331 72 Luci Stanescu
==== states ====
1332 64 Luci Stanescu
1333 64 Luci Stanescu
The {{{Account}}} objects have a setting flag called {{{enabled}}} which, if set to {{{False}}} will deactivate it: none of the internal functions will work in this case; in addition, the application using the middleware should not do anything with a disabled account. After changing it's value, the {{{save()}}} method needs to be called, as the flag is a setting and will not be used until this method is called:
1334 64 Luci Stanescu
{{{
1335 64 Luci Stanescu
account.enabled = True
1336 64 Luci Stanescu
account.save()
1337 64 Luci Stanescu
}}}
1338 64 Luci Stanescu
1339 64 Luci Stanescu
The {{{Account}}} objects will activate automatically when they are loaded/created if the {{{enabled}}} flag is set to {{{True}}} and the {{{sipsimple.engine.Engine}}} is running; if it is not running, the accounts will activate after the engine starts.
1340 64 Luci Stanescu
1341 64 Luci Stanescu
In order to create a new account, just create a new instance of {{{Account}}} with an id which doesn't belong to any other account.
1342 64 Luci Stanescu
1343 64 Luci Stanescu
The other functions of {{{Account}}} which run automatically have other enabled flags as well. They will only be activated when both the global enabled flag is set and the function-specific one. These are:
1344 64 Luci Stanescu
1345 64 Luci Stanescu
 '''Account.registration.enabled'''::
1346 64 Luci Stanescu
  This flag controls the automatic registration of the account. The notifications '''SIPAccountRegistrationDidSucceed''', '''SIPAccountRegistrationDidFail''' and '''SIPAccountRegistrationDidEnd''' are used to inform the status of this registration.
1347 64 Luci Stanescu
 '''Account.presence.enabled'''::
1348 64 Luci Stanescu
  This flag controls the automatic subscription to buddies for the ''presence'' event and the publication of data in this event. (Not implemented yet)
1349 64 Luci Stanescu
 '''Account.dialog_event.enabled'''::
1350 64 Luci Stanescu
  This flag controls the automatic subscription to buddies for the ''dialog-info'' event and the publication of data in this event. (Not implemented yet)
1351 1 Adrian Georgescu
 '''Account.message_summary.enabled'''::
1352 64 Luci Stanescu
  This flag controls the automatic subscription to the ''message-summary'' event in order to find out about voicemail messages. (Not implemented yet)
1353 64 Luci Stanescu
1354 64 Luci Stanescu
The {{{save()}}} method needs to be called after changing these flags in order for them to take effect. The methods available on {{{Account}}} objects are inherited from [wiki:SipConfigurationAPI#SettingsObject SettingsObject].
1355 64 Luci Stanescu
1356 72 Luci Stanescu
==== attributes ====
1357 64 Luci Stanescu
1358 64 Luci Stanescu
The following attributes can be used on an Account object and need to be considered read-only.
1359 64 Luci Stanescu
1360 64 Luci Stanescu
 '''id'''::
1361 64 Luci Stanescu
  This attribute is of type {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of {{{str}}}) and contains the SIP id of the account. It can be used as a normal string in the form ''user@domain'', but it also allows access to the components via the attributes {{{username}}} and {{{domain}}}.
1362 64 Luci Stanescu
  {{{
1363 64 Luci Stanescu
  account.id # 'alice@example.com'
1364 64 Luci Stanescu
  account.id.username # 'alice'
1365 64 Luci Stanescu
  account.id.domain # 'example.com'
1366 64 Luci Stanescu
  }}}
1367 64 Luci Stanescu
 '''contact'''::
1368 64 Luci Stanescu
  This attribute can be used to construct the Contact URI for SIP requests sent on behalf of this account. It's type is {{{sipsimple.account.ContactURI}}} which is a subclass of {{{sipsimple.configuration.datatypes.SIPAddress}}}. In addition to the attributes defined in {{{SIPAddress}}}, it can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}} or {{{'tls'}}}) which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate port and transport parameter. The username part is a randomly generated 8 character string consisting of lowercase letters; the domain part is the IP address on which the {{{Engine}}} is listening (as specified by the SIPSimpleSettings.local_ip setting).
1369 64 Luci Stanescu
  {{{
1370 64 Luci Stanescu
  account.contact # 'hnfkybrt@10.0.0.1'
1371 1 Adrian Georgescu
  account.contact.username # 'hnfkybrt'
1372 1 Adrian Georgescu
  account.contact.domain # '10.0.0.1'
1373 64 Luci Stanescu
  account.contact['udp'] # <SIPURI "sip:hnfkybrt@10.0.0.1:53024">
1374 1 Adrian Georgescu
  account.contact['tls'] # <SIPURI "sip:hnfkybrt@10.0.0.1:54478;transport=tls">
1375 1 Adrian Georgescu
  }}}
1376 1 Adrian Georgescu
 '''credentials'''::
1377 72 Luci Stanescu
  This attribute is of type {{{sipsimple.core.Credentials}}} which is built from the {{{id.username}}} attribute and the {{{password}}} setting of the Account. Whenever this setting is changed, this attribute is updated.
1378 1 Adrian Georgescu
  {{{
1379 72 Luci Stanescu
  account.credentials # <Credentials for 'alice'>
1380 64 Luci Stanescu
  }}}
1381 72 Luci Stanescu
 '''uri'''::
1382 72 Luci Stanescu
  This attribute is of type {{{sipsimple.core.SIPURI}}} which can be used to form a {{{FromHeader}}} associated with this account. It contains the SIP ID of the account.
1383 72 Luci Stanescu
  {{{
1384 72 Luci Stanescu
  account.uri # <SIPURI "sip:alice@example.com">
1385 72 Luci Stanescu
  }}}
1386 1 Adrian Georgescu
1387 72 Luci Stanescu
==== notifications ====
1388 1 Adrian Georgescu
1389 1 Adrian Georgescu
 '''CFGSettingsObjectDidChange'''::
1390 1 Adrian Georgescu
  This notification is sent when the {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the {{{SettingsObject}}} class, it is exaplained in detail in [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications].
1391 1 Adrian Georgescu
 '''SIPAccountDidActivate'''::
1392 72 Luci Stanescu
  This notification is sent when the {{{Account}}} activates. This can happen when the {{{Account}}} is loaded if it's enabled flag is set and the Engine is running, and at any later time when the status of the Engine changes or the enabled flag is modified.
1393 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1394 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1395 1 Adrian Georgescu
 '''SIPAccountDidDeactivate'''::
1396 72 Luci Stanescu
  This notification is sent when the {{{Account}}} deactivates. This can happend when the {{{Engine}}} is stopped or when the enabled flag of the account is set to {{{False}}}.
1397 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1398 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1399 72 Luci Stanescu
 '''SIPAccountWillRegister'''
1400 72 Luci Stanescu
  This notification is sent when the account is about to register for the first time.
1401 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1402 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1403 72 Luci Stanescu
 '''SIPAccountRegistrationWillRefresh'''
1404 72 Luci Stanescu
  This notification is sent when a registration is about to be refreshed.
1405 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1406 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1407 1 Adrian Georgescu
 '''SIPAccountRegistrationDidSucceed'''::
1408 1 Adrian Georgescu
  This notification is sent when a REGISTER request sent for the account succeeds (it is also sent for each refresh of the registration). The data contained in this notification is:
1409 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1410 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1411 72 Luci Stanescu
  [[BR]]''contact_header'':[[BR]]
1412 72 Luci Stanescu
   The Contact header which was registered.
1413 72 Luci Stanescu
  [[BR]]''contact_header_list'':[[BR]]
1414 72 Luci Stanescu
   A list containing all the contacts registered for this SIP account.
1415 1 Adrian Georgescu
  [[BR]]''expires'':[[BR]]
1416 1 Adrian Georgescu
   The amount in seconds in which this registration will expire.
1417 72 Luci Stanescu
  [[BR]]''registrar'':[[BR]]
1418 72 Luci Stanescu
  The {{{sipsimple.util.Route}}} object which was used.
1419 1 Adrian Georgescu
 '''SIPAccountRegistrationDidFail'''::
1420 1 Adrian Georgescu
  This notification is sent when a REGISTER request sent for the account fails. It can fail either because a negative response was returned or because PJSIP considered the request failed (e.g. on timeout). The data contained in this notification is:
1421 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1422 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1423 72 Luci Stanescu
  [[BR]]''error'':[[BR]]
1424 1 Adrian Georgescu
   The reason for the failure of the REGISTER request.
1425 72 Luci Stanescu
  [[BR]]''timeout'':[[BR]]
1426 72 Luci Stanescu
   The amount in seconds as a {{{float}}} after which the registration will be tried again.
1427 1 Adrian Georgescu
 '''SIPAccountRegistrationDidEnd'''::
1428 64 Luci Stanescu
  This notification is sent when a registration is ended (the account is unregistered). The data contained in this notification is:
1429 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1430 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1431 72 Luci Stanescu
  [[BR]]''registration'':[[BR]]
1432 72 Luci Stanescu
   The {{{sipsimple.core.Registration}}} object which ended.
1433 72 Luci Stanescu
 '''SIPAccountRegistrationDidNotEnd'''::
1434 72 Luci Stanescu
  This notification is sent when a registration fails to end (the account is not unregistered). The data contained in this notification is:
1435 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1436 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1437 1 Adrian Georgescu
  [[BR]]''code'':[[BR]]
1438 72 Luci Stanescu
  The SIP status code received.
1439 64 Luci Stanescu
  [[BR]]''reason'':[[BR]]
1440 72 Luci Stanescu
  The SIP status reason received.
1441 1 Adrian Georgescu
  [[BR]]''registration'':[[BR]]
1442 72 Luci Stanescu
  The {{{sipsimple.core.Registration}}} object which ended.
1443 72 Luci Stanescu
 '''SIPAccountRegistrationGotAnswer'''::
1444 72 Luci Stanescu
  This notification is sent whenever a response is received to a sent REGISTER request for this account. The data contained in this notification is:
1445 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1446 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1447 72 Luci Stanescu
  [[BR]]''code'':[[BR]]
1448 72 Luci Stanescu
  The SIP status code received.
1449 72 Luci Stanescu
  [[BR]]''reason'':[[BR]]
1450 72 Luci Stanescu
  The SIP status reason received.
1451 72 Luci Stanescu
  [[BR]]''registration'':[[BR]]
1452 72 Luci Stanescu
  The {{{sipsimple.core.Registration}}} object which was used.
1453 72 Luci Stanescu
  [[BR]]''registrar'':[[BR]]
1454 72 Luci Stanescu
  The {{{sipsimple.util.Route}}} object which was used.
1455 1 Adrian Georgescu
1456 72 Luci Stanescu
=== BonjourAccount ===
1457 1 Adrian Georgescu
1458 64 Luci Stanescu
The {{{sipsimple.account.BonjourAccount}}} represents the SIP account used for P2P mode; it does not interact with any server. The class is a singleton, as there can only be one such account on a system. Similar to the {{{Account}}}, it is used both as a complex object, which implements the functions for bonjour mode, as well as a container for the related settings.
1459 1 Adrian Georgescu
1460 72 Luci Stanescu
==== states ====
1461 64 Luci Stanescu
1462 72 Luci Stanescu
The {{{BonjourAccount}}} has an {{{enabled}}} flag which controls whether this account will be used or not. If it is set to {{{False}}}, none of the internal functions will be activated and, in addition, the account should not be used by the application. The bonjour account can only activated if the Engine is running; once it is started, if the enabled flag is set, the account will activate. When the {{{BonjourAccount}}} is activated, it will broadcast the contact address on the LAN. (Not implemented yet)
1463 64 Luci Stanescu
1464 72 Luci Stanescu
==== attributes ====
1465 1 Adrian Georgescu
1466 72 Luci Stanescu
The following attributes can be used on a BonjourAccount object and need to be considered read-only.
1467 64 Luci Stanescu
1468 64 Luci Stanescu
 '''id'''::
1469 64 Luci Stanescu
  This attribute is of type {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of {{{str}}}) and contains the SIP id of the account, which is {{{'bonjour@local'}}}. It can be used as a normal string, but it also allows access to the components via the attributes {{{username}}} and {{{domain}}}.
1470 64 Luci Stanescu
  {{{
1471 64 Luci Stanescu
  bonjour_account.id # 'bonjour@local'
1472 64 Luci Stanescu
  bonjour_account.id.username # 'bonjour'
1473 64 Luci Stanescu
  bonjour_account.id.domain # 'local'
1474 64 Luci Stanescu
  }}}
1475 64 Luci Stanescu
 '''contact'''::
1476 1 Adrian Georgescu
  This attribute can be used to construct the Contact URI for SIP requests sent on behalf of this account. It's type is {{{sipsimple.account.ContactURI}}} which is a subclass of {{{sipsimple.configuration.datatypes.SIPAddress}}}. In addition to the attributes defined in {{{SIPAddress}}}, it can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}} or {{{'tls'}}}) which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate port and transport parameter. The username part is a randomly generated 8 character string consisting of lowercase letters; the domain part is the IP address on which the {{{Engine}}} is listening (as specified by the SIPSimpleSettings.local_ip setting).
1477 64 Luci Stanescu
  {{{
1478 72 Luci Stanescu
  bonjour_account.contact # 'lxzvgack@10.0.0.1'
1479 72 Luci Stanescu
  bonjour_account.contact.username # 'lxzvgack'
1480 72 Luci Stanescu
  bonjour_account.contact.domain # '10.0.0.1'
1481 72 Luci Stanescu
  bonjour_account.contact['udp'] # <SIPURI "sip:lxzvgack@10.0.0.1:53024">
1482 72 Luci Stanescu
  bonjour_account.contact['tls'] # <SIPURI "sip:lxzvgack@10.0.0.1:54478;transport=tls">
1483 1 Adrian Georgescu
  }}}
1484 1 Adrian Georgescu
 '''credentials'''::
1485 72 Luci Stanescu
  This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{contact.username}}} attribute; the password is set to the empty string.
1486 1 Adrian Georgescu
  {{{
1487 72 Luci Stanescu
  bonjour_account.credentials # <Credentials for 'alice'>
1488 1 Adrian Georgescu
  }}}
1489 72 Luci Stanescu
 '''uri'''::
1490 72 Luci Stanescu
  This attribute is of type {{{sipsimple.core.SIPURI}}} which can be used to form a {{{FromHeader}}} associated with this account. It contains the contact address of the bonjour accunt:
1491 72 Luci Stanescu
  {{{
1492 72 Luci Stanescu
  bonjour_account.uri # <SIPURI "sip:lxzvgack@10.0.0.1">
1493 72 Luci Stanescu
  }}}
1494 64 Luci Stanescu
1495 72 Luci Stanescu
==== notifications ====
1496 64 Luci Stanescu
1497 64 Luci Stanescu
 '''CFGSettingsObjectDidChange'''::
1498 64 Luci Stanescu
  This notification is sent when the {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the {{{SettingsObject}}} class, it is exaplained in detail in [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications].
1499 64 Luci Stanescu
 '''SIPAccountDidActivate'''::
1500 72 Luci Stanescu
  This notification is sent when the {{{BonjourAccount}}} activates. This can happen when the {{{BonjourAccount}}} is loaded if it's enabled flag is set and the Engine is running, and at any later time when the status of the Engine changes or the enabled flag is modified.
1501 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1502 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1503 64 Luci Stanescu
 '''SIPAccountDidDeactivate'''::
1504 72 Luci Stanescu
  This notification is sent when the {{{BonjourAccount}}} deactivates. This can happend when the {{{Engine}}} is stopped or when the enabled flag of the account is set to {{{False}}}.
1505 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1506 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1507 1 Adrian Georgescu
1508 1 Adrian Georgescu
1509 72 Luci Stanescu
=== AccountManager ===
1510 1 Adrian Georgescu
1511 1 Adrian Georgescu
The {{{sipsimple.account.AccountManager}}} is the entity responsible for loading and keeping track of the existing accounts. It is a singleton and can be instantiated anywhere, obtaining the same instance. It cannot be used until its {{{start}}} method has been called.
1512 1 Adrian Georgescu
1513 72 Luci Stanescu
==== methods ====
1514 1 Adrian Georgescu
1515 1 Adrian Georgescu
 '''!__init!__'''(''self'')::
1516 1 Adrian Georgescu
  The {{{__init__}}} method allows the {{{AccountManager}}} to be instantiated without passing any parameters. A reference to the {{{AccountManager}}} can be obtained anywhere before it is started.
1517 1 Adrian Georgescu
 '''start'''(''self'')::
1518 72 Luci Stanescu
  This method will load all the existing accounts from the configuration. If the Engine is running, the accounts will also activate. This method can only be called after the [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] has been started. A '''SIPAccountManagerDidAddAccount''' will be sent for each account loaded. This method is called automatically by the SIPApplication when it initializes all the components of the middleware.
1519 1 Adrian Georgescu
 '''stop'''(''self'')::
1520 72 Luci Stanescu
  Calling this method will deactivate all accounts managed by the {{{AccountManager}}}. This method is called automatically by the SIPApplication when it stops.
1521 1 Adrian Georgescu
 '''has_account'''(''self'', '''id''')::
1522 1 Adrian Georgescu
  This method returns {{{True}}} if an account which has the specifed SIP ID (must be a string) exists and {{{False}}} otherwise.
1523 1 Adrian Georgescu
 '''get_account'''(''self'', '''id''')::
1524 1 Adrian Georgescu
  Returns the account (either an {{{Account}}} instance or the {{{BonjourAccount}}} instance) with the specified SIP ID. Will raise a {{{KeyError}}} if such an account does not exist.
1525 1 Adrian Georgescu
 '''get_accounts'''(''self'')::
1526 1 Adrian Georgescu
  Returns a list containing all the managed accounts.
1527 1 Adrian Georgescu
 '''iter_accounts'''(''self'')::
1528 1 Adrian Georgescu
  Returns an iterator through all the managed accounts.
1529 1 Adrian Georgescu
 '''find_account'''(''self'', '''contact_uri''')::
1530 1 Adrian Georgescu
  Returns an account with matches the specified {{{contact_uri}}} which must be a {{{sipsimple.core.SIPURI}}} instance. Only the accounts with the enabled flag set will be considered. Returns None if such an account does not exist.
1531 1 Adrian Georgescu
1532 72 Luci Stanescu
==== notifications ====
1533 1 Adrian Georgescu
1534 1 Adrian Georgescu
 '''SIPAccountManagerDidAddAccount'''::
1535 72 Luci Stanescu
  This notification is sent when a new account becomes available to the {{{AccountManager}}}. The notification is also sent when the accounts are loaded from the configuration.
1536 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1537 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1538 72 Luci Stanescu
  [[BR]]''account'':[[BR]]
1539 72 Luci Stanescu
  The account object which was added.
1540 1 Adrian Georgescu
 '''SIPAccountManagerDidRemoveAccount'''::
1541 72 Luci Stanescu
  This notification is sent when an account is deleted using the {{{delete}}} method.
1542 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1543 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1544 72 Luci Stanescu
  [[BR]]''account'':[[BR]]
1545 72 Luci Stanescu
  The account object which was deleted.
1546 1 Adrian Georgescu
 '''SIPAccountManagerDidChangeDefaultAccount'''::
1547 72 Luci Stanescu
  This notification is sent when the default account changes.
1548 72 Luci Stanescu
  [[BR]]''timestamp'':[[BR]]
1549 72 Luci Stanescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
1550 1 Adrian Georgescu
  [[BR]]''old_account'':[[BR]]
1551 1 Adrian Georgescu
   This is the account object which used to be the default account.
1552 1 Adrian Georgescu
  [[BR]]''account'':[[BR]]
1553 1 Adrian Georgescu
   This is the account object which is the new default account.