Project

General

Profile

SipMiddlewareApi » History » Version 170

Tijmen de Mes, 04/19/2012 05:07 PM

1 147 Adrian Georgescu
h1. Middleware API
2 102 Adrian Georgescu
3 1 Adrian Georgescu
4
5
6 147 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_ API  that communicates with the user interface asynchronously by using _Notifications_. For its configuration, the Middleware uses the [[SipConfigurationAPI|Configuration API]].
7 1 Adrian Georgescu
8 152 Tijmen de Mes
!={width:500px}sipsimple-middleware.png!
9 147 Adrian Georgescu
10
11
h2. SIPApplication
12
13
14 62 Luci Stanescu
Implemented in [browser:sipsimple/application.py]
15 1 Adrian Georgescu
16
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:
17 147 Adrian Georgescu
* the twisted thread
18
* the configuration system, via the [[SipConfigurationAPI#ConfigurationManager|ConfigurationManager]]
19
* the core [[SipCoreApiDocumentation#Engine|Engine]] using the settings in the configuration
20
* the [[SipMiddlewareApi#AccountManager|AccountManager]], using the accounts in the configuration
21
* the [[SipMiddlewareApi#SessionManager|SessionManager]], in order to handle incoming sessions
22
* two [[SipMiddlewareApi#AudioBridge|AudioBridges]], using the settings in the configuration
23 1 Adrian Georgescu
24
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.
25
26
27 147 Adrian Georgescu
h4. methods 
28 1 Adrian Georgescu
29 147 Adrian Georgescu
*<notextile>__init__</notextile>*(_self_)
30
>Instantiates a new SIPApplication.
31 1 Adrian Georgescu
32 147 Adrian Georgescu
*start*(_self_, *storage*)
33
>Starts the @SIPApplication@ which initializes all the components in the correct order. The @storage@ is saved as an attribute which other entities like the @Configuration Manager@ will use to take the appropriate backend. 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.
34 1 Adrian Georgescu
35 147 Adrian Georgescu
*stop*(_self_)
36
>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.
37 1 Adrian Georgescu
38
39 147 Adrian Georgescu
h4. attributes
40 1 Adrian Georgescu
41 147 Adrian Georgescu
*running*
42 154 Tijmen de Mes
>@True@ if the SIPApplication is running (it has been started and it has not been told to stop), @False@ otherwise.
43 1 Adrian Georgescu
44 147 Adrian Georgescu
*storage*
45
>Holds an object which implements the @ISIPSimpleStorage@ interface which will be used to provide a storage facility to other middleware components.
46 1 Adrian Georgescu
47 147 Adrian Georgescu
*local_nat_type*
48
>String containing the detected local NAT type.
49 1 Adrian Georgescu
50 147 Adrian Georgescu
*alert_audio_mixer*
51
>The @AudioMixer@ object created on the alert audio device as defined by the configuration (by SIPSimpleSettings.audio.alert_device).
52 1 Adrian Georgescu
53 147 Adrian Georgescu
*alert_audio_bridge*
54
>An @AudioBridge@ where @IAudioPort@ objects can be added to playback sound to the alert device.
55 1 Adrian Georgescu
56 147 Adrian Georgescu
*alert_audio_device*
57
>An @AudioDevice@ which corresponds to the alert device as defined by the configuration. This will always be part of the alert_audio_bridge.
58 1 Adrian Georgescu
59 147 Adrian Georgescu
*voice_audio_mixer*
60
>The @AudioMixer@ object created on the voice audio device as defined by the configuration (by SIPSimpleSettings.audio.input_device and SIPSimpleSettings.audio.output_device).
61 1 Adrian Georgescu
62 147 Adrian Georgescu
*voice_audio_bridge*
63
>An @AudioBridge@ where @IAudioPort@ objects can be added to playback sound to the output device or record sound from the input device.
64 1 Adrian Georgescu
65 147 Adrian Georgescu
*voice_audio_device*
66
>An @AudioDevice@ which corresponds to the voice device as defined by the configuration. This will always be part of the voice_audio_bridge.
67 1 Adrian Georgescu
68
69 147 Adrian Georgescu
h4. notifications 
70 1 Adrian Georgescu
71
72
73
*SIPApplicationWillStart*
74 147 Adrian Georgescu
>This notification is sent just after the configuration has been loaded and the twisted thread started, but before any other components have been initialized.
75 158 Tijmen de Mes
76 153 Tijmen de Mes
>+_timestamp_+:
77 157 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
78 147 Adrian Georgescu
79 1 Adrian Georgescu
*SIPApplicationDidStart*
80 147 Adrian Georgescu
>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.
81 158 Tijmen de Mes
82 153 Tijmen de Mes
>+_timestamp_+:
83 157 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
84 1 Adrian Georgescu
85 147 Adrian Georgescu
*SIPApplicationWillEnd*
86 1 Adrian Georgescu
>This notification is sent as soon as the @stop()@ method has been called.
87 158 Tijmen de Mes
88 153 Tijmen de Mes
>+_timestamp_+:
89 157 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
90 1 Adrian Georgescu
91 147 Adrian Georgescu
*SIPApplicationDidEnd*
92
>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).
93 158 Tijmen de Mes
94 153 Tijmen de Mes
>+_timestamp_+:
95 157 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
96 147 Adrian Georgescu
97 1 Adrian Georgescu
*SIPApplicationFailedToStartTLS*
98 147 Adrian Georgescu
>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.
99 158 Tijmen de Mes
100 153 Tijmen de Mes
>+_timestamp_+:
101 157 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
102 158 Tijmen de Mes
103 153 Tijmen de Mes
>+_error_+:
104 157 Tijmen de Mes
>>The exception raised by the Engine which identifies the cause for not being able to start the TLS transport.
105 1 Adrian Georgescu
106
107
108 147 Adrian Georgescu
h2. Storage API
109
110
111
Different middleware components may need to store data, i.e. configuration files or XCAP documents. The @Storage API@ defines a collection of backends which other components will use to store their data.
112
113
114
h3. API Definition
115
116
117
The @Storage API@ currently requires the following attributes to be defined as per the @ISIPSimpleStorage@ interface:
118
119
*configuration_backend*
120
>The backend used for storing the configuration.
121
122
*xcap_storage_factory*
123
>Factory used to create XCAP storage backends for each account.
124
125
126
h3. Provided implementations
127
128
129
Two storage implementations are provided: *FileStorage* and *MemoryStorage* both located in the *sipsimple.storage* module.
130
131
132
h2. SIP Sessions
133
134
135
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.
136
137
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 [[SipMiddlewareApi#MediaStreamRegistry|MediaStreamRegistry]].
138
139
140
141
h3. SessionManager
142
143
144 1 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
145
146 147 Adrian Georgescu
The @sipsimple.session.SessionManager@ class is a singleton, which acts as the central aggregation point for sessions within the middleware.
147 1 Adrian Georgescu
Although it is mainly used internally, the application can use it to query information about all active sessions.
148
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 and closing all sessions when SIPApplication is stopped.
149
150
151 147 Adrian Georgescu
h4. attributes
152 1 Adrian Georgescu
153
154
155 147 Adrian Georgescu
*sessions*
156
>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.
157 1 Adrian Georgescu
158
159 147 Adrian Georgescu
h4. methods
160 1 Adrian Georgescu
161
162
163 147 Adrian Georgescu
*<notextile>__init__</notextile>*(_self_)
164
>Instantiate a new @SessionManager@ object.
165 1 Adrian Georgescu
166 147 Adrian Georgescu
167
*start*(_self_)
168
>Start the @SessionManager@ in order to be able to handle incoming sessions. This method is called automatically when SIPApplication is started. The application should not call this method directly.
169
170
*stop*(_self_)
171
>End all connected sessions. This method is called automatically when SIPApplication is stopped. The application should not call this method directly.
172
173
174
h3. Session
175
176
177 1 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
178
179 147 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.
180 1 Adrian Georgescu
181 155 Tijmen de Mes
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. State changes are triggered by methods called on the object by the application or by received network events. These states and their transitions are represented in the following diagram:
182 1 Adrian Georgescu
183 156 Tijmen de Mes
!sipsimple-core-invite-state-machine-2.png!
184 1 Adrian Georgescu
185 147 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.
186 1 Adrian Georgescu
187 147 Adrian Georgescu
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.
188 1 Adrian Georgescu
189
190 147 Adrian Georgescu
h4. methods
191 1 Adrian Georgescu
192
193
194 147 Adrian Georgescu
*<notextile>__init__</notextile>*(_self_, *account*)
195
>Creates a new @Session@ object in the @None@ state.
196 158 Tijmen de Mes
197 1 Adrian Georgescu
>+_account_+:
198 157 Tijmen de Mes
>>The local account to be associated with this @Session@.
199 1 Adrian Georgescu
200 147 Adrian Georgescu
*connect*(_self_, *to_header*, *routes*, *streams*, *is_focus*=@False@, *subject*=@None@)
201
>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.
202
>Before contacting the remote party, a @SIPSessionNewOutgoing@ notification will be emitted.
203
>If there is a failure or the remote party rejected the offer, a @SIPSessionDidFail@ notification will be sent.
204
>Any time a ringing indication is received from the remote party, a @SIPSessionGotRingIndication@ notification is sent.
205
>If the remote party accepted the session, a @SIPSessionWillStart@ notification will be sent, followed by a @SIPSessionDidStart@ notification when the session is actually established.
206
>This method may only be called while in the @None@ state.
207 158 Tijmen de Mes
208 1 Adrian Georgescu
>+_to_header_+:
209 157 Tijmen de Mes
>>A @sipsimple.core.ToHeader@ object representing the remote identity to initiate the session to.
210 158 Tijmen de Mes
211 147 Adrian Georgescu
>+_routes_+:
212 157 Tijmen de Mes
>>An iterable of @sipsimple.util.Route@ objects, specifying the IP, port and transport to the outbound proxy.
213
>>These routes will be tried in order, until one of them succeeds.
214 158 Tijmen de Mes
215 147 Adrian Georgescu
>+_streams_+:
216 157 Tijmen de Mes
>>A list of stream objects which will be offered to the remote endpoint.
217 158 Tijmen de Mes
218 147 Adrian Georgescu
>+_is_focus_+:
219 1 Adrian Georgescu
>>Boolean flag indicating if the @isfocus@ parameter should be added to the @Contact@ header according to RFC 4579.
220 158 Tijmen de Mes
221 147 Adrian Georgescu
>+_subject_+:
222
>>Session subject. If not None a @Subject@ header will be added with the specified value.
223 158 Tijmen de Mes
224 1 Adrian Georgescu
*send_ring_indication*(_self_)
225 147 Adrian Georgescu
>Sends a 180 provisional response in the case of an incoming session.
226
227
*accept*(_self_, *streams*)
228
>Calling this methods will accept an incoming session and move the state machine to the @accepting@ state.
229
>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.
230 1 Adrian Georgescu
>After this method is called, @SIPSessionWillStart@ followed by @SIPSessionDidStart@ will be emitted, or @SIPSessionDidFail@ on an error.
231 147 Adrian Georgescu
>This method may only be called while in the @incoming@ state.
232
  
233
>+_streams_+:
234 158 Tijmen de Mes
>>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.
235 147 Adrian Georgescu
236
*reject*(_self_, *code*=@603@, *reason*=@None@)
237
>Reject an incoming session and move it to the @terminating@ state, which eventually leads to the @terminated@ state.
238 1 Adrian Georgescu
>Calling this method will cause the @Session@ object to emit a @SIPSessionDidFail@ notification once the session has been rejected.
239 147 Adrian Georgescu
>This method may only be called while in the @incoming@ state.
240
  
241 1 Adrian Georgescu
>+_code_+:
242 158 Tijmen de Mes
>>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).
243 147 Adrian Georgescu
  
244
>+_reason_+:
245 158 Tijmen de Mes
>>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.
246 147 Adrian Georgescu
247 1 Adrian Georgescu
*accept_proposal*(_self_, *streams*)
248
>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.
249 147 Adrian Georgescu
>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.
250 1 Adrian Georgescu
>This method may only be called while in the @received_proposal@ state.
251
  
252 147 Adrian Georgescu
>+_streams_+:
253 158 Tijmen de Mes
>>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.
254 147 Adrian Georgescu
255
*reject_proposal*(_self_, *code*=@488@, *reason*=@None@)
256
>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.
257
>This method may only be called while in the @received_proposal@ state.
258 1 Adrian Georgescu
  
259 147 Adrian Georgescu
>+_code_+:
260 158 Tijmen de Mes
>>An integer which represents the SIP status code in the response which is to be sent. Usually, this is 488 (Not Acceptable Here).
261 147 Adrian Georgescu
  
262 1 Adrian Georgescu
>+_reason_+:
263 158 Tijmen de Mes
>>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.
264 1 Adrian Georgescu
265 147 Adrian Georgescu
*add_stream*(_self_, *stream*)
266
>Proposes a new stream to the remote party.
267
>Calling this method will cause a @SIPSessionGotProposal@ notification to be emitted.
268
>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.
269
>This method may only be called while in the @connected@ state.
270 1 Adrian Georgescu
271 147 Adrian Georgescu
*remove_stream*(_self_, *stream*)
272
>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).
273
>This method may only be called while in the @connected@ state.
274 1 Adrian Georgescu
275 147 Adrian Georgescu
*cancel_proposal*(_self_)
276
>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.
277 1 Adrian Georgescu
278 147 Adrian Georgescu
*hold*(_self_)
279
>Put the streams of the session which support the notion of hold on hold.
280
>This will cause a @SIPSessionDidChangeHoldState@ notification to be sent.
281
>This method may be called in any state and will send the re-INVITE as soon as it is possible.
282 1 Adrian Georgescu
283 147 Adrian Georgescu
*unhold*(_self_)
284
>Take the streams of the session which support the notion of hold out of hold.
285
>This will cause a @SIPSessionDidChangeHoldState@ notification to be sent.
286
>This method may be called in any state and will send teh re-INVITE as soon as it is possible.
287 1 Adrian Georgescu
288 147 Adrian Georgescu
*end*(_self_)
289
>This method may be called any time after the @Session@ has started in order to terminate the session by sending a BYE request.
290
>Right before termination a @SIPSessionWillEnd@ notification is sent, after termination @SIPSessionDidEnd@ is sent.
291 1 Adrian Georgescu
292 147 Adrian Georgescu
*transfer*(_self_, *target_uri*,  *replaced_session*=@None@)
293
>Proposes a blind call transfer to a new target URI or assisted transfer to an URI belonging to an already established session. 
294 1 Adrian Georgescu
295 147 Adrian Georgescu
*accept_transfer*(_self_)
296
>Accepts an incoming call transfer request.
297 1 Adrian Georgescu
298 147 Adrian Georgescu
*reject_transfer*(_self_, *code*=@486@, *reason_=@None@)
299
>Rejects an incoming call transfer request.
300 1 Adrian Georgescu
301
302
303 147 Adrian Georgescu
h4. attributes
304 1 Adrian Georgescu
305
306
307 147 Adrian Georgescu
*state*
308
>The state the object is currently in, being one of the states from the diagram above.
309 1 Adrian Georgescu
310 147 Adrian Georgescu
*account*
311
>The @sipsimple.account.Account@ or @sipsimple.account.BonjourAccount@ object that the @Session@ is associated with.
312
>On an outbound session, this is the account the application specified on object instantiation.
313 1 Adrian Georgescu
314 147 Adrian Georgescu
*direction*
315
>A string indicating the direction of the initial negotiation of the session.
316
>This can be either @None@, "incoming" or "outgoing".
317 1 Adrian Georgescu
318 147 Adrian Georgescu
*transport*
319
>A string representing the transport this @Session@ is using: @"udp"@, @"tcp"@ or @"tls"@.
320 1 Adrian Georgescu
321 147 Adrian Georgescu
*start_time*
322
>The time the session started as a @datetime.datetime@ object, or @None@ if the session was not yet started.
323 1 Adrian Georgescu
324 147 Adrian Georgescu
*stop_time*
325
>The time the session stopped as a @datetime.datetime@ object, or @None@ if the session has not yet terminated.
326 1 Adrian Georgescu
327 147 Adrian Georgescu
*on_hold*
328
>Boolean indicating whether the session was put on hold, either by the local or the remote party.
329 1 Adrian Georgescu
330 147 Adrian Georgescu
*remote_user_agent*
331
>A string indicating the remote user agent, if it provided one.
332
>Initially this will be @None@, it will be set as soon as this information is received from the remote party (which may be never).
333 1 Adrian Georgescu
334 147 Adrian Georgescu
*local_identity*
335
>The @sipsimple.core.FrozenFromHeader@ or @sipsimple.core.FrozenToHeader@ identifying the local party, if the session is active, @None@ otherwise.
336 1 Adrian Georgescu
337 147 Adrian Georgescu
*remote_identity*
338
>The @sipsimple.core.FrozenFromHeader@ or @sipsimple.core.FrozenToHeader@ identifying the remote party, if the session is active, @None@ otherwise.
339 1 Adrian Georgescu
340 147 Adrian Georgescu
*streams*
341
>A list of the currently active streams in the @Session@.
342 1 Adrian Georgescu
343 147 Adrian Georgescu
*proposed_streams*
344
>A list of the currently proposed streams in the @Session@, or @None@ if there is no proposal in progress.
345 1 Adrian Georgescu
346 147 Adrian Georgescu
*conference*
347
>A @ConferenceHandler@ object instance (or Null). It can be later used to add/remove participants from a remote conference.
348 1 Adrian Georgescu
349 147 Adrian Georgescu
*subject*
350
>The session subject as a unicode object.
351 1 Adrian Georgescu
352
*replaced_session*
353 147 Adrian Georgescu
>A @Session@ object instance (or Null). It can be used for assisted call transfer.
354
355
*transfer_handler*
356 1 Adrian Georgescu
>A @TransferHandler@ object instance (or Null). It is used for managing the call transfer process.
357
358
*transfer_info*
359
>A @TransferInfo@ object instance (or Null). It is used for describing the details of a call transfer operation.
360
361
362
h4. notifications
363 147 Adrian Georgescu
364
365 1 Adrian Georgescu
366 147 Adrian Georgescu
*SIPSessionNewIncoming*
367
>Will be sent when a new incoming @Session@ is received.
368
>The application should listen for this notification to get informed of incoming sessions.
369 1 Adrian Georgescu
  
370 55 Adrian Georgescu
>+_timestamp_+:
371 158 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
372 147 Adrian Georgescu
  
373
>+_streams_+:
374 158 Tijmen de Mes
>>A list of streams that were proposed by the remote party.
375 147 Adrian Georgescu
376
*SIPSessionNewOutgoing*
377
>Will be sent when the application requests a new outgoing @Session@.
378 1 Adrian Georgescu
  
379 147 Adrian Georgescu
>+_timestamp_+:
380 158 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
381 147 Adrian Georgescu
  
382
>+_streams_+:
383 158 Tijmen de Mes
>>A list of streams that were proposed to the remote party.
384 147 Adrian Georgescu
385 67 Luci Stanescu
*SIPSessionGotRingIndication*
386 147 Adrian Georgescu
>Will be sent when an outgoing @Session@ receives an indication that a remote device is ringing.
387 94 Adrian Georgescu
  
388 147 Adrian Georgescu
>+_timestamp_+:
389 158 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
390 147 Adrian Georgescu
391
*SIPSessionGotProvisionalResponse*
392 67 Luci Stanescu
>Will be sent whenever the @Session@ receives a provisional response as a result of sending a (re-)INVITE.
393 147 Adrian Georgescu
  
394
>+_timestamp_+:
395 158 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
396 1 Adrian Georgescu
  
397 147 Adrian Georgescu
>+_code_+:
398 158 Tijmen de Mes
>>The SIP status code received.
399 147 Adrian Georgescu
  
400 94 Adrian Georgescu
>+_reason_+:
401 158 Tijmen de Mes
>>The SIP status reason received.
402 1 Adrian Georgescu
403 147 Adrian Georgescu
*SIPSessionWillStart*
404
>Will be sent just before a @Session@ completes negotiation.
405
>In terms of SIP, this is sent after the final response to the @INVITE@, but before the @ACK@.
406
  
407
>+_timestamp_+:
408 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
409 1 Adrian Georgescu
410 147 Adrian Georgescu
*SIPSessionDidStart*
411
>Will be sent when a @Session@ completes negotiation and all the streams have started.
412
>In terms of SIP this is sent after the @ACK@ was sent or received.
413 1 Adrian Georgescu
  
414
>+_timestamp_+:
415 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
416 147 Adrian Georgescu
  
417 1 Adrian Georgescu
>+_streams_+:
418 159 Tijmen de Mes
>>The list of streams which now form the active streams of the @Session@.
419 1 Adrian Georgescu
420
*SIPSessionDidFail*
421 147 Adrian Georgescu
>This notification is sent whenever the session fails before it starts.
422
>The failure reason is included in the data attributes.
423
>This notification is never followed by @SIPSessionDidEnd@.
424 1 Adrian Georgescu
  
425
>+_timestamp_+:
426 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
427 147 Adrian Georgescu
  
428
>+_originator_+:
429 159 Tijmen de Mes
>>A string indicating the originator of the @Session@. This will either be "local" or "remote".
430 1 Adrian Georgescu
  
431 147 Adrian Georgescu
>+_code_+:
432 159 Tijmen de Mes
>>The SIP error code of the failure.
433 147 Adrian Georgescu
  
434 1 Adrian Georgescu
>+_reason_+:
435 159 Tijmen de Mes
>>A SIP status reason.
436 147 Adrian Georgescu
  
437
>+_failure_reason_+:
438 159 Tijmen de Mes
>>A string which represents the reason for the failure, such as @"user_request"@, @"missing ACK"@, @"SIP core error..."@.
439 1 Adrian Georgescu
440 147 Adrian Georgescu
*SIPSessionWillEnd*
441
>Will be sent just before terminating a @Session@.
442 1 Adrian Georgescu
  
443
>+_timestamp_+:
444 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
445 147 Adrian Georgescu
446
*SIPSessionDidEnd*
447 1 Adrian Georgescu
>Will be sent always when a @Session@ ends as a result of remote or local session termination.
448 147 Adrian Georgescu
  
449
>+_timestamp_+:
450 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
451 1 Adrian Georgescu
  
452
>+_originator_+:
453 159 Tijmen de Mes
>>A string indicating who originated the termination. This will either be "local" or "remote".
454 147 Adrian Georgescu
  
455
>+_end_reason_+:
456 159 Tijmen de Mes
>>A string representing the termination reason, such as @"user_request"@, @"SIP core error..."@.
457 1 Adrian Georgescu
458 147 Adrian Georgescu
*SIPSessionDidChangeHoldState*
459
>Will be sent when the session got put on hold or removed from hold, either by the local or the remote party.
460 1 Adrian Georgescu
  
461
>+_timestamp_+:
462 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
463 147 Adrian Georgescu
  
464
>+_originator_+:
465 159 Tijmen de Mes
>>A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
466 147 Adrian Georgescu
  
467
>+_on_hold_+:
468 159 Tijmen de Mes
>>@True@ if there is at least one stream which is on hold and @False@ otherwise.
469 1 Adrian Georgescu
  
470 147 Adrian Georgescu
>+_partial_+:
471 159 Tijmen de Mes
>>@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.
472 147 Adrian Georgescu
473
*SIPSessionGotProposal*
474 1 Adrian Georgescu
>Will be sent when either the local or the remote party proposes to add streams to the session.
475 147 Adrian Georgescu
  
476 1 Adrian Georgescu
>+_timestamp_+:
477 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
478 147 Adrian Georgescu
  
479
>+_originator_+:
480 159 Tijmen de Mes
>>The party that initiated the stream proposal, can be either "local" or "remote".
481 147 Adrian Georgescu
  
482
>+_streams_+:
483 159 Tijmen de Mes
>>A list of streams that were proposed.
484 147 Adrian Georgescu
485
*SIPSessionGotRejectProposal*
486
>Will be sent when either the local or the remote party rejects a proposal to have streams added to the session.
487 1 Adrian Georgescu
  
488 147 Adrian Georgescu
>+_timestamp_+:
489 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
490 147 Adrian Georgescu
  
491 1 Adrian Georgescu
>+_originator_+:
492 159 Tijmen de Mes
>>The party that initiated the stream proposal, can be either "local" or "remote".
493 147 Adrian Georgescu
  
494
>+_code_+:
495 159 Tijmen de Mes
>>The code with which the proposal was rejected.
496 147 Adrian Georgescu
  
497
>+_reason_+:
498 159 Tijmen de Mes
>>The reason for rejecting the stream proposal.
499 1 Adrian Georgescu
  
500 147 Adrian Georgescu
>+_streams_+:
501 159 Tijmen de Mes
>>The list of streams which were rejected.
502 147 Adrian Georgescu
503
*SIPSessionGotAcceptProposal*
504
>Will be sent when either the local or the remote party accepts a proposal to have stream( added to the session.
505
  
506 1 Adrian Georgescu
>+_timestamp_+:
507 159 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
508 147 Adrian Georgescu
  
509
>+_originator_+:
510 160 Tijmen de Mes
>>The party that initiated the stream proposal, can be either "local" or "remote".
511 1 Adrian Georgescu
  
512
>+_streams_+:
513 160 Tijmen de Mes
>>The list of streams which were accepted.
514 147 Adrian Georgescu
  
515
>+_proposed_streams_+:
516 160 Tijmen de Mes
>>The list of streams which were originally proposed.
517 147 Adrian Georgescu
518
*SIPSessionHadProposalFailure*
519
>Will be sent when a re-INVITE fails because of an internal reason (such as a stream not being able to start).
520 1 Adrian Georgescu
  
521 147 Adrian Georgescu
>+_timestamp_+:
522 160 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
523 147 Adrian Georgescu
  
524
>+_failure_reason_+:
525 160 Tijmen de Mes
>>The error which caused the proposal to fail.
526 1 Adrian Georgescu
  
527 147 Adrian Georgescu
>+_streams_+:
528 160 Tijmen de Mes
>>The streams which were part of this proposal.
529 147 Adrian Georgescu
530
*SIPSessionDidRenegotiateStreams*
531
>Will be sent when a media stream is either activated or deactivated.
532
>An application should listen to this notification in order to know when a media stream can be used.
533
  
534
>+_timestamp_+:
535 160 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
536 147 Adrian Georgescu
  
537
>+_action_+:
538 160 Tijmen de Mes
>>A string which is either @"add"@ or @"remove"@ which specifies what happened to the streams the notificaton referes to
539 1 Adrian Georgescu
  
540 147 Adrian Georgescu
>+_streams_+:
541 160 Tijmen de Mes
>>A list with the streams which were added or removed.
542 1 Adrian Georgescu
543 147 Adrian Georgescu
*SIPSessionDidProcessTransaction*
544
>Will be sent whenever a SIP transaction is complete in order to provide low-level details of the progress of the INVITE dialog.
545
  
546 160 Tijmen de Mes
>>+_timestamp_+:
547 165 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
548 147 Adrian Georgescu
  
549
>+_originator_+:
550 160 Tijmen de Mes
>>The initiator of the transaction, @"local"@ or @"remote"@.
551 147 Adrian Georgescu
  
552 1 Adrian Georgescu
>+_method_+:
553 160 Tijmen de Mes
>>The method of the request.
554 147 Adrian Georgescu
  
555
>+_code_+:
556 160 Tijmen de Mes
>>The SIP status code of the response.
557 1 Adrian Georgescu
  
558 147 Adrian Georgescu
>+_reason_+:
559 160 Tijmen de Mes
>>The SIP status reason of the response.
560 147 Adrian Georgescu
  
561 1 Adrian Georgescu
>+_ack_received_+:
562 165 Tijmen de Mes
>>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.
563 147 Adrian Georgescu
564
*SIPSessionTransferNewOutgoing*
565 160 Tijmen de Mes
>>Will be sent whenever a SIP session initiates an outgoing call transfer request.
566 147 Adrian Georgescu
  
567
>+_timestamp_+:
568 160 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
569 147 Adrian Georgescu
  
570
>+_transfer_destination_+:
571 160 Tijmen de Mes
>>The destination SIP URI of the call transfer request.
572 147 Adrian Georgescu
  
573 1 Adrian Georgescu
>+_transfer_source_+:
574 160 Tijmen de Mes
>>The source SIP URI of the call transfer request.
575 147 Adrian Georgescu
576 1 Adrian Georgescu
*SIPSessionTransferDidStart*
577
>Will be sent whenever a call transfer has been started.
578 147 Adrian Georgescu
  
579
>+_timestamp_+:
580 160 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
581 147 Adrian Georgescu
582
*SIPSessionTransferDidFail*
583
>Will be sent whenever a call transfer request has failed.
584
  
585
>+_timestamp_+:
586 160 Tijmen de Mes
>>A @datetime.datetime@ object indicating when the notification was sent.
587 147 Adrian Georgescu
  
588
>+_code_+:
589 160 Tijmen de Mes
>>The SIP failure code reported by the SIP stack.
590 147 Adrian Georgescu
  
591
>+_reason_+:
592 160 Tijmen de Mes
>>The reason of the failure as a string.
593 147 Adrian Georgescu
594
595 161 Tijmen de Mes
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 [[SipSessionExample|Minimalist Session Example code]].
596 166 Tijmen de Mes
597
598
599
h3. IMediaStream
600
601
602
Implemented in [browser:sipsimple/streams/+init+.py]
603
604
This interface describes the API which the @Session@ uses to communicate with the streams. All streams used by the @Session@ +must+ respect this interface.
605
606
607
h4. methods
608
609
610
611
*<notextile>__init__</notextile>*(_self_, _account_)
612
>Initializes the generic stream instance.
613
614
*new_from_sdp*(_cls_, _account_, _remote_sdp_, _stream_index_)
615
>A classmethod which returns an instance of this stream implementation if the sdp is accepted by the stream or None otherwise.
616
  
617
>+_account_+:
618
>>The @sipsimple.account.Account@ or @sipsimple.account.BonjourAccount@ object the session which this stream would be part of is associated with.
619
  
620
>+_remote_sdp_+:
621
>>The @FrozenSDPSession@ which was received by the remote offer.
622
  
623
>+_stream_index_+:
624
>>An integer representing the index within the list of media streams within the whole SDP which this stream would be instantiated for. 
625
626
*get_local_media*(_self_, _for_offer_)
627
>Return an @SDPMediaStream@ which represents an offer for using this stream if @for_offer@ is @True@ and a response to an SDP proposal otherwise.
628
  
629
>+_for_offer_+:
630
>>@True@ if the @SDPMediaStream@ will be used for an SDP proposal and @False@ if for a response.
631
632
*initialize*(_self_, _session_, _direction_)
633
>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.
634
  
635
>+_session_+:
636
>>The @Session@ object this stream will be part of.
637
  
638
>+_direction_+:
639
>>@"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.
640
641
*start*(_self_, _local_sdp_, _remote_sdp_, _stream_index_)
642
>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.
643
  
644
>+_local_sdp_+:
645
>>The @FrozenSDPSession@ which is used by the local endpoint.
646
  
647
>+_remote_sdp_+:
648
>>The @FrozenSDPSession@ which is used by the remote endpoint.
649
  
650
>+_stream_index_+:
651
>>An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
652
653
*validate_update*(_self_, _remote_sdp_, _stream_index_)
654
>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@. 
655
  
656
>+_remote_sdp_+:
657
>>The @FrozenSDPSession@ which is used by the remote endpoint.
658
  
659
>+_stream_index_+:
660
>>An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
661
662
*update*(_self_, _local_sdp_, _remote_sdp_, _stream_index_)
663
>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.
664
  
665
>+_local_sdp_+:
666
>>The @FrozenSDPSession@ which is used by the local endpoint.
667
  
668
>+_remote_sdp_+:
669
>>The @FrozenSDPSession@ which is used by the remote endpoint.
670
  
671
>+_stream_index_+:
672
>>An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. 
673
674
*hold*(_self_)
675
>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.
676
677
*unhold*(_self_)
678
>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.
679
680
*deactivate*(_self_)
681
>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.
682
683
*end*(_self_)
684
>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.
685
686
687
h4. attributes
688
689
690
691
*type* (class attribute)
692
>A string identifying the stream type (eg: @"audio"@, @"video"@).
693
694
*priority* (class attribute)
695
>An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority).
696
697
*hold_supported*
698
>True if the stream supports hold
699
700
*on_hold_by_local*
701
>True if the stream is on hold by the local party
702
703
*on_hold_by_remote*
704
>True if the stream is on hold by the remote
705
706
*on_hold*
707
>True if either on_hold_by_local or on_hold_by_remote is true
708
709
710
h4. notifications
711
712
713
These notifications must be generated by all streams in order for the @Session@ to know the state of the stream.
714
715
716
*MediaStreamDidInitialize*
717
>Sent when the stream has been successfully initialized.
718
719
*MediaStreamDidStart*
720
>Sent when the stream has been successfully started.
721
722
*MediaStreamDidFail*
723
>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).
724
725
*MediaStreamWillEnd*
726
>Sent immediately after the @end()@ method is called.
727
728
*MediaStreamDidEnd*
729
>Sent when the @end()@ method finished closing the stream.
730 167 Tijmen de Mes
731
h3. MediaStreamRegistrar
732
733
734
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.
735
736
<pre>
737
from zope.interface import implements
738
739
from sipsimple.streams import IMediaStream, MediaStreamRegistrar
740
741
742
class MyStream(object):
743
  __metaclass__ = MediaStreamRegistrar
744
745
  implements(IMediaStream)
746
  
747
[...] 
748
</pre>
749
750
h3. AudioStream
751
752
753
Implemented in [browser:sipsimple/streams/rtp.py]
754
755
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:
756
757
<pre>
758
Content-Type: application/sdp
759
Content-Length:  1093
760
761
v=0
762
o=- 3467525278 3467525278 IN IP4 192.168.1.6
763
s=blink-0.10.7-beta
764
c=IN IP4 80.101.96.20
765
t=0 0
766
m=audio 55328 RTP/AVP 104 103 102 3 9 0 8 101
767
a=rtcp:55329 IN IP4 80.101.96.20
768
a=rtpmap:104 speex/32000
769
a=rtpmap:103 speex/16000
770
a=rtpmap:102 speex/8000
771
a=rtpmap:3 GSM/8000
772
a=rtpmap:9 G722/8000
773
a=rtpmap:0 PCMU/8000
774
a=rtpmap:8 PCMA/8000
775
a=rtpmap:101 telephone-event/8000
776
a=fmtp:101 0-15
777
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:esI6DbLY1+Aceu0JNswN9Z10DcFx5cZwqJcu91jb
778
a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:SHuEMm1BYJqOF4udKl73EaCwnsI57pO86bYKsg70
779
a=ice-ufrag:2701ed80
780
a=ice-pwd:6f8f8281
781
a=candidate:S 1 UDP 31 80.101.96.20 55328 typ srflx raddr 192.168.1.6 rport 55328
782
a=candidate:H 1 UDP 23 192.168.1.6 55328 typ host
783
a=candidate:H 1 UDP 23 10.211.55.2 55328 typ host
784
a=candidate:H 1 UDP 23 10.37.129.2 55328 typ host
785
a=candidate:S 2 UDP 30 80.101.96.20 55329 typ srflx raddr 192.168.1.6 rport 55329
786
a=candidate:H 2 UDP 22 192.168.1.6 55329 typ host
787
a=candidate:H 2 UDP 22 10.211.55.2 55329 typ host
788
a=candidate:H 2 UDP 22 10.37.129.2 55329 typ host
789
a=sendrecv
790
</pre>
791
792
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.
793
794
795
h4. methods
796
797
798
799
*start_recording*(_self_, *filename*=@None@)
800
>If an audio stream is present within this session, calling this method will record the audio to a @.wav@ file.
801
>Note that when the session is on hold, nothing will be recorded to the file.
802
>Right before starting the recording a @SIPSessionWillStartRecordingAudio@ notification will be emitted, followed by a @SIPSessionDidStartRecordingAudio@.
803
>This method may only be called while the stream is started.
804
  
805 1 Adrian Georgescu
>+_filename_+:
806 168 Tijmen de Mes
>>The name of the @.wav@ file to record to.
807
>>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.
808 167 Tijmen de Mes
809
*stop_recording*(_self_)
810
>This will stop a previously started recording.
811
>Before stopping, a @SIPSessionWillStopRecordingAudio@ notification will be sent, followed by a @SIPSessionDidStopRecordingAudio@.
812
813
*send_dtmf*(_self_, *digit*)
814
>If the audio stream is started, sends a DTMF digit to the remote party.
815
  
816
>+_digit_+:
817
>>This should a string of length 1, containing a valid DTMF digit value (0-9, A-D, * or #).
818
819
820
h4. attributes
821
822
823
824
*sample_rate*
825
>If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
826
827
*codec*
828
>If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
829
830
*srtp_active*
831
>If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
832
833
*ice_active*
834
>@True@ if the ICE candidates negotiated are being used, @False@ otherwise.
835
836
*local_rtp_address*
837
>If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
838
839
*local_rtp_port*
840
>If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
841
842
*remote_rtp_address_sdp*
843
>If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
844
845
*remote_rtp_port_sdp*
846
>If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
847
848
*remote_rtp_address_received*
849
>If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
850
851
*remote_rtp_port_received*
852
>If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
853
854
*local_rtp_candidate_type*
855
>The local ICE candidate type which was selected by the ICE negotiation if it succeeded and @None@ otherwise.
856
857
*remote_rtp_candidate_type*
858
>The remote ICE candidate type which was selected by the ICE negotiation if it succeeded and @None@ otherwise.
859
860
*recording_filename*
861
>If the audio stream is currently being recorded to disk, this property contains the name of the @.wav@ file being recorded to.
862
863
864
h4. notifications
865
866
867
868
*AudioStreamDidChangeHoldState*
869
>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.
870
  
871
>+_timestamp_+:
872
>>A @datetime.datetime@ object indicating when the notification was sent.
873
  
874
>+_originator_+:
875
>>A string representing the party which requested the hold change, @"local"@ or @"remote"@
876
  
877
>+_on_hold_+:
878
>>A boolean indicating the new hold state from the point of view of the originator.
879
880
*AudioStreamWillStartRecordingAudio_
881
>Will be sent when the application requested that the audio stream be recorded to a @.wav@ file, just before recording starts.
882
  
883
>+_timestamp_+:
884
>>A @datetime.datetime@ object indicating when the notification was sent.
885
  
886
>+_filename_+:
887
>>The full path to the @.wav@ file being recorded to.
888
889
*AudioStreamDidStartRecordingAudio*
890
>Will be sent when the application requested that the audio stream be recorded to a @.wav@ file, just after recording started.
891
  
892
>+_timestamp_+:
893
>>A @datetime.datetime@ object indicating when the notification was sent.
894
  
895
>+_filename_+:
896
>>The full path to the @.wav@ file being recorded to.
897
898
*AudioStreamWillStopRecordingAudio*
899
>Will be sent when the application requested ending the recording to a @.wav@ file, just before recording stops.
900
  
901
>+_timestamp_+:
902
>>A @datetime.datetime@ object indicating when the notification was sent.
903
  
904
>+_filename_+:
905
>>The full path to the @.wav@ file being recorded to.
906
907
*AudioStreamDidStopRecordingAudio*
908
>Will be sent when the application requested ending the recording to a @.wav@ file, just after recording stoped.
909
  
910
>+_timestamp_+:
911
>>A @datetime.datetime@ object indicating when the notification was sent.
912
  
913
>+_filename_+:
914
>>The full path to the @.wav@ file being recorded to.
915
916
*AudioStreamDidChangeRTPParameters*
917
>This notification is sent when the RTP parameters are changed, such as codec, sample rate, RTP port etc.
918
  
919
>+_timestamp_+:
920
>>A @datetime.datetime@ object indicating when the notification was sent.
921
922
*AudioStreamGotDTMF*
923
>Will be send if there is a DMTF digit received from the remote party on the audio stream. 
924
  
925
>+_timestamp_+:
926
>>A @datetime.datetime@ object indicating when the notification was sent.
927
  
928
>+_digit_+:
929
>>The DTMF digit that was received, in the form of a string of length 1.
930
931
*AudioStreamICENegotiationStateDidChange*
932
>This notification is proxied from the @RTPTransport@ and as such has the same data as the @RTPTransportICENegotiationStateDidChange@.
933
934
*AudioStreamICENegotiationDidSucceed*
935
>This notification is proxied from the @RTPTransport@ and as such has the same data as the @RTPTransportICENegotiationDidSucceed@.
936
937
*AudioStreamICENegotiationDidFail*
938
>This notification is proxied from the @RTPTransport@ and as such has the same data as the @RTPTransportICENegotiationDidFail@.
939
940
*AudioStreamDidTimeout*
941
>This notification is proxied from the @RTPTransport@. It's sent when the RTP transport did not receive any data after the specified amount of time (rtp.timeout setting in the @Account@).
942 169 Tijmen de Mes
943
944
h3. MSRPStreamBase
945
946
947
Implemented in [browser:sipsimple/streams/msrp.py]
948
949
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.
950
951
952
h4. methods
953
954
 
955
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.
956
957
958
h4. attributes
959
960
961
The attributes defined in the @IMediaStream@ interface which are not provided by this class are:
962
* type
963
* priority
964
965
In addition, the following attributes need to be defined in the subclass in order for the @MSRPStreamBase@ class to take the correct decisions
966
967
*media_type*
968
>The media type as included in the SDP (eg. @"message"@, @"application"@).
969
970
*accept_types*
971
>A list of the MIME types which should be accepted by the stream (this is also sent within the SDP).
972
973
*accept_wrapped_types*
974
>A list of the MIME types which should be accepted by the stream while wrapped in a @message/cpim@ envelope.
975
976
*use_msrp_session*
977
>A boolean indicating whether or not an @MSRPSession@ should be used.
978
979
980
h4. notifications
981
982
983
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.
984
985
986
*MSRPTransportTrace*
987
>This notification is sent when an MSRP message is received for logging purposes.
988
  
989
>+_timestamp_+:
990
>>A @datetime.datetime@ object indicating when the notification was sent.
991
  
992
>+_direction_+:
993
>>The direction of the message, @"incoming"@ or @"outgoing"@.
994
  
995
>+_data_+:
996
>>The MSRP message as a string.
997
998
*MSRPLibraryLog*
999
>This notification is sent anonymously whenever the MSRP library needs to log any information.
1000
  
1001
>+_timestamp_+:
1002
>>A @datetime.datetime@ object indicating when the notification was sent.
1003
  
1004
>+_message_+:
1005
>>The log message as a string.
1006
  
1007
>+_level_+:
1008
>>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.
1009 170 Tijmen de Mes
1010
h3. ChatStream
1011
1012
1013
Implemented in [browser:sipsimple/streams/msrp.py]
1014
1015
@sipsimple.streams.msrp.ChatStream@ implements session-based Instant Messaging (IM) over MSRP. This class performs the following functions:
1016
1017
* automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types
1018
* unwraps incoming Message/CPIM messages; for each incoming message, the @ChatStreamGotMessage@ notification is posted
1019
* composes iscomposing payloads and reacts to those received by sending the @ChatStreamGotComposingIndication@ notification
1020
1021
An example of an SDP created using this class follows:
1022
1023
<pre>
1024
Content-Type: application/sdp
1025
Content-Length:   283
1026
1027
v=0
1028
o=- 3467525214 3467525214 IN IP4 192.168.1.6
1029
s=blink-0.10.7-beta
1030
c=IN IP4 192.168.1.6
1031
t=0 0
1032
m=message 2855 TCP/TLS/MSRP *
1033
a=path:msrps://192.168.1.6:2855/ca7940f12ddef14c3c32;tcp
1034
a=accept-types:message/cpim text/* application/im-iscomposing+xml
1035
a=accept-wrapped-types:*
1036
</pre>
1037
1038
1039
h4. methods
1040
1041
1042
1043
*<notextile>__init__</notextile>*(_self_, *account*, *direction*=@'sendrecv'@)
1044
>Initializes the ChatStream instance.
1045
1046
1047
*send_message*(_self_, *content*, *content_type*=@'text/plain'@, *recipients*=@None@, *courtesy_recipients*=@None@, *subject*=@None@, _timestamp_=@None@, *required*=@None@, *additional_headers*=@None@)
1048
>Sends an IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be
1049
>queued until the stream starts.
1050
>Returns the generated MSRP message ID.
1051
  
1052
content:
1053
>>The content of the message.
1054
  
1055
>+_content_type_+:
1056
>>Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case);
1057
>otherwise, Content-Type of MSRP message.
1058
  
1059
>+_recipients_+:
1060
>>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.
1061
>May only differ from the default one if the remote party supports private messages. If it does not, a @ChatStreamError@ will be raised.
1062
  
1063
>+_courtesy_recipients_+:
1064
>>The list of @CPIMIdentity@ objects which will be used for the @cc@ header of the CPIM wrapper.
1065
>May only be specified if the remote party supports private messages and CPIM is supported. If it does not, a @ChatStreamError@ will be raised.
1066
  
1067
>+_subject_+:
1068
>>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.
1069
  
1070
>+_required_+:
1071
>>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.
1072
  
1073
>+_additional_headers_+:
1074
>>A list of MSRP header objects which will be added to this CPIM message. If CPIM is not supported, a @ChatStreamError@ will be raised.
1075
  
1076
>+_timestamp_+:
1077
>>A @datetime.datetime@ object representing the timestamp to put on the CPIM wrapper of the message.
1078
>When set to @None@, a default one representing the current moment will be added.
1079
1080
 These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses:
1081
<pre>
1082
Failure-Report: partial
1083
Success-Report: yes
1084
</pre>
1085
1086
1087
*send_composing_indication*(_self_, _state_, _refresh_, _last_active=None_, _recipients=None_)
1088
>Sends an is-composing message to the listed recipients.
1089
  
1090
>+_state_+:
1091
>>The state of the endpoint, @"active"@ or @"idle"@.
1092
  
1093
>+_refresh_+:
1094
>>How often the local endpoint will send is-composing indications to keep the state from being reverted to @"idle"@.
1095
  
1096
>+_last_active_+:
1097
>>A @datatime.datetime@ object representing the moment when the local endpoint was last active.
1098
  
1099
>+_recipients_+:
1100
>>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.
1101
>May only differ from the default one if the remote party supports private messages. If it does not, a @ChatStreamError@ will be raised.
1102
1103
1104
h4. notifications
1105
1106
1107
1108
*ChatStreamGotMessage*
1109
>Sent whenever a new incoming message is received,
1110
  
1111
>+_timestamp_+:
1112
>>A @datetime.datetime@ object indicating when the notification was sent.
1113
  
1114
>+_message_+:
1115
>>A @ChatMessage@ or @CPIMMessage@ instance, depending on whether a CPIM message was received or not.
1116
1117
*ChatStreamDidDeliverMessage*
1118
>Sent when a successful report is received.
1119
  
1120
>+_timestamp_+:
1121
>>A @datetime.datetime@ object indicating when the notification was sent.
1122
  
1123
>+_message_id_+:
1124
>>Text identifier of the message.
1125
  
1126
>+_code_+:
1127
>>The status code received. Will always be 200 for this notification.
1128
  
1129
>+_reason_+:
1130
>>The status reason received.
1131
  
1132
>+_chunk_+:
1133
>>A @msrplib.protocol.MSRPData@ instance providing all the MSRP information about the report.
1134
1135
*ChatStreamDidNotDeliverMessage*
1136
>Sent when a failure report is received.
1137
  
1138
>+_timestamp_+:
1139
>>A @datetime.datetime@ object indicating when the notification was sent.
1140
  
1141
>+_message_id_+:
1142
>>Text identifier of the message.
1143
  
1144
>+_code_+:
1145
>>The status code received.
1146
  
1147
>+_reason_+:
1148
>>The status reason received.
1149
  
1150
>+_chunk_+:
1151
>>A @msrplib.protocol.MSRPData@ instance providing all the MSRP information about the report.
1152
1153
*ChatStreamDidSendMessage*
1154
>Sent when an outgoing message has been sent.
1155
  
1156
>+_timestamp_+:
1157
>>A @datetime.datetime@ object indicating when the notification was sent.
1158
  
1159
>+_message_+:
1160
>>A @msrplib.protocol.MSRPData@ instance providing all the MSRP information about the sent message.
1161
1162
*ChatStreamGotComposingIndication*
1163
>Sent when a is-composing payload is received.
1164
  
1165
>+_timestamp_+:
1166
>>A @datetime.datetime@ object indicating when the notification was sent.
1167
  
1168
>+_state_+:
1169
>>The state of the endpoint, @"active"@ or @"idle"@.
1170
  
1171
>+_refresh_+:
1172
>>How often the remote endpoint will send is-composing indications to keep the state from being reverted to @"idle"@. May be @None@.
1173
  
1174
>+_last_active_+:
1175
>>A @datatime.datetime@ object representing the moment when the remote endpoint was last active. May be @None@.
1176
  
1177
>+_content_type_+:
1178
>>The MIME type of message being composed. May be @None@.
1179
  
1180
>+_sender_+:
1181
>>The @ChatIdentity@ or @CPIMIdentity@ instance which identifies the sender of the is-composing indication.
1182
  
1183
>+_recipients_+:
1184
>>The @ChatIdentity@ or @CPIMIdentity@ instances list which identifies the recipients of the is-composing indication.