Project

General

Profile

SipMiddlewareApi » History » Version 18

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