Project

General

Profile

SipMiddlewareApi » History » Version 17

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