Project

General

Profile

SipMiddlewareApi » History » Version 12

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