Project

General

Profile

SipMiddlewareApi » History » Version 19

Ruud Klaver, 03/24/2009 06:33 PM

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 16 Adrian Georgescu
The middleware is event driven and uses a [wiki:SipSettingsAPI configuration API] to access 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 17 Ruud Klaver
Although it is mainly used internally, the application can use it to query information about all active sessions.
16
The SessionManager is implemented as a singleton, meaning that only one instance of this class exists within the middleware.
17 19 Ruud Klaver
Note that, in order to be able to receive calls, the application has to instantiate this object.
18 1 Adrian Georgescu
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
24
==== methods ====
25
26
 '''!__init!__'''(''self'')::
27
  This either returns a new {{{SessionManager}}} object with default configuration objects, or returns a copy of the already existing instance.
28
29
=== Session ===
30
31
A {{{sipsimple.session.Session}}} object represents a complete SIP session between the local and a remote endpoints, including media streams.
32
The currently supported media streams are audio and MSRP chat.
33
Both incoming and outgoing sessions are represented by this class.
34
35
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.
36
State changes are triggered by methods called on the object by the application or by received network events.
37
Every time this attribute changes, a {{{SCSessionChangedState}}} notification is sent by the object.
38
These states and their transitions are represented in the following diagram:
39
40 2 Adrian Georgescu
[[Image(sipsimple-session-state-machine.png)]]
41 1 Adrian Georgescu
42
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.
43
44
==== attributes ====
45
46
 '''state'''::
47
  The state the object is currently in, being one of the states from the diagram above.
48 18 Ruud Klaver
 '''account'''::
49
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object that the {{{Session}}} is associated with.
50
  On an outbound session, this is the account the application specified on object instantiation.
51 1 Adrian Georgescu
 '''direction'''::
52
  A string indicating the direction of the initial negotiation of the session.
53
  This can be either {{{None}}}, "incoming" or "outgoing".
54
 '''start_time'''::
55
  The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started.
56
 '''stop_time'''::
57
  The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated.
58
 '''on_hold_by_local'''::
59
  Boolean indicating whether the session was put on hold by the local party.
60
 '''on_hold_by_remote'''::
61
  Boolean indicating whether the session was put on hold by the remote party.
62
 '''on_hold'''::
63
  Boolean indicating whether the session was put on hold, either by the local or the remote party.
64
 '''remote_user_agent'''::
65
  A string indicating the remote user agent, if it provided one.
66
  Initially this will be {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never).
67
 '''local_uri'''::
68
  The {{{sipsimple.core.SIPURI}}} of the local party, if the session is active.
69
 '''remote_uri'''::
70
  The {{{sipsimple.core.SIPURI}}} of the remote party, if the session is active.
71
 '''caller_uri'''::
72
  The {{{sipsimple.core.SIPURI}}} of the calling party, if the session is active.
73
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
74
 '''callee_uri'''::
75
  The {{{sipsimple.core.SIPURI}}} of the called party, if the session is active.
76
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
77
 '''credentials'''::
78
  A copy of the {{{sipsimple.core.Credentials}}} object passed when the {{{new()}}} method was called.
79
  On incoming or inactive sessions this is {{{None}}}.
80
 '''route'''::
81
  A copy of the {{{sipsimple.core.Route}}} object passed when the {{{new()}}} method was called.
82
  On incoming or inactive sessions this is {{{None}}}.
83
 '''audio_transport'''::
84
  The {{{sipsimple.core.AudioTransport}}} object used by the session, if it currently contains an audio stream.
85
  Normally the application will not need to access this directly.
86
 '''has_audio'''::
87
  A boolean property indicating if this {{{Session}}} currently has an audio stream.
88
 '''audio_sample_rate'''::
89
  If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
90
 '''audio_codec'''::
91
  If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
92
 '''audio_srtp_active'''::
93
  If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
94
 '''audio_local_rtp_address'''::
95
  If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
96
 '''audio_local_rtp_port'''::
97
  If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
98
 '''audio_remote_rtp_address_sdp'''::
99
  If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
100
 '''audio_remote_rtp_port_sdp'''::
101
  If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
102
 '''audio_remote_rtp_address_received'''::
103
  If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
104
 '''audio_remote_rtp_port_received'''::
105
  If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
106
 '''audio_was_received'''::
107
  This boolean property indicates if audio was actually received on the audio stream contained within this session.
108
 '''audio_recording_file_name'''::
109
  If the audio stream is currently being recorded to disk, this property contains the name of the {{{.wav}}} file being recorded to.
110
 '''chat_transport'''::
111
  The {{{sipsimple.msrp.MSRPChat}}} object used by the session as chat transport, if the session currently contains a chat stream.
112
  Normally the application will not need to access this directly.
113
 '''has_chat'''::
114
  A boolean property indicating if this {{{Session}}} currently has a chat stream.
115
116
==== methods ====
117
118 18 Ruud Klaver
 '''!__init!__'''(''self'', '''account''')::
119 1 Adrian Georgescu
  Creates a new {{{Session}}} object in the {{{NULL}}} state.
120 19 Ruud Klaver
  [[BR]]''account'':[[BR]]
121
  The local account to be associated with this {{{Session}}}.
122
 '''connect'''(''self'', '''callee_uri''', '''routes''', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
123 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.
124
  Before contacting the remote party, a {{{SCSessionNewOutgoing}}} notification will be emitted.
125
  If there is a failure or the remote party rejected the offer, a {{{SCSessionDidFail}}} notification will be sent, followed by a {{{SCSessionDidEnd}}}.
126
  Any time a ringing indication is received from the remote party, a {{{SCSessionGotRingIndication}}} notification is sent.
127
  If the remote party accepted the session, a {{{SCSessionWillStart}}} notification will be sent, followed by a {{{SCSessionDidStart}}} notification when the session is actually established.
128
  This method may only be called while in the {{{NULL}}} state.
129
  [[BR]]''callee_uri'':[[BR]]
130
  A {{{sipsimple.core.SIPURI}}} object representing the remote host to initiate the session to.
131 19 Ruud Klaver
  [[BR]]''routes'':[[BR]]
132
  An iterable of {{{sipsimple.core.Route}}} objects, specifying the IP, port and transport to the outbound proxy.
133
  These routes will be tried in order, until one of them succeeds.
134 1 Adrian Georgescu
  [[BR]]''audio'':[[BR]]
135
  A boolean indicating whether an audio stream should be initially included in this session.
136
  [[BR]]''chat'':[[BR]]
137
  A boolean indicating whether a chat stream should be initially included in this session.
138 19 Ruud Klaver
 '''accept'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
139 1 Adrian Georgescu
  Calling this methods will accept an incoming session and move the state machine to the {{{ACCEPTING}}} state.
140
  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.
141
  After this method is called, {{{SCSessionWillStart}}} followed by {{{SCSessionDidStart}}} will be emitted, or {{{SCSessionDidFail}}} followed by {{{SCSessionDidEnd}}} on an error.
142
  This method may only be called while in the {{{INCOMING}}} state.
143
  [[BR]]''audio'':[[BR]]
144
  A boolean indicating whether an audio stream should be accepted for this session.
145
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
146
  [[BR]]''chat'':[[BR]]
147
  A boolean indicating whether a chat stream should be accepted for this session.
148
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
149
 '''reject'''(''self'')::
150
  Reject an incoming session and move it to the {{{TERMINATING}}} state, which eventually leads to the {{{TERMINATED}}} state.
151
  Calling this method will cause the {{{Session}}} object to emit a {{{SCSessionWillEnd}}} notification, followed by a {{{SCSessionDidEnd}}} notification.
152
  This method may only be called while in the {{{INCOMING}}} state.
153
 '''hold'''(''self'')::
154
  Put the session on hold.
155
  This will cause a {{{SCGotHoldRequest}}} notification to be sent.
156
  This method may only be called while in the {{{ESTABLISHED}}} state.
157
 '''unhold'''(''self'')::
158
  Take the session out of hold.
159
  This will cause a {{{SCGotUnholdRequest}}} notification to be sent.
160
  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
  Right before starting the recording a {{{SCSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SCSessionDidStartRecordingAudio}}}.
165
  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
  Before stopping, a {{{SCSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SCSessionDidStopRecordingAudio}}}.
172
  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
  This method may only be called while in the {{{ESTABLISHED}}} state.
176
  [[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
  This will result in either a {{{SCSessionDidDeliverMessage}}} or a {{{SCSessionDidNotDeliverMessage}}} notification being sent.
181
  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
  [[BR]]''to_uri'':[[BR]]]
188
  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
  Calling this method will cause a {{{SCSessionGotStreamProposal}}} notification to be emitted.
196
  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.
197
  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
  Calling this method will cause a {{{SCSessionGotStreamProposal}}} notification to be emitted.
204
  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.
205
  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 1 Adrian Georgescu
  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.
211
  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.
212
  This method may only be called while in the {{{PROPOSED}}} state.
213 19 Ruud Klaver
  [[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
  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 {{{SCSessionRejectedStreamProposal}}} notification is sent.
221
  This method may only be called while in the {{{PROPOSED}}} state.
222
 '''terminate'''(''self'')::
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 {{{SCSessionWillEnd}}} notification is sent, after termination {{{SCSessionDidEnd}}} is sent.
225
226
==== notifications ====
227
228
 '''SCSessionChangedState'''::
229
  Will be sent whenever the {{{Session}}} object changes its state.
230
  [[BR]]''timestamp'':[[BR]]
231
  A {{{datetime.datetime}}} object indicating when the notification was sent.
232
  [[BR]]''prev_state'':[[BR]]
233
  The previous state state the object was in.
234
  [[BR]]''state'':[[BR]]
235
  The new state the object is in.
236
 '''SCSessionNewIncoming'''::
237
  Will be sent when a new incoming {{{Session}}} is received.
238
  The application should listen for this notification from all objects specifically to get informed of incoming sessions.
239
  [[BR]]''timestamp'':[[BR]]
240
  A {{{datetime.datetime}}} object indicating when the notification was sent.
241 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
242
  A list of strings indicating the streams that were proposed by the remote party.
243 1 Adrian Georgescu
 '''SCSessionNewOutgoing'''::
244
  Will be sent when the applcation requests a new outgoing {{{Session}}}.
245
  [[BR]]''timestamp'':[[BR]]
246
  A {{{datetime.datetime}}} object indicating when the notification was sent.
247 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
248
  A list of strings indicating the streams that were proposed by the remote party.
249 1 Adrian Georgescu
 '''SCSessionGotRingIndication'''::
250
  Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing.
251
  [[BR]]''timestamp'':[[BR]]
252
  A {{{datetime.datetime}}} object indicating when the notification was sent.
253
 '''SCSessionWillStart'''::
254
  Will be sent just before a {{{Session}}} completes negotiation.
255
  In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}.
256
  [[BR]]''timestamp'':[[BR]]
257
  A {{{datetime.datetime}}} object indicating when the notification was sent.
258
 '''SCSessionDidStart'''::
259
  Will be sent when a {{{Session}}} completes negotiation.
260
  In terms of SIP this is sent after the {{{ACK}}} was sent or received.
261
  [[BR]]''timestamp'':[[BR]]
262
  A {{{datetime.datetime}}} object indicating when the notification was sent.
263
 '''SCSessionDidFail'''::
264
  This notification is sent whenever the session fails.
265
  The failure reason is included in the data attributes.
266
  This notification is always followed by {{{SCSessionDidEnd}}}.
267
  [[BR]]''timestamp'':[[BR]]
268
  A {{{datetime.datetime}}} object indicating when the notification was sent.
269
  [[BR]]''originator'':[[BR]]
270
  A string indicating the origin of the failure.
271
  This will either be "local" or "remote".
272
  [[BR]]''code'':[[BR]]
273
  The SIP error code of the failure.
274
  If this is 0, the error was an internal exception.
275
  [[BR]]''reason'':[[BR]]
276
  A string explaining the reason of the failure.
277
 '''SCSessionWillEnd'''::
278
  Will be sent just before terminating a {{{Session}}} at the request of the application.
279
  [[BR]]''timestamp'':[[BR]]
280
  A {{{datetime.datetime}}} object indicating when the notification was sent.
281
 '''SCSessionDidEnd'''::
282
  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.
283
  [[BR]]''timestamp'':[[BR]]
284
  A {{{datetime.datetime}}} object indicating when the notification was sent.
285
  [[BR]]''originator'':[[BR]]
286
  A string indicating who originated the termination.
287
  This will either be "local" or "remote".
288
 '''SCSessionGotHoldRequest'''::
289
  Will be sent when the session got put on hold, either by the local or the remote party.
290
  [[BR]]''timestamp'':[[BR]]
291
  A {{{datetime.datetime}}} object indicating when the notification was sent.
292
  [[BR]]''originator'':[[BR]]
293
  A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
294
 '''SCSessionGotUnholdRequest'''::
295
  Will be sent when the session got taken out of hold, either by the local or the remote party.
296
  [[BR]]''timestamp'':[[BR]]
297
  A {{{datetime.datetime}}} object indicating when the notification was sent.
298
  [[BR]]''originator'':[[BR]]
299
  A string indicating who sent the original hold request, and consequently in which direction the session got taken out of hold.
300
 '''SCSessionWillStartRecordingAudio'''::
301
  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.
302
  [[BR]]''timestamp'':[[BR]]
303
  A {{{datetime.datetime}}} object indicating when the notification was sent.
304
  [[BR]]''file_name'':[[BR]]
305
  The name of the recording {{{.wav}}} file, including full path.
306
 '''SCSessionDidStartRecordingAudio'''::
307
  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.
308
  [[BR]]''timestamp'':[[BR]]
309
  A {{{datetime.datetime}}} object indicating when the notification was sent.
310
  [[BR]]''file_name'':[[BR]]
311
  The name of the recording {{{.wav}}} file, including full path.
312
 '''SCSessionWillStopRecordingAudio'''::
313
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
314
  [[BR]]''timestamp'':[[BR]]
315
  A {{{datetime.datetime}}} object indicating when the notification was sent.
316
  [[BR]]''file_name'':[[BR]]
317
  The name of the recording {{{.wav}}} file, including full path.
318
 '''SCSessionDidStopRecordingAudio'''::
319
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
320
  [[BR]]''timestamp'':[[BR]]
321
  A {{{datetime.datetime}}} object indicating when the notification was sent.
322
  [[BR]]''file_name'':[[BR]]
323
  The name of the recording {{{.wav}}} file, including full path.
324
 '''SCSessionGotNoAudio'''::
325
  This notification will be sent if 5 seconds after the audio stream starts, no audio was received from the remote party.
326
  [[BR]]''timestamp'':[[BR]]
327
  A {{{datetime.datetime}}} object indicating when the notification was sent.
328
 '''SCSessionGotDTMF'''::
329
  Will be send if there is a DMTF digit received from the remote party on the audio stream. 
330
  [[BR]]''timestamp'':[[BR]]
331
  A {{{datetime.datetime}}} object indicating when the notification was sent.
332
  [[BR]]''digit'':[[BR]]
333
  The DTMF digit that was received, in the form of a string of length 1.
334
 '''SCSessionGotMessage'''::
335
  Will be sent whenever a MSRP message is received on the chat stream of the session.
336
  [[BR]]''content'':[[BR]]
337
  The body of the message.
338
  [[BR]]''content_type'':[[BR]]
339
  The Content-Type of the body.
340
  [[BR]]''cpim_headers'':[[BR]]
341
  A dictionary of headers included in the CPIM wrapper.
342
  [[BR]]''message'':[[BR]]
343 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
344 1 Adrian Georgescu
 '''SCSessionDidDeliverMessage'''::
345
  Will be sent when a previously sent MSRP chat message got delivered to the remote party.
346
  [[BR]]''message_id'':[[BR]]
347
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
348
  [[BR]]''code'':[[BR]]
349
  The response code of the confirmation report.
350
  [[BR]]''reason'':[[BR]]
351 5 Redmine Admin
  The reason string of the confirmation report.
352 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
353
  Raw MSRP message, an msrplib.protocol.MSRPData instance
354
 '''SCSessionDidDeliverMessage'''::
355
  Will be sent when a previously sent MSRP chat message did not get delivered to the remote party.
356
  [[BR]]''message_id'':[[BR]]
357
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
358
  [[BR]]''code'':[[BR]]
359
  The response code of the confirmation report.
360
  [[BR]]''reason'':[[BR]]
361 5 Redmine Admin
  The reason string of the confirmation report.
362 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
363
  Raw MSRP message, an msrplib.protocol.MSRPData instance
364
 '''SCSessionGotStreamProposal'''::
365
  Will be sent when either the local or the remote party proposes to add a stream to the session.
366
  [[BR]]''timestamp'':[[BR]]
367
  A {{{datetime.datetime}}} object indicating when the notification was sent.
368
  [[BR]]''proposer'':[[BR]]
369
  The party that did the stream proposal, can be either "local" or "remote".
370 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
371
  A list of strings indicating the streams that were proposed.
372 1 Adrian Georgescu
 '''SCSessionRejectedStreamProposal'''::
373
  Will be sent when either the local or the remote party rejects a proposal to have (a) stream(s) added to the session.
374
  [[BR]]''timestamp'':[[BR]]
375
  A {{{datetime.datetime}}} object indicating when the notification was sent.
376
  [[BR]]''proposer'':[[BR]]
377
  The party that did the stream proposal, can be either "local" or "remote".
378
  [[BR]]''reason'':[[BR]]
379
  The reason for rejecting the stream proposal.
380
 '''SCSessionRejectedStreamProposal'''::
381
  Will be sent when either the local or the remote party accepts a proposal to have (a) stream(s) added to the session.
382
  [[BR]]''timestamp'':[[BR]]
383
  A {{{datetime.datetime}}} object indicating when the notification was sent.
384
  [[BR]]''proposer'':[[BR]]
385
  The party that did the stream proposal, can be either "local" or "remote".
386
387
==== examples ====
388
389 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:
390
391
{{{
392
from threading import Event
393
from zope.interface import implements
394
from application.notification import IObserver, NotificationCenter
395
from sipsimple import *
396
397
class SimpleOutboundCall(object):
398
    # indicate that we implement the application.notification.IObserver interface
399
    implements(IObserver)
400
401
    def __init__(self, local_uri, password, remote_uri, route):
402
        # setup a threading.Event to signal that the Engine has stopped
403
        self.engine_ended_event = Event()
404
        # start the Engine with default parameters
405 1 Adrian Georgescu
        Engine().start()
406 7 Ruud Klaver
        # Set up an outbound ringtone on the session manager
407
        SessionManager().ringtone_config.outbound_ringtone = "ringtone.wav"
408 6 Ruud Klaver
        # create a new Session
409
        self.session = Session()
410
        # listen for the notification that the Engine stopped
411
        NotificationCenter().add_observer(self, "SCEngineDidEnd", Engine())
412
        # listen for the notification that the Session ended
413
        NotificationCenter().add_observer(self, "SCSessionDidEnd", self.session)
414
        # setup sipsimple.core.Credentials object
415
        cred = Credentials(local_uri, password)
416
        # start a new outbound session
417
        self.session.new(remote_uri, cred, route, audio=True)
418
419
    def end(self):
420
        # if the Session is still active, terminate it
421
        self.session.terminate()
422
        # wait for the engine to stop, processed in handle_notification
423
        self.engine_ended_event.wait()
424
        # quit the progam, as this can only be done from the main thread
425
        sys.exit()
426
427
    def handle_notification(self, notification):
428
        if notification.name == "SCSessionDidEnd":
429
            # if for whatever reason the session ended, stop the Engine
430
            print "Session ended"
431
            Engine().stop()
432
        elif notification.name == "SCEngineDidEnd":
433
            # once the Engine has stopped, signal the (possibly) waiting main
434
            # thread through a threading.Event
435
            self.engine_ended_event.set()
436
437
438
# place an audio call from the specified account to the specified URI, through
439
# the specified SIP proxy
440
# edit this to reflect real settings
441
call = SimpleOutboundCall(SIPURI(user="alice", host="example.com"), "p4ssw0rd", SIPURI(user="bob", host="example.com"), Route("1.2.3.4"))
442
# block waiting for user input
443
print "Placing call, press enter to quit program"
444
raw_input()
445
# block in end() until the Engine has stopped
446
call.end()
447
}}}
448
449
450 1 Adrian Georgescu
=== MSRPChat ===
451
452
==== Methods ====
453
==== Attributes ====
454
455
=== MSRPFileTransfer ===
456
457
==== Methods ====
458
==== Attributes ====
459
== Notifications ==
460
461
The notifications bus is implemented using [http://pypi.python.org/pypi/python-application/ python-application] notifications system.
462
463
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. 
464
465
=== SIP Registration ===
466
467
 * SCRegistrationDidSucceed
468
 * SCRegistrationDidFail
469
 * SCRegistrationWillEnd
470
 * SCRegistrationDidEnd
471
472
=== SIP Subscription ===
473
474
 * SCSubscriptionDidSucceed
475
 * SCSubscriptionDidFail
476
 * SCSubscriptionWillEnd
477
 * SCSubscriptionDidEnd
478
 * SCSubscriptionGotNotify
479
480
=== SIP Publication ===
481
482
 * SCPublicationDidSucceed
483
 * SCPublicationDidFail
484
 * SCPublicationWillEnd
485
 * SCPublicationDidEnd
486
487
=== MSRP IM Chat  ===  
488
489
 * MSRPChatDidInitialize
490
 * MSRPChatDidStart
491
 * MSRPChatDidFail
492
 * MSRPChatWillEnd
493
 * MSRPChatDidEnd
494
 * MSRPChatGotMessage      
495
 * MSRPChatDidDeliverMessage
496
 * MSRPChatDidNotDeliverMessage
497
498
=== MSRP File Transfer ===  
499
500
 * MSRPFileTransferDidInitialize       
501
 * MSRPFileTransferDidStart            
502
 * MSRPFileTransferDidFail       
503
 * MSRPFileTransferGotFile       
504
 * MSRPFileTransferDidDeliverFile     
505
 * MSRPFileTransferDidNotDeliverFile   
506
 * MSRPFileTransferWillEnd       
507
 * MSRPFileTransferDidEnd