SipMiddlewareApi

Version 23 (Ruud Klaver, 03/25/2009 07:55 pm)

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