Project

General

Profile

SipMiddlewareApi » History » Version 15

Oliver Bril, 03/23/2009 09:13 AM

1 1 Adrian Georgescu
= Middleware API =
2
3
[[TOC(WikiStart, Sip*, depth=3)]]
4 11 Adrian Georgescu
[[Image(sipsimple-middleware.png, align=right, 400px)]]
5 1 Adrian Georgescu
6 14 Adrian Georgescu
This chapter describes the middleware API that can be used by a developer to easily build a user interface for SIP SIMPLE client library. By using this Python API you can easily create a desktop graphical client or a server application for real-time communications based on SIP standards. 
7
8
The middleware is event driven and uses a [wiki:SipSettingsAPI configuration framework] to access various settings for the SIP accounts.
9 1 Adrian Georgescu
10
== Classes ==
11
12
=== SessionManager ===
13
14
The {{{sipsimple.session.SessionManager}}} class is a singleton which acts as the central aggregation point for sessions within the middleware.
15
The application can use it to query information about the active sessions and set global configuration options relevant to sessions, such as transport options and ringtones.
16
In order to achieve the latter, the {{{SessionManager}}} instance contains three configuration attributes that can be inspected and modified at runtime.
17
When a {{{Session}}} is created, either as by the application on an outbound session or by the middleware as an inbound session, these configuration attributes will be copied from the {{{SessionManager}}}.
18
19
> The SessionManager will be integrated with both the configuration framework and the accountmanager, meaning that the part of this API regarding configuration is is subject to change.
20
21
==== attributes ====
22
23
 '''sessions'''::
24
  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.
25
 '''ringtone_config'''::
26
  A {{{RingtoneConfiguration}}} object, which manages the ringtones that should be played on new inbound and outbound sessions.
27
 '''rtp_config'''::
28
  A {{{RTPConfiguration}}} object, which indicates which options should be used when creating a new RTP transport for use by an audio stream.
29
 '''msrp_config'''::
30
  A {{{MSRPConfiguration}}} object, which provides the options that should be used when creating a new MSRP transport used for chat.
31
32
==== methods ====
33
34
 '''!__init!__'''(''self'')::
35
  This either returns a new {{{SessionManager}}} object with default configuration objects, or returns a copy of the already existing instance.
36
37
=== RingtoneConfiguration ===
38
39
A {{{sipsimple.session.RingtoneConfiguration}}} object is contained in the {{{SessionManager}}} and acts as a registration point for both default ringtones and ringtones per incoming SIP URI.
40
41
==== attributes ====
42
43
 '''default_inbound_ringtone'''::
44
  A string pointing to a {{{.wav}}} file on the filesystem that should be played on an incoming session when the remote SIP URI cannot be matched to any of the registered ones.
45
  If this is set to {{{None}}}, no ringtone is played in this situation.
46
 '''outbound_ringtone'''::
47
  A string pointing to a {{{.wav}}} file on the filesystem that should be played when an outbound session receives a ringing indication from the remote party.
48
  If this is set to {{{None}}}, no ringtone is played in this situation.
49
50
==== methods ====
51
52
 '''!__init!__'''(''self'')::
53
  Creates a new {{{RingtoneConfiguration}}} object with both attributes set to {{{None}}} and no SIP URIs registered.
54
 '''add_ringtone_for_sipuri'''(''self'', '''sipuri''', '''ringtone''')::
55
  Registers a ringtone, in the form of a string pointing to a {{{.wav}}} file, to be played back when a incoming session is received from a remote party with the specified SIP URI, in the form of a {{{sipsimple.core.SIPURI}}} object.
56
  This will possibly override a previously registered ringtone.
57
 '''remove_sipuri'''(''self'', '''sipuri''')::
58
  Removes the ringtone of a previously registered SIP URI.
59
 '''get_ringtone_for_sipuri'''(''self'', '''sipuri''')::
60
  Retrieve the ringtone to use when receiving an inbound session from the specified SIP URI, as a {{{sipsimple.core.SIPURI}}} object.
61
  If no ringtone was registed, this will return {{{default_inbound_ringtone}}}.
62
63
=== RTPConfiguration ===
64
65
A {{{sipsimple.session.RTPConfiguration}}} object contains parameters that should be used when creating a new RTP transport, used by a {{{Session}}} object for an audio stream.
66
67
==== attributes ====
68
69
 '''local_rtp_address'''::
70
  The IP address to use for the RTP endpoint.
71
 '''use_srtp'''::
72
  A boolean indicating whether SRTP should be used.
73
 '''srtp_forced'''::
74
  A boolean indicating whether SRTP should be mandatory, if SRTP is to be used.
75
 '''use_ice'''::
76
  A boolean indicating whether ICE should be used.
77
 '''ice_stun_address'''::
78
  The IP adress of the STUN server that should be contacted to retrieve an ICE candidate.
79
  This attribute is only relevant if ICE is used.
80
  If this is the case and this attribute is set to {{{None}}}, no STUN candidate shall be retrieved for ICE.
81
 '''ice_stun_port''::
82
  The port of the STUN server to be used for retrieving an ICE candidate.
83
  The same condition apply to this attribute as for {{{ice_stun_address}}}.
84
85
==== methods ====
86
87
 '''!__init!__'''(''self'', '''local_rtp_address'''=<default_host_ip>, '''use_srtp'''={{{False}}}, '''srtp_forced'''={{{False}}}, '''use_ice'''={{{False}}}, '''ice_stun_address'''={{{None}}}, '''ice_stun_port'''=3478)::
88
  This creates a new {{{RTPConfiguration}}} object with sensible defaults, setting all the attributes to the specified values.
89
  The default value for the {{{local_rtp_address}}} attribute is the default outbound IP of this host, detected at application start.
90
91
=== MSRPConfiguration ===
92
93
A {{{sipsimple.session.MSRPConfiguration}}} object governs the parameters used for creating an MSRP connection when establishing a chat within a session.
94
95
==== attributes ====
96
97
 '''local_ip'''::
98
  The local IP address to put in the MSRP URI.
99
  If this is set to None, an IP will be automatically detected.
100
 '''local_port'''::
101
  The local port to use for MSRP.
102
  If this is set to None, an a port will be automatically allocated.
103
 '''local_use_tls'''::
104
  A boolean indicating whether to use TLS in the local MSRP URI.
105
 '''use_relay_incoming'''::
106
  A boolean indicating whether to use a MSRP relay for incoming sessions.
107
 '''use_relay_outgoing'''::
108
  A boolean indicating whether to use a MSRP relay for outgoing sessions.
109
 '''relay_host'''::
110
  The IP address of the MSRP relay to use, set by the above conditions.
111
 '''relay_port'''::
112
  The TCP port to use on the MSRP relay.
113
 '''relay_use_tls'''::
114
  A boolean indicating whether the connection to the MSRP relay specified should use TLS.
115
116
==== methods ====
117
118
 '''!__init!__'''(''self'', '''local_ip'''={{{None}}}, '''local_port'''={{{None}}}, '''local_use_tls'''={{{True}}}, '''use_relay_incoming'''={{{True}}}, '''use_relay_outgoing'''={{{False}}}, '''relay_host'''={{{None}}}, '''relay_port'''={{{None}}}, '''relay_use_tls'''={{{None}}})::
119
  This creates a new {{{MSRPConfiguration}}} object with sensible defaults, setting all the attributes to the specified values.
120
121
=== Session ===
122
123
A {{{sipsimple.session.Session}}} object represents a complete SIP session between the local and a remote endpoints, including media streams.
124
The currently supported media streams are audio and MSRP chat.
125
Both incoming and outgoing sessions are represented by this class.
126
127
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.
128
State changes are triggered by methods called on the object by the application or by received network events.
129
Every time this attribute changes, a {{{SCSessionChangedState}}} notification is sent by the object.
130
These states and their transitions are represented in the following diagram:
131
132 2 Adrian Georgescu
[[Image(sipsimple-session-state-machine.png)]]
133 1 Adrian Georgescu
134
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.
135
136
==== attributes ====
137
138
 '''state'''::
139
  The state the object is currently in, being one of the states from the diagram above.
140
 '''direction'''::
141
  A string indicating the direction of the initial negotiation of the session.
142
  This can be either {{{None}}}, "incoming" or "outgoing".
143
 '''start_time'''::
144
  The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started.
145
 '''stop_time'''::
146
  The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated.
147
 '''on_hold_by_local'''::
148
  Boolean indicating whether the session was put on hold by the local party.
149
 '''on_hold_by_remote'''::
150
  Boolean indicating whether the session was put on hold by the remote party.
151
 '''on_hold'''::
152
  Boolean indicating whether the session was put on hold, either by the local or the remote party.
153
 '''remote_user_agent'''::
154
  A string indicating the remote user agent, if it provided one.
155
  Initially this will be {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never).
156
 '''local_uri'''::
157
  The {{{sipsimple.core.SIPURI}}} of the local party, if the session is active.
158
 '''remote_uri'''::
159
  The {{{sipsimple.core.SIPURI}}} of the remote party, if the session is active.
160
 '''caller_uri'''::
161
  The {{{sipsimple.core.SIPURI}}} of the calling party, if the session is active.
162
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
163
 '''callee_uri'''::
164
  The {{{sipsimple.core.SIPURI}}} of the called party, if the session is active.
165
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
166
 '''credentials'''::
167
  A copy of the {{{sipsimple.core.Credentials}}} object passed when the {{{new()}}} method was called.
168
  On incoming or inactive sessions this is {{{None}}}.
169
 '''route'''::
170
  A copy of the {{{sipsimple.core.Route}}} object passed when the {{{new()}}} method was called.
171
  On incoming or inactive sessions this is {{{None}}}.
172
 '''audio_transport'''::
173
  The {{{sipsimple.core.AudioTransport}}} object used by the session, if it currently contains an audio stream.
174
  Normally the application will not need to access this directly.
175
 '''has_audio'''::
176
  A boolean property indicating if this {{{Session}}} currently has an audio stream.
177
 '''audio_sample_rate'''::
178
  If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
179
 '''audio_codec'''::
180
  If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
181
 '''audio_srtp_active'''::
182
  If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
183
 '''audio_local_rtp_address'''::
184
  If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
185
 '''audio_local_rtp_port'''::
186
  If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
187
 '''audio_remote_rtp_address_sdp'''::
188
  If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
189
 '''audio_remote_rtp_port_sdp'''::
190
  If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
191
 '''audio_remote_rtp_address_received'''::
192
  If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
193
 '''audio_remote_rtp_port_received'''::
194
  If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
195
 '''audio_was_received'''::
196
  This boolean property indicates if audio was actually received on the audio stream contained within this session.
197
 '''audio_recording_file_name'''::
198
  If the audio stream is currently being recorded to disk, this property contains the name of the {{{.wav}}} file being recorded to.
199
 '''chat_transport'''::
200
  The {{{sipsimple.msrp.MSRPChat}}} object used by the session as chat transport, if the session currently contains a chat stream.
201
  Normally the application will not need to access this directly.
202
 '''has_chat'''::
203
  A boolean property indicating if this {{{Session}}} currently has a chat stream.
204
205
==== methods ====
206
207
 '''!__init!__'''(''self'')::
208
  Creates a new {{{Session}}} object in the {{{NULL}}} state.
209 15 Oliver Bril
 '''connect'''(''self'', '''callee_uri''', '''credentials''', '''route''', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
210 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.
211
  Before contacting the remote party, a {{{SCSessionNewOutgoing}}} notification will be emitted.
212
  If there is a failure or the remote party rejected the offer, a {{{SCSessionDidFail}}} notification will be sent, followed by a {{{SCSessionDidEnd}}}.
213
  Any time a ringing indication is received from the remote party, a {{{SCSessionGotRingIndication}}} notification is sent.
214
  If the remote party accepted the session, a {{{SCSessionWillStart}}} notification will be sent, followed by a {{{SCSessionDidStart}}} notification when the session is actually established.
215
  This method may only be called while in the {{{NULL}}} state.
216
  [[BR]]''callee_uri'':[[BR]]
217
  A {{{sipsimple.core.SIPURI}}} object representing the remote host to initiate the session to.
218
  [[BR]]''credentials'':[[BR]]
219
  A {{{sipsimple.core.Credentials}}} object, encapsulating the local SIP URI and the password for it, if set.
220
  [[BR]]''route'':[[BR]]
221
  A {{{sipsimple.core.Route}}} object, specifying the IP, port and transport to the outbound proxy.
222
  [[BR]]''audio'':[[BR]]
223
  A boolean indicating whether an audio stream should be initially included in this session.
224
  [[BR]]''chat'':[[BR]]
225
  A boolean indicating whether a chat stream should be initially included in this session.
226
 '''accept'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}}, '''password'''={{{None}}})::
227
  Calling this methods will accept an incoming session and move the state machine to the {{{ACCEPTING}}} state.
228
  When there is a new incoming session, a {{{SCSessionNewIncoming}}} notification is sent, after which the application can call this method on the sender of the notification.
229
  After this method is called, {{{SCSessionWillStart}}} followed by {{{SCSessionDidStart}}} will be emitted, or {{{SCSessionDidFail}}} followed by {{{SCSessionDidEnd}}} on an error.
230
  This method may only be called while in the {{{INCOMING}}} state.
231
  [[BR]]''audio'':[[BR]]
232
  A boolean indicating whether an audio stream should be accepted for this session.
233
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
234
  [[BR]]''chat'':[[BR]]
235
  A boolean indicating whether a chat stream should be accepted for this session.
236
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
237
  [[BR]]''password'':[[BR]]
238
  The password for the local SIP URI to which the session was proposed.
239
  This is only used for reserving a session at the MSRP relay.
240
 '''reject'''(''self'')::
241
  Reject an incoming session and move it to the {{{TERMINATING}}} state, which eventually leads to the {{{TERMINATED}}} state.
242
  Calling this method will cause the {{{Session}}} object to emit a {{{SCSessionWillEnd}}} notification, followed by a {{{SCSessionDidEnd}}} notification.
243
  This method may only be called while in the {{{INCOMING}}} state.
244
 '''hold'''(''self'')::
245
  Put the session on hold.
246
  This will cause a {{{SCGotHoldRequest}}} notification to be sent.
247
  This method may only be called while in the {{{ESTABLISHED}}} state.
248
 '''unhold'''(''self'')::
249
  Take the session out of hold.
250
  This will cause a {{{SCGotUnholdRequest}}} notification to be sent.
251
  This method may only be called while in the {{{ESTABLISHED}}} state.
252
 '''start_recording_audio'''(''self'', '''path''', '''file_name'''={{{None}}})::
253
  If an audio stream is present within this session, calling this method will record the audio to a {{{.wav}}} file.
254
  Note that when the session is on hold, nothing will be recorded to the file.
255
  Right before starting the recording a {{{SCSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SCSessionDidStartRecordingAudio}}}.
256
  This method may only be called while in the {{{ESTABLISHED}}} state.
257
  [[BR]]''path'':[[BR]]
258
  The path to the directory to place the {{{.wav}}} file in.
259
  [[BR]]''file_name'':[[BR]]
260
  The name of the {{{.wav}}} file to record to.
261
  If this is set to {{{None}}}, a default file name including the session participants and the timestamp will be generated.
262
 '''stop_recording_audio'''(''self'')::
263
  This will stop a previously started recording.
264
  Before stopping, a {{{SCSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SCSessionDidStopRecordingAudio}}}.
265
  This method may only be called while in the {{{ESTABLISHED}}} state.
266
 '''send_dtmf'''(''self'', '''digit''')::
267
  If this session currently has an active audio stream, send a DTMF digit to the remote party over it.
268
  This method may only be called while in the {{{ESTABLISHED}}} state.
269
  [[BR]]''digit'':[[BR]]
270
  This should a string of length 1, containing a valid DTMF digit value.
271 13 Luci Stanescu
 '''send_message'''(''self'', '''content''', '''content_type'''="text/plain", '''to_uri'''={{{None}}}, '''dt'''={{{None}}})::
272 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.
273
  This will result in either a {{{SCSessionDidDeliverMessage}}} or a {{{SCSessionDidNotDeliverMessage}}} notification being sent.
274
  These notifications include a unique ID as data attribute which is also returned by this method.
275
  This method may only be called while in the {{{ESTABLISHED}}} state.
276
  [[BR]]''content'':[[BR]]
277
  The body of the MSRP message as a string.
278
  [[BR]]''content_type'':[[BR]]
279
  The Content-Type of the body as a string
280
  [[BR]]''to_uri'':[[BR]]]
281
  The {{{sipsimple.core.SIPURI}}} that should be put in the {{{To:}}} header of the CPIM wrapper of the message.
282
  This defaults to the SIP URI of the remote party of the session if the argument is set to {{{None}}}
283
  [[BR]]''dt'':[[BR]]
284
  A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message.
285
  When set to {{{None}}}, this defaults to now.
286
 '''add_audio'''(''self'')::
287
  Propose the remote party to add an audio stream to this session.
288
  Calling this method will cause a {{{SCSessionGotStreamProposal}}} notification to be emitted.
289
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SCSessionAcceptedStreamProposal}}} or {{{SCSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
290
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that does not currently have an audio stream.
291
 '''remove_audio'''(''self'')::
292
  Stop the audio stream currently active within the session and inform the remote party of this.
293
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has an audio stream.
294
 '''add_chat'''(''self'')::
295
  Propose the remote party to add a chat stream to this session.
296
  Calling this method will cause a {{{SCSessionGotStreamProposal}}} notification to be emitted.
297
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SCSessionAcceptedStreamProposal}}} or {{{SCSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
298
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that does not currently have a chat stream.
299
 '''remove_chat'''(''self'')::
300
  Stop the chat stream currently active within the session and inform the remote party of this.
301
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has a chat stream.
302
 '''accept_proposal'''(''self'')::
303
  When the remote party proposes to add a new stream, signaled by the {{{SCSessionGotStreamProposal}}} notification, the application can use this method to accept the stream(s) being proposed.
304
  After calling this method a {{{SCSessionAcceptedStreamProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a {{{SCSessionRejectedStreamProposal}}} notification is sent and a rejection is sent to the remote party.
305
  This method may only be called while in the {{{PROPOSED}}} state.
306
 '''reject_proposal'''(''self'')::
307
  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 {{{SCSessionRejectedStreamProposal}}} notification is sent.
308
  This method may only be called while in the {{{PROPOSED}}} state.
309
 '''terminate'''(''self'')::
310
  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.
311
  Right before termination a {{{SCSessionWillEnd}}} notification is sent, after termination {{{SCSessionDidEnd}}} is sent.
312
313
==== notifications ====
314
315
 '''SCSessionChangedState'''::
316
  Will be sent whenever the {{{Session}}} object changes its state.
317
  [[BR]]''timestamp'':[[BR]]
318
  A {{{datetime.datetime}}} object indicating when the notification was sent.
319
  [[BR]]''prev_state'':[[BR]]
320
  The previous state state the object was in.
321
  [[BR]]''state'':[[BR]]
322
  The new state the object is in.
323
 '''SCSessionNewIncoming'''::
324
  Will be sent when a new incoming {{{Session}}} is received.
325
  The application should listen for this notification from all objects specifically to get informed of incoming sessions.
326
  [[BR]]''timestamp'':[[BR]]
327
  A {{{datetime.datetime}}} object indicating when the notification was sent.
328
  [[BR]]''has_audio'':[[BR]]
329
  A boolean indicating if the remote party proposed an audio stream within this session.
330
  [[BR]]''has_chat'':[[BR]]
331
  A boolean indicating if the remote party proposed a chat stream within this session.
332
 '''SCSessionNewOutgoing'''::
333
  Will be sent when the applcation requests a new outgoing {{{Session}}}.
334
  [[BR]]''timestamp'':[[BR]]
335
  A {{{datetime.datetime}}} object indicating when the notification was sent.
336
 '''SCSessionGotRingIndication'''::
337
  Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing.
338
  [[BR]]''timestamp'':[[BR]]
339
  A {{{datetime.datetime}}} object indicating when the notification was sent.
340
 '''SCSessionWillStart'''::
341
  Will be sent just before a {{{Session}}} completes negotiation.
342
  In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}.
343
  [[BR]]''timestamp'':[[BR]]
344
  A {{{datetime.datetime}}} object indicating when the notification was sent.
345
 '''SCSessionDidStart'''::
346
  Will be sent when a {{{Session}}} completes negotiation.
347
  In terms of SIP this is sent after the {{{ACK}}} was sent or received.
348
  [[BR]]''timestamp'':[[BR]]
349
  A {{{datetime.datetime}}} object indicating when the notification was sent.
350
 '''SCSessionDidFail'''::
351
  This notification is sent whenever the session fails.
352
  The failure reason is included in the data attributes.
353
  This notification is always followed by {{{SCSessionDidEnd}}}.
354
  [[BR]]''timestamp'':[[BR]]
355
  A {{{datetime.datetime}}} object indicating when the notification was sent.
356
  [[BR]]''originator'':[[BR]]
357
  A string indicating the origin of the failure.
358
  This will either be "local" or "remote".
359
  [[BR]]''code'':[[BR]]
360
  The SIP error code of the failure.
361
  If this is 0, the error was an internal exception.
362
  [[BR]]''reason'':[[BR]]
363
  A string explaining the reason of the failure.
364
 '''SCSessionWillEnd'''::
365
  Will be sent just before terminating a {{{Session}}} at the request of the application.
366
  [[BR]]''timestamp'':[[BR]]
367
  A {{{datetime.datetime}}} object indicating when the notification was sent.
368
 '''SCSessionDidEnd'''::
369
  Will be sent always when a {{{Session}}} ends, either because of a failure (in which case it is preceded by {{{SCSessionDidFail}}}), remote or local session termination.
370
  [[BR]]''timestamp'':[[BR]]
371
  A {{{datetime.datetime}}} object indicating when the notification was sent.
372
  [[BR]]''originator'':[[BR]]
373
  A string indicating who originated the termination.
374
  This will either be "local" or "remote".
375
 '''SCSessionGotHoldRequest'''::
376
  Will be sent when the session got put on hold, either by the local or the remote party.
377
  [[BR]]''timestamp'':[[BR]]
378
  A {{{datetime.datetime}}} object indicating when the notification was sent.
379
  [[BR]]''originator'':[[BR]]
380
  A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
381
 '''SCSessionGotUnholdRequest'''::
382
  Will be sent when the session got taken out of hold, either by the local or the remote party.
383
  [[BR]]''timestamp'':[[BR]]
384
  A {{{datetime.datetime}}} object indicating when the notification was sent.
385
  [[BR]]''originator'':[[BR]]
386
  A string indicating who sent the original hold request, and consequently in which direction the session got taken out of hold.
387
 '''SCSessionWillStartRecordingAudio'''::
388
  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.
389
  [[BR]]''timestamp'':[[BR]]
390
  A {{{datetime.datetime}}} object indicating when the notification was sent.
391
  [[BR]]''file_name'':[[BR]]
392
  The name of the recording {{{.wav}}} file, including full path.
393
 '''SCSessionDidStartRecordingAudio'''::
394
  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.
395
  [[BR]]''timestamp'':[[BR]]
396
  A {{{datetime.datetime}}} object indicating when the notification was sent.
397
  [[BR]]''file_name'':[[BR]]
398
  The name of the recording {{{.wav}}} file, including full path.
399
 '''SCSessionWillStopRecordingAudio'''::
400
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
401
  [[BR]]''timestamp'':[[BR]]
402
  A {{{datetime.datetime}}} object indicating when the notification was sent.
403
  [[BR]]''file_name'':[[BR]]
404
  The name of the recording {{{.wav}}} file, including full path.
405
 '''SCSessionDidStopRecordingAudio'''::
406
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
407
  [[BR]]''timestamp'':[[BR]]
408
  A {{{datetime.datetime}}} object indicating when the notification was sent.
409
  [[BR]]''file_name'':[[BR]]
410
  The name of the recording {{{.wav}}} file, including full path.
411
 '''SCSessionGotNoAudio'''::
412
  This notification will be sent if 5 seconds after the audio stream starts, no audio was received from the remote party.
413
  [[BR]]''timestamp'':[[BR]]
414
  A {{{datetime.datetime}}} object indicating when the notification was sent.
415
 '''SCSessionGotDTMF'''::
416
  Will be send if there is a DMTF digit received from the remote party on the audio stream. 
417
  [[BR]]''timestamp'':[[BR]]
418
  A {{{datetime.datetime}}} object indicating when the notification was sent.
419
  [[BR]]''digit'':[[BR]]
420
  The DTMF digit that was received, in the form of a string of length 1.
421
 '''SCSessionGotMessage'''::
422
  Will be sent whenever a MSRP message is received on the chat stream of the session.
423
  [[BR]]''content'':[[BR]]
424
  The body of the message.
425
  [[BR]]''content_type'':[[BR]]
426
  The Content-Type of the body.
427
  [[BR]]''cpim_headers'':[[BR]]
428
  A dictionary of headers included in the CPIM wrapper.
429
  [[BR]]''message'':[[BR]]
430 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
431 1 Adrian Georgescu
 '''SCSessionDidDeliverMessage'''::
432
  Will be sent when a previously sent MSRP chat message got delivered to the remote party.
433
  [[BR]]''message_id'':[[BR]]
434
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
435
  [[BR]]''code'':[[BR]]
436
  The response code of the confirmation report.
437
  [[BR]]''reason'':[[BR]]
438
  The reason string of the confirmation report.
439
  [[BR]]''message'':[[BR]]
440 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
441 1 Adrian Georgescu
 '''SCSessionDidDeliverMessage'''::
442
  Will be sent when a previously sent MSRP chat message did not get delivered to the remote party.
443
  [[BR]]''message_id'':[[BR]]
444
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
445
  [[BR]]''code'':[[BR]]
446
  The response code of the confirmation report.
447
  [[BR]]''reason'':[[BR]]
448
  The reason string of the confirmation report.
449
  [[BR]]''message'':[[BR]]
450 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
451 1 Adrian Georgescu
 '''SCSessionGotStreamProposal'''::
452
  Will be sent when either the local or the remote party proposes to add a stream to the session.
453
  [[BR]]''timestamp'':[[BR]]
454
  A {{{datetime.datetime}}} object indicating when the notification was sent.
455
  [[BR]]''proposer'':[[BR]]
456
  The party that did the stream proposal, can be either "local" or "remote".
457
  [[BR]]''adds_audio'':[[BR]]
458
  A boolean indicating if the proposal would add an audio stream.
459
  [[BR]]''adds_chat'':[[BR]]
460
  A boolean indicating if the proposal would add a chat stream.
461
 '''SCSessionRejectedStreamProposal'''::
462
  Will be sent when either the local or the remote party rejects a proposal to have (a) stream(s) added to the session.
463
  [[BR]]''timestamp'':[[BR]]
464
  A {{{datetime.datetime}}} object indicating when the notification was sent.
465
  [[BR]]''proposer'':[[BR]]
466
  The party that did the stream proposal, can be either "local" or "remote".
467
  [[BR]]''reason'':[[BR]]
468
  The reason for rejecting the stream proposal.
469
 '''SCSessionRejectedStreamProposal'''::
470
  Will be sent when either the local or the remote party accepts a proposal to have (a) stream(s) added to the session.
471
  [[BR]]''timestamp'':[[BR]]
472
  A {{{datetime.datetime}}} object indicating when the notification was sent.
473
  [[BR]]''proposer'':[[BR]]
474
  The party that did the stream proposal, can be either "local" or "remote".
475
476
==== examples ====
477
478 6 Ruud Klaver
As an example of how to use the {{{Session}}} object, the following provides a very basic Python program that places an outbound call:
479
480
{{{
481
from threading import Event
482
from zope.interface import implements
483
from application.notification import IObserver, NotificationCenter
484
from sipsimple import *
485
486
class SimpleOutboundCall(object):
487
    # indicate that we implement the application.notification.IObserver interface
488
    implements(IObserver)
489
490
    def __init__(self, local_uri, password, remote_uri, route):
491
        # setup a threading.Event to signal that the Engine has stopped
492
        self.engine_ended_event = Event()
493
        # start the Engine with default parameters
494 1 Adrian Georgescu
        Engine().start()
495 7 Ruud Klaver
        # Set up an outbound ringtone on the session manager
496
        SessionManager().ringtone_config.outbound_ringtone = "ringtone.wav"
497 6 Ruud Klaver
        # create a new Session
498
        self.session = Session()
499
        # listen for the notification that the Engine stopped
500
        NotificationCenter().add_observer(self, "SCEngineDidEnd", Engine())
501
        # listen for the notification that the Session ended
502
        NotificationCenter().add_observer(self, "SCSessionDidEnd", self.session)
503
        # setup sipsimple.core.Credentials object
504
        cred = Credentials(local_uri, password)
505
        # start a new outbound session
506
        self.session.new(remote_uri, cred, route, audio=True)
507
508
    def end(self):
509
        # if the Session is still active, terminate it
510
        self.session.terminate()
511
        # wait for the engine to stop, processed in handle_notification
512
        self.engine_ended_event.wait()
513
        # quit the progam, as this can only be done from the main thread
514
        sys.exit()
515
516
    def handle_notification(self, notification):
517
        if notification.name == "SCSessionDidEnd":
518
            # if for whatever reason the session ended, stop the Engine
519
            print "Session ended"
520
            Engine().stop()
521
        elif notification.name == "SCEngineDidEnd":
522
            # once the Engine has stopped, signal the (possibly) waiting main
523
            # thread through a threading.Event
524
            self.engine_ended_event.set()
525
526
527
# place an audio call from the specified account to the specified URI, through
528
# the specified SIP proxy
529
# edit this to reflect real settings
530
call = SimpleOutboundCall(SIPURI(user="alice", host="example.com"), "p4ssw0rd", SIPURI(user="bob", host="example.com"), Route("1.2.3.4"))
531
# block waiting for user input
532
print "Placing call, press enter to quit program"
533
raw_input()
534
# block in end() until the Engine has stopped
535
call.end()
536
}}}
537
538
539 1 Adrian Georgescu
=== MSRPChat ===
540
541
==== Methods ====
542
==== Attributes ====
543
544
=== MSRPFileTransfer ===
545
546
==== Methods ====
547
==== Attributes ====
548
== Notifications ==
549
550
The notifications bus is implemented using [http://pypi.python.org/pypi/python-application/ python-application] notifications system.
551
552
Each software component that needs to communicate with the rest of the system can subscribe to or publish messages. The format of a message on the notification bus is ABClassNameVerbNoun. Attached to each message data can be appended, the data need to be understood by an interested observer. The messages exchanged on the notifications bus and their context are described below. 
553
554
=== SIP Registration ===
555
556
 * SCRegistrationDidSucceed
557
 * SCRegistrationDidFail
558
 * SCRegistrationWillEnd
559
 * SCRegistrationDidEnd
560
561
=== SIP Subscription ===
562
563
 * SCSubscriptionDidSucceed
564
 * SCSubscriptionDidFail
565
 * SCSubscriptionWillEnd
566
 * SCSubscriptionDidEnd
567
 * SCSubscriptionGotNotify
568
569
=== SIP Publication ===
570
571
 * SCPublicationDidSucceed
572
 * SCPublicationDidFail
573
 * SCPublicationWillEnd
574
 * SCPublicationDidEnd
575
576
=== MSRP IM Chat  ===  
577
578
 * MSRPChatDidInitialize
579
 * MSRPChatDidStart
580
 * MSRPChatDidFail
581
 * MSRPChatWillEnd
582
 * MSRPChatDidEnd
583
 * MSRPChatGotMessage      
584
 * MSRPChatDidDeliverMessage
585
 * MSRPChatDidNotDeliverMessage
586
587
=== MSRP File Transfer ===  
588
589
 * MSRPFileTransferDidInitialize       
590
 * MSRPFileTransferDidStart            
591
 * MSRPFileTransferDidFail       
592
 * MSRPFileTransferGotFile       
593
 * MSRPFileTransferDidDeliverFile     
594
 * MSRPFileTransferDidNotDeliverFile   
595
 * MSRPFileTransferWillEnd       
596
 * MSRPFileTransferDidEnd