Project

General

Profile

SipMiddlewareApi » History » Version 90

Adrian Georgescu, 03/28/2010 04:12 PM

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