Project

General

Profile

SipMiddlewareApi » History » Version 55

Adrian Georgescu, 11/17/2009 07:14 PM

1 1 Adrian Georgescu
= Middleware API =
2
3
[[TOC(WikiStart, Sip*, depth=3)]]
4
5 21 Adrian Georgescu
This chapter describes the event driven middleware API that can be used by a developer to build a user interface for SIP SIMPLE client library.  
6 14 Adrian Georgescu
7 54 Adrian Georgescu
 * For sub-systems communications the Middleware uses the [http://pypi.python.org/pypi/python-application/ Notification Bus] provided by [http://pypi.python.org/pypi/python-application/ python-application]
8 49 Adrian Georgescu
 * For configuration the Middleware uses the [wiki:SipConfigurationAPI Configuration API] to access General and SIP account  settings
9 1 Adrian Georgescu
10 53 Adrian Georgescu
[[Image(sipsimple-middleware.png, align=center, width=800)]]
11 1 Adrian Georgescu
12 50 Adrian Georgescu
== SIPApplication ==
13 1 Adrian Georgescu
14 50 Adrian Georgescu
Implemented in [browser:sipsimple/api.py]
15 1 Adrian Georgescu
16 50 Adrian Georgescu
Implements a high-level application responsable for starting and stopping
17
various sub-systems required to implement a fully featured SIP User Agent
18
application.
19
20
21
=== Attributes ===
22
23
=== Methods  ===
24
25
=== Notifications  ===
26
27
28
== Session ==
29 1 Adrian Georgescu
30 51 Adrian Georgescu
[[Image(sipsimple-session-state-machine.png, align=right, width=400)]]
31
32 44 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
33
34 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.
35
36
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.
37 26 Luci Stanescu
State changes are triggered by methods called on the object by the application or by received network events.
38 1 Adrian Georgescu
Every time this attribute changes, a {{{SIPSessionChangedState}}} notification is sent by the object.
39
These states and their transitions are represented in the following diagram:
40 2 Adrian Georgescu
41 51 Adrian Georgescu
42 1 Adrian Georgescu
43
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 different set of notifications is also emitted, which provide all the necessary information to the application.
44
45 50 Adrian Georgescu
=== Attributes ===
46 1 Adrian Georgescu
47
 '''state'''::
48
  The state the object is currently in, being one of the states from the diagram above.
49 18 Ruud Klaver
 '''account'''::
50
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object that the {{{Session}}} is associated with.
51
  On an outbound session, this is the account the application specified on object instantiation.
52 1 Adrian Georgescu
 '''direction'''::
53
  A string indicating the direction of the initial negotiation of the session.
54
  This can be either {{{None}}}, "incoming" or "outgoing".
55
 '''start_time'''::
56
  The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started.
57
 '''stop_time'''::
58
  The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated.
59
 '''on_hold_by_local'''::
60
  Boolean indicating whether the session was put on hold by the local party.
61
 '''on_hold_by_remote'''::
62
  Boolean indicating whether the session was put on hold by the remote party.
63
 '''on_hold'''::
64
  Boolean indicating whether the session was put on hold, either by the local or the remote party.
65
 '''remote_user_agent'''::
66
  A string indicating the remote user agent, if it provided one.
67
  Initially this will be {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never).
68
 '''local_uri'''::
69
  The {{{sipsimple.core.SIPURI}}} of the local party, if the session is active.
70
 '''remote_uri'''::
71
  The {{{sipsimple.core.SIPURI}}} of the remote party, if the session is active.
72
 '''caller_uri'''::
73
  The {{{sipsimple.core.SIPURI}}} of the calling party, if the session is active.
74
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
75
 '''callee_uri'''::
76
  The {{{sipsimple.core.SIPURI}}} of the called party, if the session is active.
77
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
78
 '''route'''::
79 20 Ruud Klaver
  A copy of the {{{sipsimple.core.Route}}} object passed when the {{{connect()}}} method was called.
80 1 Adrian Georgescu
  On incoming or inactive sessions this is {{{None}}}.
81
 '''audio_transport'''::
82
  The {{{sipsimple.core.AudioTransport}}} object used by the session, if it currently contains an audio stream.
83
  Normally the application will not need to access this directly.
84
 '''has_audio'''::
85 23 Ruud Klaver
  A boolean indicating if this {{{Session}}} currently has an active audio stream.
86 1 Adrian Georgescu
 '''audio_sample_rate'''::
87
  If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
88
 '''audio_codec'''::
89
  If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
90
 '''audio_srtp_active'''::
91
  If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
92
 '''audio_local_rtp_address'''::
93
  If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
94
 '''audio_local_rtp_port'''::
95
  If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
96
 '''audio_remote_rtp_address_sdp'''::
97
  If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
98
 '''audio_remote_rtp_port_sdp'''::
99
  If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
100
 '''audio_remote_rtp_address_received'''::
101
  If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
102
 '''audio_remote_rtp_port_received'''::
103
  If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
104
 '''audio_was_received'''::
105
  This boolean property indicates if audio was actually received on the audio stream contained within this session.
106
 '''audio_recording_file_name'''::
107
  If the audio stream is currently being recorded to disk, this property contains the name of the {{{.wav}}} file being recorded to.
108
 '''chat_transport'''::
109
  The {{{sipsimple.msrp.MSRPChat}}} object used by the session as chat transport, if the session currently contains a chat stream.
110
  Normally the application will not need to access this directly.
111
 '''has_chat'''::
112 23 Ruud Klaver
  A boolean property indicating if this {{{Session}}} currently has an active chat stream.
113 1 Adrian Georgescu
114 50 Adrian Georgescu
=== Methods ===
115 1 Adrian Georgescu
116 18 Ruud Klaver
 '''!__init!__'''(''self'', '''account''')::
117 1 Adrian Georgescu
  Creates a new {{{Session}}} object in the {{{NULL}}} state.
118 19 Ruud Klaver
  [[BR]]''account'':[[BR]]
119
  The local account to be associated with this {{{Session}}}.
120
 '''connect'''(''self'', '''callee_uri''', '''routes''', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
121 1 Adrian Georgescu
  Will set up the {{{Session}}} as outbound and propose the new session to the specified remote party and move the state machine to the {{{CALLING}}} state.
122 26 Luci Stanescu
  Before contacting the remote party, a {{{SIPSessionNewOutgoing}}} notification will be emitted.
123
  If there is a failure or the remote party rejected the offer, a {{{SIPSessionDidFail}}} notification will be sent, followed by a {{{SIPSessionDidEnd}}}.
124
  Any time a ringing indication is received from the remote party, a {{{SIPSessionGotRingIndication}}} notification is sent.
125
  If the remote party accepted the session, a {{{SIPSessionWillStart}}} notification will be sent, followed by a {{{SIPSessionDidStart}}} notification when the session is actually established.
126 1 Adrian Georgescu
  This method may only be called while in the {{{NULL}}} state.
127
  [[BR]]''callee_uri'':[[BR]]
128
  A {{{sipsimple.core.SIPURI}}} object representing the remote host to initiate the session to.
129 19 Ruud Klaver
  [[BR]]''routes'':[[BR]]
130
  An iterable of {{{sipsimple.core.Route}}} objects, specifying the IP, port and transport to the outbound proxy.
131
  These routes will be tried in order, until one of them succeeds.
132 1 Adrian Georgescu
  [[BR]]''audio'':[[BR]]
133
  A boolean indicating whether an audio stream should be initially included in this session.
134
  [[BR]]''chat'':[[BR]]
135
  A boolean indicating whether a chat stream should be initially included in this session.
136 19 Ruud Klaver
 '''accept'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
137 1 Adrian Georgescu
  Calling this methods will accept an incoming session and move the state machine to the {{{ACCEPTING}}} state.
138 26 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.
139
  After this method is called, {{{SIPSessionWillStart}}} followed by {{{SIPSessionDidStart}}} will be emitted, or {{{SIPSessionDidFail}}} followed by {{{SIPSessionDidEnd}}} on an error.
140 1 Adrian Georgescu
  This method may only be called while in the {{{INCOMING}}} state.
141
  [[BR]]''audio'':[[BR]]
142
  A boolean indicating whether an audio stream should be accepted for this session.
143
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
144
  [[BR]]''chat'':[[BR]]
145
  A boolean indicating whether a chat stream should be accepted for this session.
146
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
147 41 Ruud Klaver
 '''reject'''(''self'', '''is_busy'''={{{False}}})::
148 1 Adrian Georgescu
  Reject an incoming session and move it to the {{{TERMINATING}}} state, which eventually leads to the {{{TERMINATED}}} state.
149 26 Luci Stanescu
  Calling this method will cause the {{{Session}}} object to emit a {{{SIPSessionWillEnd}}} notification, followed by a {{{SIPSessionDidEnd}}} notification.
150 1 Adrian Georgescu
  This method may only be called while in the {{{INCOMING}}} state.
151 41 Ruud Klaver
  [[BR]]''chat'':[[BR]]
152
  A boolean indicating whether the response code sent to the remote party should be 486 (Busy) instead of 603 (Decline).
153 1 Adrian Georgescu
 '''hold'''(''self'')::
154
  Put the session on hold.
155 26 Luci Stanescu
  This will cause a {{{SIPGotHoldRequest}}} notification to be sent.
156 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
157
 '''unhold'''(''self'')::
158
  Take the session out of hold.
159 26 Luci Stanescu
  This will cause a {{{SIPGotUnholdRequest}}} notification to be sent.
160 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
161 19 Ruud Klaver
 '''start_recording_audio'''(''self'', '''file_name'''={{{None}}})::
162 1 Adrian Georgescu
  If an audio stream is present within this session, calling this method will record the audio to a {{{.wav}}} file.
163
  Note that when the session is on hold, nothing will be recorded to the file.
164 26 Luci Stanescu
  Right before starting the recording a {{{SIPSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SIPSessionDidStartRecordingAudio}}}.
165 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
166
  [[BR]]''file_name'':[[BR]]
167
  The name of the {{{.wav}}} file to record to.
168
  If this is set to {{{None}}}, a default file name including the session participants and the timestamp will be generated.
169
 '''stop_recording_audio'''(''self'')::
170
  This will stop a previously started recording.
171 26 Luci Stanescu
  Before stopping, a {{{SIPSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SIPSessionDidStopRecordingAudio}}}.
172 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
173
 '''send_dtmf'''(''self'', '''digit''')::
174
  If this session currently has an active audio stream, send a DTMF digit to the remote party over it.
175 23 Ruud Klaver
  This method may only be called while in the {{{ESTABLISHED}}} state and if the session has an active audio stream.
176 1 Adrian Georgescu
  [[BR]]''digit'':[[BR]]
177
  This should a string of length 1, containing a valid DTMF digit value.
178 13 Luci Stanescu
 '''send_message'''(''self'', '''content''', '''content_type'''="text/plain", '''to_uri'''={{{None}}}, '''dt'''={{{None}}})::
179 1 Adrian Georgescu
  If this session currently has an active MSRP chat with the remote party, send a message over with the with the specified parameters.
180 26 Luci Stanescu
  This will result in either a {{{SIPSessionDidDeliverMessage}}} or a {{{SIPSessionDidNotDeliverMessage}}} notification being sent.
181 1 Adrian Georgescu
  These notifications include a unique ID as data attribute which is also returned by this method.
182
  This method may only be called while in the {{{ESTABLISHED}}} state.
183
  [[BR]]''content'':[[BR]]
184
  The body of the MSRP message as a string.
185
  [[BR]]''content_type'':[[BR]]
186
  The Content-Type of the body as a string
187 22 Ruud Klaver
  [[BR]]''to_uri'':[[BR]]
188 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} that should be put in the {{{To:}}} header of the CPIM wrapper of the message.
189
  This defaults to the SIP URI of the remote party of the session if the argument is set to {{{None}}}
190
  [[BR]]''dt'':[[BR]]
191
  A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message.
192
  When set to {{{None}}}, this defaults to now.
193
 '''add_audio'''(''self'')::
194
  Propose the remote party to add an audio stream to this session.
195 26 Luci Stanescu
  Calling this method will cause a {{{SIPSessionGotStreamProposal}}} notification to be emitted.
196
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SIPSessionAcceptedStreamProposal}}} or {{{SIPSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
197 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that does not currently have an audio stream.
198
 '''remove_audio'''(''self'')::
199
  Stop the audio stream currently active within the session and inform the remote party of this.
200
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has an audio stream.
201
 '''add_chat'''(''self'')::
202
  Propose the remote party to add a chat stream to this session.
203 26 Luci Stanescu
  Calling this method will cause a {{{SIPSessionGotStreamProposal}}} notification to be emitted.
204
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SIPSessionAcceptedStreamProposal}}} or {{{SIPSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
205 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that does not currently have a chat stream.
206
 '''remove_chat'''(''self'')::
207
  Stop the chat stream currently active within the session and inform the remote party of this.
208
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has a chat stream.
209 19 Ruud Klaver
 '''accept_proposal'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
210 26 Luci Stanescu
  When the remote party proposes to add a new stream, signaled by the {{{SIPSessionGotStreamProposal}}} notification, the application can use this method to accept the stream(s) being proposed.
211 1 Adrian Georgescu
  After calling this method a {{{SIPSessionAcceptedStreamProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a {{{SIPSessionRejectedStreamProposal}}} notification is sent and a rejection is sent to the remote party.
212 19 Ruud Klaver
  This method may only be called while in the {{{PROPOSED}}} state.
213
  [[BR]]''audio'':[[BR]]
214
  A boolean indicating whether an audio stream should be accepted for this proposal.
215
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
216
  [[BR]]''chat'':[[BR]]
217
  A boolean indicating whether a chat stream should be accepted for this proposal.
218 26 Luci Stanescu
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
219 1 Adrian Georgescu
 '''reject_proposal'''(''self'')::
220
  When the remote party proposes (a) stream(s) that the application does not want to accept, this method can be used to reject the proposal, after which a {{{SIPSessionRejectedStreamProposal}}} notification is sent.
221 41 Ruud Klaver
  This method may only be called while in the {{{PROPOSED}}} state.
222 1 Adrian Georgescu
 '''end'''(''self'' '''is_busy'''={{{False}}})::
223
  This method may be called any time when the {{{Session}}} object is active (i.e. not in the {{{NULL}}}, {{{TERMINATING}}} or {{{TERMINATED}}} states) in order to terminate the session.
224
  Right before termination a {{{SIPSessionWillEnd}}} notification is sent, after termination {{{SIPSessionDidEnd}}} is sent.
225 41 Ruud Klaver
  [[BR]]''chat'':[[BR]]
226
  A boolean indicating whether the response code sent to the remote party should be 486 (Busy) instead of 603 (Decline).
227 1 Adrian Georgescu
228 50 Adrian Georgescu
=== Notifications ===
229 1 Adrian Georgescu
230 26 Luci Stanescu
 '''SIPSessionChangedState'''::
231 1 Adrian Georgescu
  Will be sent whenever the {{{Session}}} object changes its state.
232
  [[BR]]''timestamp'':[[BR]]
233
  A {{{datetime.datetime}}} object indicating when the notification was sent.
234
  [[BR]]''prev_state'':[[BR]]
235
  The previous state state the object was in.
236
  [[BR]]''state'':[[BR]]
237
  The new state the object is in.
238 26 Luci Stanescu
 '''SIPSessionNewIncoming'''::
239 1 Adrian Georgescu
  Will be sent when a new incoming {{{Session}}} is received.
240
  The application should listen for this notification from all objects specifically to get informed of incoming sessions.
241
  [[BR]]''timestamp'':[[BR]]
242
  A {{{datetime.datetime}}} object indicating when the notification was sent.
243 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
244
  A list of strings indicating the streams that were proposed by the remote party.
245 26 Luci Stanescu
 '''SIPSessionNewOutgoing'''::
246 1 Adrian Georgescu
  Will be sent when the applcation requests a new outgoing {{{Session}}}.
247
  [[BR]]''timestamp'':[[BR]]
248
  A {{{datetime.datetime}}} object indicating when the notification was sent.
249 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
250 32 Adrian Georgescu
  A list of strings indicating the streams that were proposed to the remote party.
251 26 Luci Stanescu
 '''SIPSessionGotRingIndication'''::
252 1 Adrian Georgescu
  Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing.
253
  [[BR]]''timestamp'':[[BR]]
254
  A {{{datetime.datetime}}} object indicating when the notification was sent.
255 26 Luci Stanescu
 '''SIPSessionWillStart'''::
256 1 Adrian Georgescu
  Will be sent just before a {{{Session}}} completes negotiation.
257
  In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}.
258
  [[BR]]''timestamp'':[[BR]]
259
  A {{{datetime.datetime}}} object indicating when the notification was sent.
260 26 Luci Stanescu
 '''SIPSessionDidStart'''::
261 1 Adrian Georgescu
  Will be sent when a {{{Session}}} completes negotiation.
262
  In terms of SIP this is sent after the {{{ACK}}} was sent or received.
263
  [[BR]]''timestamp'':[[BR]]
264
  A {{{datetime.datetime}}} object indicating when the notification was sent.
265 26 Luci Stanescu
 '''SIPSessionDidFail'''::
266 1 Adrian Georgescu
  This notification is sent whenever the session fails.
267
  The failure reason is included in the data attributes.
268 26 Luci Stanescu
  This notification is always followed by {{{SIPSessionDidEnd}}}.
269 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
270
  A {{{datetime.datetime}}} object indicating when the notification was sent.
271
  [[BR]]''originator'':[[BR]]
272
  A string indicating the origin of the failure.
273
  This will either be "local" or "remote".
274
  [[BR]]''code'':[[BR]]
275
  The SIP error code of the failure.
276
  If this is 0, the error was an internal exception.
277
  [[BR]]''reason'':[[BR]]
278
  A string explaining the reason of the failure.
279 26 Luci Stanescu
 '''SIPSessionWillEnd'''::
280 1 Adrian Georgescu
  Will be sent just before terminating a {{{Session}}} at the request of the application.
281
  [[BR]]''timestamp'':[[BR]]
282
  A {{{datetime.datetime}}} object indicating when the notification was sent.
283 26 Luci Stanescu
 '''SIPSessionDidEnd'''::
284
  Will be sent always when a {{{Session}}} ends, either because of a failure (in which case it is preceded by {{{SIPSessionDidFail}}}), remote or local session termination.
285 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
286
  A {{{datetime.datetime}}} object indicating when the notification was sent.
287
  [[BR]]''originator'':[[BR]]
288
  A string indicating who originated the termination.
289
  This will either be "local" or "remote".
290 26 Luci Stanescu
 '''SIPSessionGotHoldRequest'''::
291 1 Adrian Georgescu
  Will be sent when the session got put on hold, either by the local or the remote party.
292
  [[BR]]''timestamp'':[[BR]]
293
  A {{{datetime.datetime}}} object indicating when the notification was sent.
294
  [[BR]]''originator'':[[BR]]
295
  A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
296 26 Luci Stanescu
 '''SIPSessionGotUnholdRequest'''::
297 1 Adrian Georgescu
  Will be sent when the session got taken out of hold, either by the local or the remote party.
298
  [[BR]]''timestamp'':[[BR]]
299
  A {{{datetime.datetime}}} object indicating when the notification was sent.
300
  [[BR]]''originator'':[[BR]]
301
  A string indicating who sent the original hold request, and consequently in which direction the session got taken out of hold.
302 26 Luci Stanescu
 '''SIPSessionWillStartRecordingAudio'''::
303 1 Adrian Georgescu
  Will be sent when the application requested that the audio stream active within the session be record to a {{{.wav}}} file, just before recording starts.
304
  [[BR]]''timestamp'':[[BR]]
305
  A {{{datetime.datetime}}} object indicating when the notification was sent.
306
  [[BR]]''file_name'':[[BR]]
307
  The name of the recording {{{.wav}}} file, including full path.
308 26 Luci Stanescu
 '''SIPSessionDidStartRecordingAudio'''::
309 1 Adrian Georgescu
  Will be sent when the application requested that the audio stream active within the session be record to a {{{.wav}}} file, just after recording starts.
310
  [[BR]]''timestamp'':[[BR]]
311
  A {{{datetime.datetime}}} object indicating when the notification was sent.
312
  [[BR]]''file_name'':[[BR]]
313
  The name of the recording {{{.wav}}} file, including full path.
314 26 Luci Stanescu
 '''SIPSessionWillStopRecordingAudio'''::
315 1 Adrian Georgescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
316
  [[BR]]''timestamp'':[[BR]]
317
  A {{{datetime.datetime}}} object indicating when the notification was sent.
318
  [[BR]]''file_name'':[[BR]]
319
  The name of the recording {{{.wav}}} file, including full path.
320 26 Luci Stanescu
 '''SIPSessionDidStopRecordingAudio'''::
321 1 Adrian Georgescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
322
  [[BR]]''timestamp'':[[BR]]
323
  A {{{datetime.datetime}}} object indicating when the notification was sent.
324
  [[BR]]''file_name'':[[BR]]
325
  The name of the recording {{{.wav}}} file, including full path.
326 26 Luci Stanescu
 '''SIPSessionGotNoAudio'''::
327 1 Adrian Georgescu
  This notification will be sent if 5 seconds after the audio stream starts, no audio was received from the remote party.
328
  [[BR]]''timestamp'':[[BR]]
329
  A {{{datetime.datetime}}} object indicating when the notification was sent.
330 26 Luci Stanescu
 '''SIPSessionGotDTMF'''::
331 1 Adrian Georgescu
  Will be send if there is a DMTF digit received from the remote party on the audio stream. 
332
  [[BR]]''timestamp'':[[BR]]
333
  A {{{datetime.datetime}}} object indicating when the notification was sent.
334
  [[BR]]''digit'':[[BR]]
335
  The DTMF digit that was received, in the form of a string of length 1.
336 26 Luci Stanescu
 '''SIPSessionGotMessage'''::
337 1 Adrian Georgescu
  Will be sent whenever a MSRP message is received on the chat stream of the session.
338
  [[BR]]''content'':[[BR]]
339
  The body of the message.
340
  [[BR]]''content_type'':[[BR]]
341
  The Content-Type of the body.
342
  [[BR]]''cpim_headers'':[[BR]]
343
  A dictionary of headers included in the CPIM wrapper.
344
  [[BR]]''message'':[[BR]]
345 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
346 26 Luci Stanescu
 '''SIPSessionDidDeliverMessage'''::
347 1 Adrian Georgescu
  Will be sent when a previously sent MSRP chat message got delivered to the remote party.
348
  [[BR]]''message_id'':[[BR]]
349
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
350
  [[BR]]''code'':[[BR]]
351
  The response code of the confirmation report.
352
  [[BR]]''reason'':[[BR]]
353 5 Redmine Admin
  The reason string of the confirmation report.
354 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
355
  Raw MSRP message, an msrplib.protocol.MSRPData instance
356 26 Luci Stanescu
 '''SIPSessionDidDeliverMessage'''::
357 1 Adrian Georgescu
  Will be sent when a previously sent MSRP chat message did not get delivered to the remote party.
358
  [[BR]]''message_id'':[[BR]]
359
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
360
  [[BR]]''code'':[[BR]]
361
  The response code of the confirmation report.
362
  [[BR]]''reason'':[[BR]]
363 5 Redmine Admin
  The reason string of the confirmation report.
364 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
365
  Raw MSRP message, an msrplib.protocol.MSRPData instance
366 26 Luci Stanescu
 '''SIPSessionGotStreamProposal'''::
367 1 Adrian Georgescu
  Will be sent when either the local or the remote party proposes to add a stream to the session.
368
  [[BR]]''timestamp'':[[BR]]
369
  A {{{datetime.datetime}}} object indicating when the notification was sent.
370
  [[BR]]''proposer'':[[BR]]
371
  The party that did the stream proposal, can be either "local" or "remote".
372 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
373
  A list of strings indicating the streams that were proposed.
374 26 Luci Stanescu
 '''SIPSessionRejectedStreamProposal'''::
375 1 Adrian Georgescu
  Will be sent when either the local or the remote party rejects a proposal to have (a) stream(s) added to the session.
376
  [[BR]]''timestamp'':[[BR]]
377
  A {{{datetime.datetime}}} object indicating when the notification was sent.
378
  [[BR]]''proposer'':[[BR]]
379
  The party that did the stream proposal, can be either "local" or "remote".
380
  [[BR]]''reason'':[[BR]]
381
  The reason for rejecting the stream proposal.
382
 '''SIPSessionRejectedStreamProposal'''::
383 26 Luci Stanescu
  Will be sent when either the local or the remote party accepts a proposal to have (a) stream(s) added to the session.
384 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
385
  A {{{datetime.datetime}}} object indicating when the notification was sent.
386
  [[BR]]''proposer'':[[BR]]
387
  The party that did the stream proposal, can be either "local" or "remote".
388
 '''SIPSessionGotStreamUpdate'''::
389 26 Luci Stanescu
  Will be sent when a media stream is either activated or deactivated.
390 23 Ruud Klaver
  An application should listen to this notification in order to know when a media stream can be used.
391
  [[BR]]''timestamp'':[[BR]]
392
  A {{{datetime.datetime}}} object indicating when the notification was sent.
393
  [[BR]]''streams'':[[BR]]
394
  A list indicating which streams are active on the session from this point onwards.
395
396 30 Adrian Georgescu
As an example for how to use the {{{Session}}} object, the following provides a basic Python program that initiates an outgoing SIP session request:
397 6 Ruud Klaver
398
{{{
399 24 Ruud Klaver
import sys
400 6 Ruud Klaver
from threading import Event
401
from zope.interface import implements
402
from application.notification import IObserver, NotificationCenter
403 1 Adrian Georgescu
404 24 Ruud Klaver
from sipsimple.configuration import ConfigurationManager
405
from sipsimple.account import AccountManager
406
from sipsimple.engine import Engine
407
from sipsimple.session import Session
408
from sipsimple.core import SIPURI, Route
409
410 1 Adrian Georgescu
class SimpleOutboundCall(object):
411
    # indicate that we implement the application.notification.IObserver interface
412
    implements(IObserver)
413
414 24 Ruud Klaver
    def __init__(self, remote_uri, route):
415 1 Adrian Georgescu
        # setup a threading.Event to signal that the Engine has stopped
416
        self.engine_ended_event = Event()
417 24 Ruud Klaver
        # start the configuration manager
418
        ConfigurationManager().start()
419
        # start the account manager
420
        am = AccountManager()
421
        am.start()
422
        # start the Engine with configuration framework parameters
423
        Engine().start_cfg()
424
        # create a new Session using the default account
425
        self.session = Session(am.default_account)
426 6 Ruud Klaver
        # listen for the notification that the Engine stopped
427 26 Luci Stanescu
        NotificationCenter().add_observer(self, "SIPEngineDidEnd", Engine())
428 6 Ruud Klaver
        # listen for the notification that the Session ended
429 26 Luci Stanescu
        NotificationCenter().add_observer(self, "SIPSessionDidEnd", self.session)
430 6 Ruud Klaver
        # start a new outbound session
431 24 Ruud Klaver
        self.session.connect(remote_uri, [route], audio=True)
432 6 Ruud Klaver
433 23 Ruud Klaver
    def end(self):
434 6 Ruud Klaver
        # if the Session is still active, terminate it
435
        self.session.end()
436
        # wait for the engine to stop, processed in handle_notification
437
        self.engine_ended_event.wait()
438
        # quit the progam, as this can only be done from the main thread
439
        sys.exit()
440
441 1 Adrian Georgescu
    def handle_notification(self, notification):
442
        if notification.name == "SIPSessionDidEnd":
443
            # if for whatever reason the session ended, stop the Engine
444
            print "Session ended"
445
            Engine().stop()
446
        elif notification.name == "SIPEngineDidEnd":
447
            # once the Engine has stopped, signal the (possibly) waiting main
448
            # thread through a threading.Event
449
            self.engine_ended_event.set()
450
451
# place an audio call from the specified account to the specified URI, through
452
# the specified SIP proxy
453
# edit this to reflect real settings
454
call = SimpleOutboundCall(SIPURI(user="bob", host="example.com"), Route("1.2.3.4"))
455
# block waiting for user input
456
print "Placing call, press enter to quit program"
457 26 Luci Stanescu
raw_input()
458 6 Ruud Klaver
# block in end() until the Engine has stopped
459 30 Adrian Georgescu
call.end()
460
}}}
461 47 Adrian Georgescu
462 50 Adrian Georgescu
== SessionManager ==
463 31 Adrian Georgescu
464 1 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
465 30 Adrian Georgescu
466
The {{{sipsimple.session.SessionManager}}} class is a singleton, which acts as the central aggregation point for sessions within the middleware.
467
Although it is mainly used internally, the application can use it to query information about all active sessions.
468 1 Adrian Georgescu
The SessionManager is implemented as a singleton, meaning that only one instance of this class exists within the middleware.
469 30 Adrian Georgescu
Note that, in order to be able to receive calls, the application has to instantiate this object.
470
471 50 Adrian Georgescu
=== Attributes ===
472 30 Adrian Georgescu
473 1 Adrian Georgescu
 '''sessions'''::
474 30 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.
475
476 50 Adrian Georgescu
=== Methods ===
477 30 Adrian Georgescu
478
 '''!__init!__'''(''self'')::
479 35 Luci Stanescu
  This either returns a new {{{SessionManager}}} object with default configuration objects, or returns a copy of the already existing instance.
480 1 Adrian Georgescu
481 35 Luci Stanescu
482 50 Adrian Georgescu
== Account ==
483 47 Adrian Georgescu
484
Implemented in [browser:sipsimple/account.py]
485 35 Luci Stanescu
486 40 Luci Stanescu
The {{{sipsimple.account.Account}}} objects represent the SIP accounts which are used by the middleware. 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].
487 35 Luci Stanescu
488
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}}}.
489
490 50 Adrian Georgescu
=== States ===
491 35 Luci Stanescu
492
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:
493
{{{
494
account.enabled = True
495
account.save()
496
}}}
497 37 Luci Stanescu
498
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.
499 39 Luci Stanescu
500
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.
501 35 Luci Stanescu
502
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:
503
504 1 Adrian Georgescu
 '''Account.registration.enabled'''::
505 35 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.
506
 '''Account.presence.enabled'''::
507
  This flag controls the automatic subscription to buddies for the ''presence'' event and the publication of data in this event. (Not implemented yet)
508
 '''Account.dialog_event.enabled'''::
509
  This flag controls the automatic subscription to buddies for the ''dialog-info'' event and the publication of data in this event. (Not implemented yet)
510
 '''Account.message_summary.enabled'''::
511
  This flag controls the automatic subscription to the ''message-summary'' event in order to find out about voicemail messages. (Not implemented yet)
512 1 Adrian Georgescu
513 39 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].
514 36 Luci Stanescu
515 50 Adrian Georgescu
=== Attributes ===
516 36 Luci Stanescu
517
The following attributes can be used on an Account object and need to be considered read-only.
518
519
 '''id'''::
520
  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}}}.
521
  {{{
522
  account.id # 'alice@example.com'
523
  account.id.username # 'alice'
524
  account.id.domain # 'example.com'
525
  }}}
526
 '''contact'''::
527
  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).
528
  {{{
529 1 Adrian Georgescu
  account.contact # 'hnfkybrt@10.0.0.1'
530 36 Luci Stanescu
  account.contact.username # 'hnfkybrt'
531
  account.contact.domain # '10.0.0.1'
532
  account.contact['udp'] # <SIPURI "sip:hnfkybrt@10.0.0.1:53024">
533
  account.contact['tls'] # <SIPURI "sip:hnfkybrt@10.0.0.1:54478;transport=tls">
534
  }}}
535
 '''credentials'''::
536
  This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{id}}} attribute and {{{display_name}}} and {{{password}}} settings of the Account. Whenever one of these settings are changed, this attribute is updated.
537
  {{{
538
  account.credentials # <Credentials for '"Alice" <sip:alice@example.com>'>
539
  }}}
540 37 Luci Stanescu
541 50 Adrian Georgescu
=== Notifications ===
542 37 Luci Stanescu
543
 '''CFGSettingsObjectDidChange'''::
544
  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].
545
 '''SIPAccountDidActivate'''::
546
  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. The notification does not contain any data.
547
 '''SIPAccountDidDeactivate'''::
548
  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}}}. The notification does not contain any data.
549
 '''SIPAccountRegistrationDidSucceed'''::
550
  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:
551
  [[BR]]''code'':[[BR]]
552
   The status code of the response for the REGISTER request.
553
  [[BR]]''reason'':[[BR]]
554
   The reason of the response for the REGISTER request.
555
  [[BR]]''contact_uri'':[[BR]]
556
   The Contact URI which was registered.
557
  [[BR]]''contact_uri_list'':[[BR]]
558
   A list containing all the contact URIs registered for this SIP account.
559
  [[BR]]''expires'':[[BR]]
560
   The amount in seconds in which this registration will expire.
561
  [[BR]]''registration'':[[BR]]
562
   The {{{sipsimple.core.Registration}}} object used to register this account.
563
 '''SIPAccountRegistrationDidFail'''::
564
  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:
565
  [[BR]]''code'':[[BR]]
566
   The status code of the response for the REGISTER request. This is only present if the notification is sent as a result of a response being received.
567
  [[BR]]''reason'':[[BR]]
568
   The reason for the failure of the REGISTER request.
569
  [[BR]]''registration'':[[BR]]
570
   The {{{sipsimple.core.Registration}}} object which failed.
571 1 Adrian Georgescu
  [[BR]]''next_route'':[[BR]]
572 37 Luci Stanescu
   A {{{sipsimple.core.Route}}} object which will be tried next for registering the account, or {{{None}}} if a new DNS lookup needs to be performed.
573
  [[BR]]''delay'':[[BR]]
574
   The amount in seconds as a {{{float}}} after which the next route will be tried for registering the account.
575
 '''SIPAccountRegistrationDidEnd'''::
576 1 Adrian Georgescu
  This notification is sent when a registration is ended (the account is unregistered). The data contained in this notification is:
577 37 Luci Stanescu
  [[BR]]''code'':[[BR]]
578
   The status code of the response for the REGISTER with {{{Expires: 0}}} request. This is only present if a response was received.
579 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
580 37 Luci Stanescu
   The reason returned in the response for the Register with {{{Expires: 0}}} request. This is only present if a response was received
581
  [[BR]]''registration'':[[BR]]
582
   The {{{sipsimple.core.Registration}}} object which ended.
583
584 50 Adrian Georgescu
== BonjourAccount ==
585 37 Luci Stanescu
586 48 Adrian Georgescu
Implemented in [browser:sipsimple/account.py]
587
588 37 Luci Stanescu
The {{{sipsimple.account.BonjourAccount}}} represents the SIP account used for P2P mode; it does not interact with any server. The class is a singleton, as there can only be one such account on a system. Similar to the {{{Account}}}, it is used both as a complex object, which implements the functions for bonjour mode, as well as a container for the related settings.
589
590 50 Adrian Georgescu
=== States ===
591 38 Luci Stanescu
592
The {{{BonjourAccount}}} has an {{{enabled}}} flags 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)
593
594 50 Adrian Georgescu
=== Attributes ===
595 38 Luci Stanescu
596
The following attributes can be used on an BonjourAccount object and need to be considered read-only.
597
598
 '''id'''::
599
  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}}}.
600
  {{{
601
  bonjour_account.id # 'bonjour@local'
602
  bonjour_account.id.username # 'bonjour'
603
  bonjour_account.id.domain # 'local'
604 1 Adrian Georgescu
  }}}
605 38 Luci Stanescu
 '''contact'''::
606
  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).
607
  {{{
608
  account.contact # 'lxzvgack@10.0.0.1'
609
  account.contact.username # 'lxzvgack'
610
  account.contact.domain # '10.0.0.1'
611
  account.contact['udp'] # <SIPURI "sip:lxzvgack@10.0.0.1:53024">
612
  account.contact['tls'] # <SIPURI "sip:lxzvgack@10.0.0.1:54478;transport=tls">
613 1 Adrian Georgescu
  }}}
614 38 Luci Stanescu
 '''credentials'''::
615
  This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{contact}}} attribute and {{{display_name}}} setting of the BonjourAccount; the password is set to the empty string. Whenever the display_name setting is changed, this attribute is updated.
616
  {{{
617 1 Adrian Georgescu
  account.credentials # <Credentials for '"Alice" <sip:lxzvgack@10.0.0.1>'>
618
  }}}
619 39 Luci Stanescu
620 50 Adrian Georgescu
=== Notifications ===
621 39 Luci Stanescu
622
 '''CFGSettingsObjectDidChange'''::
623
  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].
624
 '''SIPAccountDidActivate'''::
625
  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. The notification does not contain any data.
626
 '''SIPAccountDidDeactivate'''::
627
  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}}}. The notification does not contain any data.
628
629
630 50 Adrian Georgescu
== AccountManager ==
631 48 Adrian Georgescu
632 39 Luci Stanescu
Implemented in [browser:sipsimple/account.py]
633
634
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.
635
636 50 Adrian Georgescu
=== Methods ===
637 39 Luci Stanescu
638
 '''!__init!__'''(''self'')::
639
  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.
640
 '''start'''(''self'')::
641
  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.
642
 '''stop'''(''self'')::
643
  Calling this method will deactivate all accounts managed by the {{{AccountManager}}}.
644
 '''has_account'''(''self'', '''id''')::
645
  This method returns {{{True}}} if an account which has the specifed SIP ID (must be a string) exists and {{{False}}} otherwise.
646
 '''get_account'''(''self'', '''id''')::
647
  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.
648
 '''get_accounts'''(''self'')::
649
  Returns a list containing all the managed accounts.
650
 '''iter_accounts'''(''self'')::
651
  Returns an iterator through all the managed accounts.
652
 '''find_account'''(''self'', '''contact_uri''')::
653
  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.
654
655 50 Adrian Georgescu
=== Notifications ===
656 39 Luci Stanescu
657
 '''SIPAccountManagerDidAddAccount'''::
658
  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. The data contains a single attribute, {{{account}}} which is the account object which was added.
659
 '''SIPAccountManagerDidRemoveAccount'''::
660
  This notification is sent when an account is deleted using the {{{delete}}} method. The data contains a single attribute, {{{account}}} which is the account object which was deleted.
661
 '''SIPAccountManagerDidChangeDefaultAccount'''::
662
  This notification is sent when the default account changes. The notification contains two attributes:
663
  [[BR]]''old_account'':[[BR]]
664
   This is the account object which used to be the default account.
665
  [[BR]]''account'':[[BR]]
666
   This is the account object which is the new default account.
667 55 Adrian Georgescu
668
== IMediaStream ==
669
670
Implemented in [browser:sipsimple/streams/__init__.py]
671
672
This module automatically registers media streams to a stream registry
673
allowing for a plug and play mechanism of various types of media negoticated
674
in a SIP session that can be added to this library by using a generic API.
675
676
For actual usage see rtp.py and msrp.py that implement media streams based
677
on their respective RTP and MSRP protocols.
678
679
680
=== Atributes ===
681
682
 '''type''' (class attribute)::
683
 A string identifying the stream type (ex: audio, video, ...)
684
 '''priority'''::
685
 An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority)
686
 '''hold_supported'''::
687
 True if the stream supports hold
688
 '''on_hold_by_local'''::
689
 True if the stream is on hold by the local party
690
 '''on_hold_by_remote'''::
691
 True if the stream is on hold by the remote
692
 '''on_hold'''::
693
 True if either on_hold_by_local or on_hold_by_remote is true
694
695
=== Methods ===
696
697
 '''!__init!__'''(''self'', ''account'')::
698
 Initializes the generic stream instance.
699
 '''new_from_sdp'''(''cls'', ''account'', ''remote_sdp'', ''stream_index'')::
700
 '''get_local_media'''(''self'', ''for_offer'')::
701
 '''initialize'''(''self'', ''session'', ''direction'')::
702
 Initializes the stream 
703
 '''start'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
704
 Completes the stream related connection. [[BR]]
705
 When done, must fire StreamChatDidStart notification. 
706
 '''end'''(''self'')::
707
 Ends the stream.  When done, must fire StreamChatDidEnd notification. 
708
 '''validate_update'''(''self'', ''remote_sdp'', ''stream_index'')::
709
 '''update'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
710
 '''hold'''(''self'')::
711
 Puts the stream on hold if supported by the stream. Typically used by audio and video streams.
712
 '''unhold'''(''self'')::
713
 Takes the stream off hold.
714
715
=== Notifications ===
716
717
These notifications must be generated by all streams in order for the upper layer (SIP session) to perform the right decissions.
718
719
 '''MediaStreamDidInitialize'''::
720
 Sent when the {{{Stream}}} instance is initialized
721
 '''MediaStreamDidStart'''::
722
 Sent when the {{{Stream}}} instance has started.
723
 '''MediaStreamDidFail'''::
724
 Sent when the {{{Stream}}} instance has failed.
725
 '''MediaStreamWillEnd'''::
726
 Sent before the {{{Stream}}} instance will end.
727
 '''MediaStreamDidEnd'''::
728
 Sent when the {{{Stream}}} instance did ended.
729
730
== MediaStreamRegistry ==
731
732
The MediaStream registry is used to register streams that can be automatically dealt with by the SIP session layer.
733
734
There are several pre-built streams based on the '''iMediaStream''' API:
735
736
 * {{{sipsimple.streams.msrp.MSRPStreamBase}}}  - MSRP base stream, all MSRP derived streams inherit this
737
 * {{{sipsimple.streams.msrp.ChatStream}}} - Chat stream based on MSRP 
738
 * {{{sipsimple.streams.msrp.FileSelector}}} - Helper for selecting a file for FileTransferStream
739
 * {{{sipsimple.streams.msrp.FileTransferStream}}} - File Transfer stream based on MSRP 
740
 * {{{sipsimple.streams.msrp.VNCConnectionError}}} - Helper class for DesktopSharingStream
741
 * {{{sipsimple.streams.msrp.DesktopSharingHandlerBase}}}  - Helper class for DesktopSharingStream
742
 * {{{sipsimple.streams.msrp.InternalVNCViewerHandler}}} - Helper class for DesktopSharingStream
743
 * {{{sipsimple.streams.msrp.InternalVNCViewerHandler}}}  - Helper class for DesktopSharingStream
744
 * {{{sipsimple.streams.msrp.ExternalVNCViewerHandler}}}  - Helper class for DesktopSharingStream
745
 * {{{sipsimple.streams.msrp.ExternalVNCServerHandler}}}  - Helper class for DesktopSharingStream
746
 * {{{sipsimple.streams.msrp.DesktopSharingStream}}} -  Desktop Sharing stream based on VNC over MSRP 
747
 * {{{sipsimple.streams.msrp.NotificationProxyLogger}}} - Helper class for handling MSRP library logs
748
749
These classes are used internally by [wiki:SipMiddlewareApi#Session Session], which provides the necessary methods to access their features. The notifications posted by these classes are also handled internally by [wiki:SipMiddlewareApi#Session Session]. The notifications that are relevant to the user are then reposted by the Session instance. Refer to [wiki:SipMiddlewareApi#Session Session documentation] for details on the Session API. 
750
751
== AudioStream ==
752
753
Implemented in [browser:sipsimple/streams/rtp.py]
754
755
=== Atributes ===
756
757
 '''recording_file_name''' (class attribute)::
758
 '''sample_rate''' (class attribute)::
759
 '''local_rtp_address''' (class attribute)::
760
 '''local_rtp_port''' (class attribute)::
761
 '''remote_rtp_address''' (class attribute)::
762
 '''remote_rtp_port''' (class attribute)::
763
 '''srtp_active''' (class attribute)::
764
 '''statistics''' (class attribute)::
765
766
=== Notifications ===
767
768
 '''AudioStreamDidChangeHoldState'''::
769
 '''AudioStreamDidStartRecordingAudio'''::
770
 '''AudioStreamDidStopRecordingAudio'''::
771
 '''AudioStreamGotDTMF'''::
772
 '''AudioStreamWillStartRecordingAudio''::
773
 '''AudioStreamWillStopRecordingAudio'''::
774
 
775
== MSRPStreamBase ==
776
777
Implemented in [browser:sipsimple/streams/msrp.py]
778
779
=== Atributes ===
780
781
 '''media_type'''::
782
 '''accept_types'''::
783
 '''accept_wrapped_types'''::
784
 '''use_msrp_session'''::
785
786
=== Notifications ===
787
788
 '''MSRPLibraryLog'''::
789
 '''MSRPTransportTrace'''::
790
791
== ChatStream ==
792
793
Implemented in [browser:sipsimple/streams/msrp.py]
794
795
{{{sipsimple.streams.msrp.ChatStream}}} implements Instant Messaging (IM) over MSRP for the [wiki:SipMiddlewareApi middleware]. This class performs the following functions:
796
797
 * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types
798
 * unwraps incoming Message/CPIM messages; for each incoming message, {{{ChatStreamGotMessage}}} is posted
799
 * plays notification sounds on received/sent message
800
 * reacts to and composes iscomposing payloads
801
802
=== Methods ===
803
804
 '''!__init!__'''(''self'', ''account'', ''direction'')::
805
 Initializes the ChatStream instance.
806
807
 '''initialize'''(''self'')::
808
 Initializes the MSRP connection; connects to the relay if necessary. When done, fires ChatStreamDidInitialize (with 'sdpmedia' attribute, containing the appropriate 'SDPMedia' instance)
809
810
 '''start'''(''self'', ''remote_media'')::
811
 Completes the MSRP connection establishment; this includes binding the MSRP session. [[BR]]
812
 When done, fires MSRPChatDidStart notification. At this point each incoming message is posted as a {{{ChatStreamGotMessage}}} notification
813
814
 '''end'''(''self'')::
815
 Closes the MSRP connection or cleans up after initialize(), whatever is necessary. [[BR]]
816
 Before doing anything posts {{{ChatStreamWillEnd}}} notification.
817
 When done, posts {{{ChatStreamDidEnd}}} notification. If there was an error, posts {{{ChatStreamDidFail}}} notification. 
818
 {{{ChatStreamDidEnd}}} notification will be posted anyway.
819
820
 '''send_message'''(''self'', ''content'', ''content_type''={{{'text/plain'}}}, ''to_uri''={{{None}}}, ''dt''={{{None}}})::
821
 Sends IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be
822
 queued until ChatStreamDidStart notification.
823
824
 Returns the generated MSRP chunk (MSRPData instance); to get Message-ID use its 'message_id' attribute.
825
826
 ''content'' str:[[BR]]
827
 content of the message
828
829
 ''to_uri'' SIPURI:[[BR]]
830
 "To" header of CPIM wrapper; use to override the default supplied to {{{__init__}}}.
831
 May only differ from the one supplied in __init__ if the remote party supports private messages. If it does not, {{{MSRPChatError}}} will be raised;
832
833
 ''content_type'' str:[[BR]]
834
 Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case);
835
 otherwise, Content-Type of MSRP message.
836
837
 These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses:
838
{{{
839
Failure-Report: partial
840
Success-Report: yes
841
}}}
842
843
 '''send_composing_indication'''(''self'', ''state'', ''refresh'', ''last_active=None'', ''remote_identity=None'')::
844
 Send is composing notification.
845
846
=== Notifications ===
847
848
To communicate with the middleware, MSRPChat class uses the notification system provided by the [http://pypi.python.org/pypi/python-application python-application] package.
849
850
 '''ChatStreamGotMessage'''::
851
 Sent whenever a new incoming message is received,
852
  [[BR]]''content'':[[BR]]
853
  The string that the remote user has typed.
854
  [[BR]]''content_type'':[[BR]]
855
  Content-Type of the user message.
856
  [[BR]]''cpim_headers'':[[BR]]
857
  A dictionary of CPIM headers. (Empty dictionary if no CPIM wrapper was used).
858
  [[BR]]''message'':[[BR]]
859
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the chunk.
860
 '''ChatStreamDidDeliverMessage'''::
861
 Sent when a successful report is received.
862
  [[BR]]''message_id'':[[BR]]
863
  Text identifier of the message.
864
  [[BR]]''code'':[[BR]]
865
  Integer result code.
866
  [[BR]]''reason'':[[BR]]
867
  Text comment.
868
  [[BR]]''message'':[[BR]]
869
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
870
 '''ChatStreamDidNotDeliverMessage'''::
871
 Sent when a failure report of failure transaction response is received.
872
  [[BR]]''message_id'':[[BR]]
873
  Text identifier of the message.
874
  [[BR]]''code'':[[BR]]
875
  Integer result code.
876
  [[BR]]''reason'':[[BR]]
877
  Text comment.
878
  [[BR]]''message'':[[BR]]
879
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
880
 '''ChatStreamDidSendMessage'''::
881
 Sent when an outgoing message has been sent.
882
 '''ChatStreamGotComposingIndication'''::
883
 Sent when a iscomposing payload is received.
884
885
886
== FileTransferStream ==
887
888
Implemented in [browser:sipsimple/streams/msrp.py]
889
890
=== Methods ===
891
=== Notifications ===
892
893
 '''FileTransferStreamDidDeliverChunk'''::
894
 '''FileTransferStreamDidFinish'''::
895
 '''FileTransferStreamDidNotDeliverChunk'''::
896
 '''FileTransferStreamGotChunk'''::
897
898
== DesktopSharingStream ==
899
900
Implemented in [browser:sipsimple/streams/msrp.py]
901
902
=== Methods ===
903
904
=== Notifications ===
905
906
 '''DesktopSharingHandlerDidFail'''::
907
 '''DesktopSharingStreamGotData'''::