SipMiddlewareApi

Version 98 (Adrian Georgescu, 03/31/2010 10:10 am)

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