SipMiddlewareApi

Version 58 (Adrian Georgescu, 12/03/2009 11:27 pm)

1 1 Adrian Georgescu
= Middleware API =
2 1 Adrian Georgescu
3 1 Adrian Georgescu
[[TOC(WikiStart, Sip*, depth=3)]]
4 1 Adrian Georgescu
5 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.  
6 14 Adrian Georgescu
7 54 Adrian Georgescu
 * For sub-systems communications the Middleware uses the [http://pypi.python.org/pypi/python-application/ Notification Bus] provided by [http://pypi.python.org/pypi/python-application/ python-application]
8 49 Adrian Georgescu
 * For configuration the Middleware uses the [wiki:SipConfigurationAPI Configuration API] to access General and SIP account  settings
9 1 Adrian Georgescu
10 53 Adrian Georgescu
[[Image(sipsimple-middleware.png, align=center, width=800)]]
11 1 Adrian Georgescu
12 50 Adrian Georgescu
== SIPApplication ==
13 1 Adrian Georgescu
14 50 Adrian Georgescu
Implemented in [browser:sipsimple/api.py]
15 1 Adrian Georgescu
16 50 Adrian Georgescu
Implements a high-level application responsable for starting and stopping
17 50 Adrian Georgescu
various sub-systems required to implement a fully featured SIP User Agent
18 50 Adrian Georgescu
application.
19 50 Adrian Georgescu
20 50 Adrian Georgescu
21 50 Adrian Georgescu
=== Attributes ===
22 50 Adrian Georgescu
23 50 Adrian Georgescu
=== Methods  ===
24 50 Adrian Georgescu
25 50 Adrian Georgescu
=== Notifications  ===
26 50 Adrian Georgescu
27 50 Adrian Georgescu
28 50 Adrian Georgescu
== Session ==
29 1 Adrian Georgescu
30 51 Adrian Georgescu
[[Image(sipsimple-session-state-machine.png, align=right, width=400)]]
31 51 Adrian Georgescu
32 44 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
33 44 Adrian Georgescu
34 1 Adrian Georgescu
A {{{sipsimple.session.Session}}} object represents a complete SIP session between the local and a remote endpoints. Both incoming and outgoing sessions are represented by this class.
35 1 Adrian Georgescu
36 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.
37 26 Luci Stanescu
State changes are triggered by methods called on the object by the application or by received network events.
38 1 Adrian Georgescu
Every time this attribute changes, a {{{SIPSessionChangedState}}} notification is sent by the object.
39 1 Adrian Georgescu
These states and their transitions are represented in the following diagram:
40 2 Adrian Georgescu
41 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.
42 1 Adrian Georgescu
43 50 Adrian Georgescu
=== Attributes ===
44 1 Adrian Georgescu
45 1 Adrian Georgescu
 '''state'''::
46 1 Adrian Georgescu
  The state the object is currently in, being one of the states from the diagram above.
47 18 Ruud Klaver
 '''account'''::
48 18 Ruud Klaver
  The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object that the {{{Session}}} is associated with.
49 18 Ruud Klaver
  On an outbound session, this is the account the application specified on object instantiation.
50 1 Adrian Georgescu
 '''direction'''::
51 1 Adrian Georgescu
  A string indicating the direction of the initial negotiation of the session.
52 1 Adrian Georgescu
  This can be either {{{None}}}, "incoming" or "outgoing".
53 1 Adrian Georgescu
 '''start_time'''::
54 1 Adrian Georgescu
  The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started.
55 1 Adrian Georgescu
 '''stop_time'''::
56 1 Adrian Georgescu
  The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated.
57 1 Adrian Georgescu
 '''on_hold_by_local'''::
58 1 Adrian Georgescu
  Boolean indicating whether the session was put on hold by the local party.
59 1 Adrian Georgescu
 '''on_hold_by_remote'''::
60 1 Adrian Georgescu
  Boolean indicating whether the session was put on hold by the remote party.
61 1 Adrian Georgescu
 '''on_hold'''::
62 1 Adrian Georgescu
  Boolean indicating whether the session was put on hold, either by the local or the remote party.
63 1 Adrian Georgescu
 '''remote_user_agent'''::
64 1 Adrian Georgescu
  A string indicating the remote user agent, if it provided one.
65 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).
66 1 Adrian Georgescu
 '''local_uri'''::
67 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} of the local party, if the session is active.
68 1 Adrian Georgescu
 '''remote_uri'''::
69 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} of the remote party, if the session is active.
70 1 Adrian Georgescu
 '''caller_uri'''::
71 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} of the calling party, if the session is active.
72 1 Adrian Georgescu
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
73 1 Adrian Georgescu
 '''callee_uri'''::
74 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} of the called party, if the session is active.
75 1 Adrian Georgescu
  Depending on the direction, this is either {{{local_uri}}} or {{{remote_uri}}}.
76 1 Adrian Georgescu
 '''route'''::
77 20 Ruud Klaver
  A copy of the {{{sipsimple.core.Route}}} object passed when the {{{connect()}}} method was called.
78 1 Adrian Georgescu
  On incoming or inactive sessions this is {{{None}}}.
79 1 Adrian Georgescu
 '''audio_transport'''::
80 1 Adrian Georgescu
  The {{{sipsimple.core.AudioTransport}}} object used by the session, if it currently contains an audio stream.
81 1 Adrian Georgescu
  Normally the application will not need to access this directly.
82 1 Adrian Georgescu
 '''has_audio'''::
83 23 Ruud Klaver
  A boolean indicating if this {{{Session}}} currently has an active audio stream.
84 1 Adrian Georgescu
 '''audio_sample_rate'''::
85 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the sample rate of the audio negotiated.
86 1 Adrian Georgescu
 '''audio_codec'''::
87 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the name of the audio codec that was negotiated.
88 1 Adrian Georgescu
 '''audio_srtp_active'''::
89 1 Adrian Georgescu
  If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream.
90 1 Adrian Georgescu
 '''audio_local_rtp_address'''::
91 1 Adrian Georgescu
  If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream.
92 1 Adrian Georgescu
 '''audio_local_rtp_port'''::
93 1 Adrian Georgescu
  If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream.
94 1 Adrian Georgescu
 '''audio_remote_rtp_address_sdp'''::
95 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to.
96 1 Adrian Georgescu
 '''audio_remote_rtp_port_sdp'''::
97 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to.
98 1 Adrian Georgescu
 '''audio_remote_rtp_address_received'''::
99 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received.
100 1 Adrian Georgescu
 '''audio_remote_rtp_port_received'''::
101 1 Adrian Georgescu
  If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received.
102 1 Adrian Georgescu
 '''audio_was_received'''::
103 1 Adrian Georgescu
  This boolean property indicates if audio was actually received on the audio stream contained within this session.
104 1 Adrian Georgescu
 '''audio_recording_file_name'''::
105 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.
106 1 Adrian Georgescu
 '''chat_transport'''::
107 1 Adrian Georgescu
  The {{{sipsimple.msrp.MSRPChat}}} object used by the session as chat transport, if the session currently contains a chat stream.
108 1 Adrian Georgescu
  Normally the application will not need to access this directly.
109 1 Adrian Georgescu
 '''has_chat'''::
110 23 Ruud Klaver
  A boolean property indicating if this {{{Session}}} currently has an active chat stream.
111 1 Adrian Georgescu
112 50 Adrian Georgescu
=== Methods ===
113 1 Adrian Georgescu
114 18 Ruud Klaver
 '''!__init!__'''(''self'', '''account''')::
115 1 Adrian Georgescu
  Creates a new {{{Session}}} object in the {{{NULL}}} state.
116 19 Ruud Klaver
  [[BR]]''account'':[[BR]]
117 19 Ruud Klaver
  The local account to be associated with this {{{Session}}}.
118 19 Ruud Klaver
 '''connect'''(''self'', '''callee_uri''', '''routes''', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
119 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.
120 26 Luci Stanescu
  Before contacting the remote party, a {{{SIPSessionNewOutgoing}}} notification will be emitted.
121 26 Luci Stanescu
  If there is a failure or the remote party rejected the offer, a {{{SIPSessionDidFail}}} notification will be sent, followed by a {{{SIPSessionDidEnd}}}.
122 26 Luci Stanescu
  Any time a ringing indication is received from the remote party, a {{{SIPSessionGotRingIndication}}} notification is sent.
123 26 Luci Stanescu
  If the remote party accepted the session, a {{{SIPSessionWillStart}}} notification will be sent, followed by a {{{SIPSessionDidStart}}} notification when the session is actually established.
124 1 Adrian Georgescu
  This method may only be called while in the {{{NULL}}} state.
125 1 Adrian Georgescu
  [[BR]]''callee_uri'':[[BR]]
126 1 Adrian Georgescu
  A {{{sipsimple.core.SIPURI}}} object representing the remote host to initiate the session to.
127 19 Ruud Klaver
  [[BR]]''routes'':[[BR]]
128 19 Ruud Klaver
  An iterable of {{{sipsimple.core.Route}}} objects, specifying the IP, port and transport to the outbound proxy.
129 19 Ruud Klaver
  These routes will be tried in order, until one of them succeeds.
130 1 Adrian Georgescu
  [[BR]]''audio'':[[BR]]
131 1 Adrian Georgescu
  A boolean indicating whether an audio stream should be initially included in this session.
132 1 Adrian Georgescu
  [[BR]]''chat'':[[BR]]
133 1 Adrian Georgescu
  A boolean indicating whether a chat stream should be initially included in this session.
134 19 Ruud Klaver
 '''accept'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
135 1 Adrian Georgescu
  Calling this methods will accept an incoming session and move the state machine to the {{{ACCEPTING}}} state.
136 26 Luci Stanescu
  When there is a new incoming session, a {{{SIPSessionNewIncoming}}} notification is sent, after which the application can call this method on the sender of the notification.
137 26 Luci Stanescu
  After this method is called, {{{SIPSessionWillStart}}} followed by {{{SIPSessionDidStart}}} will be emitted, or {{{SIPSessionDidFail}}} followed by {{{SIPSessionDidEnd}}} on an error.
138 1 Adrian Georgescu
  This method may only be called while in the {{{INCOMING}}} state.
139 1 Adrian Georgescu
  [[BR]]''audio'':[[BR]]
140 1 Adrian Georgescu
  A boolean indicating whether an audio stream should be accepted for this session.
141 1 Adrian Georgescu
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
142 1 Adrian Georgescu
  [[BR]]''chat'':[[BR]]
143 1 Adrian Georgescu
  A boolean indicating whether a chat stream should be accepted for this session.
144 1 Adrian Georgescu
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
145 41 Ruud Klaver
 '''reject'''(''self'', '''is_busy'''={{{False}}})::
146 1 Adrian Georgescu
  Reject an incoming session and move it to the {{{TERMINATING}}} state, which eventually leads to the {{{TERMINATED}}} state.
147 26 Luci Stanescu
  Calling this method will cause the {{{Session}}} object to emit a {{{SIPSessionWillEnd}}} notification, followed by a {{{SIPSessionDidEnd}}} notification.
148 1 Adrian Georgescu
  This method may only be called while in the {{{INCOMING}}} state.
149 41 Ruud Klaver
  [[BR]]''chat'':[[BR]]
150 41 Ruud Klaver
  A boolean indicating whether the response code sent to the remote party should be 486 (Busy) instead of 603 (Decline).
151 1 Adrian Georgescu
 '''hold'''(''self'')::
152 1 Adrian Georgescu
  Put the session on hold.
153 26 Luci Stanescu
  This will cause a {{{SIPGotHoldRequest}}} notification to be sent.
154 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
155 1 Adrian Georgescu
 '''unhold'''(''self'')::
156 1 Adrian Georgescu
  Take the session out of hold.
157 26 Luci Stanescu
  This will cause a {{{SIPGotUnholdRequest}}} notification to be sent.
158 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
159 19 Ruud Klaver
 '''start_recording_audio'''(''self'', '''file_name'''={{{None}}})::
160 1 Adrian Georgescu
  If an audio stream is present within this session, calling this method will record the audio to a {{{.wav}}} file.
161 1 Adrian Georgescu
  Note that when the session is on hold, nothing will be recorded to the file.
162 26 Luci Stanescu
  Right before starting the recording a {{{SIPSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SIPSessionDidStartRecordingAudio}}}.
163 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
164 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
165 1 Adrian Georgescu
  The name of the {{{.wav}}} file to record to.
166 1 Adrian Georgescu
  If this is set to {{{None}}}, a default file name including the session participants and the timestamp will be generated.
167 1 Adrian Georgescu
 '''stop_recording_audio'''(''self'')::
168 1 Adrian Georgescu
  This will stop a previously started recording.
169 26 Luci Stanescu
  Before stopping, a {{{SIPSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SIPSessionDidStopRecordingAudio}}}.
170 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
171 1 Adrian Georgescu
 '''send_dtmf'''(''self'', '''digit''')::
172 1 Adrian Georgescu
  If this session currently has an active audio stream, send a DTMF digit to the remote party over it.
173 23 Ruud Klaver
  This method may only be called while in the {{{ESTABLISHED}}} state and if the session has an active audio stream.
174 1 Adrian Georgescu
  [[BR]]''digit'':[[BR]]
175 1 Adrian Georgescu
  This should a string of length 1, containing a valid DTMF digit value.
176 13 Luci Stanescu
 '''send_message'''(''self'', '''content''', '''content_type'''="text/plain", '''to_uri'''={{{None}}}, '''dt'''={{{None}}})::
177 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.
178 26 Luci Stanescu
  This will result in either a {{{SIPSessionDidDeliverMessage}}} or a {{{SIPSessionDidNotDeliverMessage}}} notification being sent.
179 1 Adrian Georgescu
  These notifications include a unique ID as data attribute which is also returned by this method.
180 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state.
181 1 Adrian Georgescu
  [[BR]]''content'':[[BR]]
182 1 Adrian Georgescu
  The body of the MSRP message as a string.
183 1 Adrian Georgescu
  [[BR]]''content_type'':[[BR]]
184 1 Adrian Georgescu
  The Content-Type of the body as a string
185 22 Ruud Klaver
  [[BR]]''to_uri'':[[BR]]
186 1 Adrian Georgescu
  The {{{sipsimple.core.SIPURI}}} that should be put in the {{{To:}}} header of the CPIM wrapper of the message.
187 1 Adrian Georgescu
  This defaults to the SIP URI of the remote party of the session if the argument is set to {{{None}}}
188 1 Adrian Georgescu
  [[BR]]''dt'':[[BR]]
189 1 Adrian Georgescu
  A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message.
190 1 Adrian Georgescu
  When set to {{{None}}}, this defaults to now.
191 1 Adrian Georgescu
 '''add_audio'''(''self'')::
192 1 Adrian Georgescu
  Propose the remote party to add an audio stream to this session.
193 26 Luci Stanescu
  Calling this method will cause a {{{SIPSessionGotStreamProposal}}} notification to be emitted.
194 26 Luci Stanescu
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SIPSessionAcceptedStreamProposal}}} or {{{SIPSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
195 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.
196 1 Adrian Georgescu
 '''remove_audio'''(''self'')::
197 1 Adrian Georgescu
  Stop the audio stream currently active within the session and inform the remote party of this.
198 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has an audio stream.
199 1 Adrian Georgescu
 '''add_chat'''(''self'')::
200 1 Adrian Georgescu
  Propose the remote party to add a chat stream to this session.
201 26 Luci Stanescu
  Calling this method will cause a {{{SIPSessionGotStreamProposal}}} notification to be emitted.
202 26 Luci Stanescu
  After this, the state machine will move into the {{{PROPOSING}}} state until either a {{{SIPSessionAcceptedStreamProposal}}} or {{{SIPSessionRejectedStreamProposal}}} notification is sent, informing the application if the remote party accepted the proposal.
203 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.
204 1 Adrian Georgescu
 '''remove_chat'''(''self'')::
205 1 Adrian Georgescu
  Stop the chat stream currently active within the session and inform the remote party of this.
206 1 Adrian Georgescu
  This method may only be called while in the {{{ESTABLISHED}}} state on a {{{Session}}} object that has a chat stream.
207 19 Ruud Klaver
 '''accept_proposal'''(''self'', '''audio'''={{{False}}}, '''chat'''={{{False}}})::
208 26 Luci Stanescu
  When the remote party proposes to add a new stream, signaled by the {{{SIPSessionGotStreamProposal}}} notification, the application can use this method to accept the stream(s) being proposed.
209 1 Adrian Georgescu
  After calling this method a {{{SIPSessionAcceptedStreamProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a {{{SIPSessionRejectedStreamProposal}}} notification is sent and a rejection is sent to the remote party.
210 19 Ruud Klaver
  This method may only be called while in the {{{PROPOSED}}} state.
211 19 Ruud Klaver
  [[BR]]''audio'':[[BR]]
212 19 Ruud Klaver
  A boolean indicating whether an audio stream should be accepted for this proposal.
213 19 Ruud Klaver
  Note that this may only be set to {{{True}}} if an audio stream was actually proposed by the remote party.
214 19 Ruud Klaver
  [[BR]]''chat'':[[BR]]
215 19 Ruud Klaver
  A boolean indicating whether a chat stream should be accepted for this proposal.
216 26 Luci Stanescu
  Note that this may only be set to {{{True}}} if a chat stream was actually proposed by the remote party.
217 1 Adrian Georgescu
 '''reject_proposal'''(''self'')::
218 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 {{{SIPSessionRejectedStreamProposal}}} notification is sent.
219 41 Ruud Klaver
  This method may only be called while in the {{{PROPOSED}}} state.
220 1 Adrian Georgescu
 '''end'''(''self'' '''is_busy'''={{{False}}})::
221 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.
222 1 Adrian Georgescu
  Right before termination a {{{SIPSessionWillEnd}}} notification is sent, after termination {{{SIPSessionDidEnd}}} is sent.
223 41 Ruud Klaver
  [[BR]]''chat'':[[BR]]
224 41 Ruud Klaver
  A boolean indicating whether the response code sent to the remote party should be 486 (Busy) instead of 603 (Decline).
225 1 Adrian Georgescu
226 50 Adrian Georgescu
=== Notifications ===
227 1 Adrian Georgescu
228 26 Luci Stanescu
 '''SIPSessionChangedState'''::
229 1 Adrian Georgescu
  Will be sent whenever the {{{Session}}} object changes its state.
230 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
231 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
232 1 Adrian Georgescu
  [[BR]]''prev_state'':[[BR]]
233 1 Adrian Georgescu
  The previous state state the object was in.
234 1 Adrian Georgescu
  [[BR]]''state'':[[BR]]
235 1 Adrian Georgescu
  The new state the object is in.
236 26 Luci Stanescu
 '''SIPSessionNewIncoming'''::
237 1 Adrian Georgescu
  Will be sent when a new incoming {{{Session}}} is received.
238 1 Adrian Georgescu
  The application should listen for this notification from all objects specifically to get informed of incoming sessions.
239 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
240 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
241 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
242 19 Ruud Klaver
  A list of strings indicating the streams that were proposed by the remote party.
243 26 Luci Stanescu
 '''SIPSessionNewOutgoing'''::
244 1 Adrian Georgescu
  Will be sent when the applcation requests a new outgoing {{{Session}}}.
245 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
246 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
247 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
248 32 Adrian Georgescu
  A list of strings indicating the streams that were proposed to the remote party.
249 26 Luci Stanescu
 '''SIPSessionGotRingIndication'''::
250 1 Adrian Georgescu
  Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing.
251 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
252 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
253 26 Luci Stanescu
 '''SIPSessionWillStart'''::
254 1 Adrian Georgescu
  Will be sent just before a {{{Session}}} completes negotiation.
255 1 Adrian Georgescu
  In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}.
256 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
257 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
258 26 Luci Stanescu
 '''SIPSessionDidStart'''::
259 1 Adrian Georgescu
  Will be sent when a {{{Session}}} completes negotiation.
260 1 Adrian Georgescu
  In terms of SIP this is sent after the {{{ACK}}} was sent or received.
261 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
262 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
263 26 Luci Stanescu
 '''SIPSessionDidFail'''::
264 1 Adrian Georgescu
  This notification is sent whenever the session fails.
265 1 Adrian Georgescu
  The failure reason is included in the data attributes.
266 26 Luci Stanescu
  This notification is always followed by {{{SIPSessionDidEnd}}}.
267 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
268 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
269 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
270 1 Adrian Georgescu
  A string indicating the origin of the failure.
271 1 Adrian Georgescu
  This will either be "local" or "remote".
272 1 Adrian Georgescu
  [[BR]]''code'':[[BR]]
273 1 Adrian Georgescu
  The SIP error code of the failure.
274 1 Adrian Georgescu
  If this is 0, the error was an internal exception.
275 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
276 1 Adrian Georgescu
  A string explaining the reason of the failure.
277 26 Luci Stanescu
 '''SIPSessionWillEnd'''::
278 1 Adrian Georgescu
  Will be sent just before terminating a {{{Session}}} at the request of the application.
279 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
280 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
281 26 Luci Stanescu
 '''SIPSessionDidEnd'''::
282 26 Luci Stanescu
  Will be sent always when a {{{Session}}} ends, either because of a failure (in which case it is preceded by {{{SIPSessionDidFail}}}), remote or local session termination.
283 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
284 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
285 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
286 1 Adrian Georgescu
  A string indicating who originated the termination.
287 1 Adrian Georgescu
  This will either be "local" or "remote".
288 26 Luci Stanescu
 '''SIPSessionGotHoldRequest'''::
289 1 Adrian Georgescu
  Will be sent when the session got put on hold, either by the local or the remote party.
290 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
291 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
292 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
293 1 Adrian Georgescu
  A string indicating who originated the hold request, and consequently in which direction the session got put on hold.
294 26 Luci Stanescu
 '''SIPSessionGotUnholdRequest'''::
295 1 Adrian Georgescu
  Will be sent when the session got taken out of hold, either by the local or the remote party.
296 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
297 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
298 1 Adrian Georgescu
  [[BR]]''originator'':[[BR]]
299 1 Adrian Georgescu
  A string indicating who sent the original hold request, and consequently in which direction the session got taken out of hold.
300 26 Luci Stanescu
 '''SIPSessionWillStartRecordingAudio'''::
301 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.
302 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
303 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
304 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
305 1 Adrian Georgescu
  The name of the recording {{{.wav}}} file, including full path.
306 26 Luci Stanescu
 '''SIPSessionDidStartRecordingAudio'''::
307 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.
308 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
309 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
310 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
311 1 Adrian Georgescu
  The name of the recording {{{.wav}}} file, including full path.
312 26 Luci Stanescu
 '''SIPSessionWillStopRecordingAudio'''::
313 1 Adrian Georgescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
314 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
315 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
316 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
317 1 Adrian Georgescu
  The name of the recording {{{.wav}}} file, including full path.
318 26 Luci Stanescu
 '''SIPSessionDidStopRecordingAudio'''::
319 1 Adrian Georgescu
  Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops.
320 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
321 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
322 1 Adrian Georgescu
  [[BR]]''file_name'':[[BR]]
323 1 Adrian Georgescu
  The name of the recording {{{.wav}}} file, including full path.
324 26 Luci Stanescu
 '''SIPSessionGotNoAudio'''::
325 1 Adrian Georgescu
  This notification will be sent if 5 seconds after the audio stream starts, no audio was received from the remote party.
326 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
327 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
328 26 Luci Stanescu
 '''SIPSessionGotDTMF'''::
329 1 Adrian Georgescu
  Will be send if there is a DMTF digit received from the remote party on the audio stream. 
330 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
331 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
332 1 Adrian Georgescu
  [[BR]]''digit'':[[BR]]
333 1 Adrian Georgescu
  The DTMF digit that was received, in the form of a string of length 1.
334 26 Luci Stanescu
 '''SIPSessionGotMessage'''::
335 1 Adrian Georgescu
  Will be sent whenever a MSRP message is received on the chat stream of the session.
336 1 Adrian Georgescu
  [[BR]]''content'':[[BR]]
337 1 Adrian Georgescu
  The body of the message.
338 1 Adrian Georgescu
  [[BR]]''content_type'':[[BR]]
339 1 Adrian Georgescu
  The Content-Type of the body.
340 1 Adrian Georgescu
  [[BR]]''cpim_headers'':[[BR]]
341 1 Adrian Georgescu
  A dictionary of headers included in the CPIM wrapper.
342 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
343 5 Redmine Admin
  Raw MSRP message, an msrplib.protocol.MSRPData instance
344 26 Luci Stanescu
 '''SIPSessionDidDeliverMessage'''::
345 1 Adrian Georgescu
  Will be sent when a previously sent MSRP chat message got delivered to the remote party.
346 1 Adrian Georgescu
  [[BR]]''message_id'':[[BR]]
347 1 Adrian Georgescu
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
348 1 Adrian Georgescu
  [[BR]]''code'':[[BR]]
349 1 Adrian Georgescu
  The response code of the confirmation report.
350 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
351 5 Redmine Admin
  The reason string of the confirmation report.
352 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
353 1 Adrian Georgescu
  Raw MSRP message, an msrplib.protocol.MSRPData instance
354 26 Luci Stanescu
 '''SIPSessionDidDeliverMessage'''::
355 1 Adrian Georgescu
  Will be sent when a previously sent MSRP chat message did not get delivered to the remote party.
356 1 Adrian Georgescu
  [[BR]]''message_id'':[[BR]]
357 1 Adrian Georgescu
  The unique identifier of this message as a string, as previously returned by the {{{send_message()}}} method.
358 1 Adrian Georgescu
  [[BR]]''code'':[[BR]]
359 1 Adrian Georgescu
  The response code of the confirmation report.
360 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
361 5 Redmine Admin
  The reason string of the confirmation report.
362 1 Adrian Georgescu
  [[BR]]''message'':[[BR]]
363 1 Adrian Georgescu
  Raw MSRP message, an msrplib.protocol.MSRPData instance
364 26 Luci Stanescu
 '''SIPSessionGotStreamProposal'''::
365 1 Adrian Georgescu
  Will be sent when either the local or the remote party proposes to add a stream to the session.
366 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
367 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
368 1 Adrian Georgescu
  [[BR]]''proposer'':[[BR]]
369 1 Adrian Georgescu
  The party that did the stream proposal, can be either "local" or "remote".
370 19 Ruud Klaver
  [[BR]]''streams'':[[BR]]
371 19 Ruud Klaver
  A list of strings indicating the streams that were proposed.
372 26 Luci Stanescu
 '''SIPSessionRejectedStreamProposal'''::
373 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.
374 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
375 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
376 1 Adrian Georgescu
  [[BR]]''proposer'':[[BR]]
377 1 Adrian Georgescu
  The party that did the stream proposal, can be either "local" or "remote".
378 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
379 1 Adrian Georgescu
  The reason for rejecting the stream proposal.
380 1 Adrian Georgescu
 '''SIPSessionRejectedStreamProposal'''::
381 26 Luci Stanescu
  Will be sent when either the local or the remote party accepts a proposal to have (a) stream(s) added to the session.
382 1 Adrian Georgescu
  [[BR]]''timestamp'':[[BR]]
383 1 Adrian Georgescu
  A {{{datetime.datetime}}} object indicating when the notification was sent.
384 1 Adrian Georgescu
  [[BR]]''proposer'':[[BR]]
385 1 Adrian Georgescu
  The party that did the stream proposal, can be either "local" or "remote".
386 1 Adrian Georgescu
 '''SIPSessionGotStreamUpdate'''::
387 26 Luci Stanescu
  Will be sent when a media stream is either activated or deactivated.
388 23 Ruud Klaver
  An application should listen to this notification in order to know when a media stream can be used.
389 23 Ruud Klaver
  [[BR]]''timestamp'':[[BR]]
390 23 Ruud Klaver
  A {{{datetime.datetime}}} object indicating when the notification was sent.
391 23 Ruud Klaver
  [[BR]]''streams'':[[BR]]
392 23 Ruud Klaver
  A list indicating which streams are active on the session from this point onwards.
393 23 Ruud Klaver
394 30 Adrian Georgescu
As an example for how to use the {{{Session}}} object, the following provides a basic Python program that initiates an outgoing SIP session request:
395 6 Ruud Klaver
396 6 Ruud Klaver
{{{
397 24 Ruud Klaver
import sys
398 6 Ruud Klaver
from threading import Event
399 6 Ruud Klaver
from zope.interface import implements
400 6 Ruud Klaver
from application.notification import IObserver, NotificationCenter
401 1 Adrian Georgescu
402 24 Ruud Klaver
from sipsimple.configuration import ConfigurationManager
403 24 Ruud Klaver
from sipsimple.account import AccountManager
404 24 Ruud Klaver
from sipsimple.engine import Engine
405 24 Ruud Klaver
from sipsimple.session import Session
406 24 Ruud Klaver
from sipsimple.core import SIPURI, Route
407 24 Ruud Klaver
408 1 Adrian Georgescu
class SimpleOutboundCall(object):
409 1 Adrian Georgescu
    # indicate that we implement the application.notification.IObserver interface
410 1 Adrian Georgescu
    implements(IObserver)
411 1 Adrian Georgescu
412 24 Ruud Klaver
    def __init__(self, remote_uri, route):
413 1 Adrian Georgescu
        # setup a threading.Event to signal that the Engine has stopped
414 1 Adrian Georgescu
        self.engine_ended_event = Event()
415 24 Ruud Klaver
        # start the configuration manager
416 24 Ruud Klaver
        ConfigurationManager().start()
417 24 Ruud Klaver
        # start the account manager
418 24 Ruud Klaver
        am = AccountManager()
419 24 Ruud Klaver
        am.start()
420 24 Ruud Klaver
        # start the Engine with configuration framework parameters
421 24 Ruud Klaver
        Engine().start_cfg()
422 24 Ruud Klaver
        # create a new Session using the default account
423 24 Ruud Klaver
        self.session = Session(am.default_account)
424 6 Ruud Klaver
        # listen for the notification that the Engine stopped
425 26 Luci Stanescu
        NotificationCenter().add_observer(self, "SIPEngineDidEnd", Engine())
426 6 Ruud Klaver
        # listen for the notification that the Session ended
427 26 Luci Stanescu
        NotificationCenter().add_observer(self, "SIPSessionDidEnd", self.session)
428 6 Ruud Klaver
        # start a new outbound session
429 24 Ruud Klaver
        self.session.connect(remote_uri, [route], audio=True)
430 6 Ruud Klaver
431 23 Ruud Klaver
    def end(self):
432 6 Ruud Klaver
        # if the Session is still active, terminate it
433 6 Ruud Klaver
        self.session.end()
434 6 Ruud Klaver
        # wait for the engine to stop, processed in handle_notification
435 6 Ruud Klaver
        self.engine_ended_event.wait()
436 6 Ruud Klaver
        # quit the progam, as this can only be done from the main thread
437 6 Ruud Klaver
        sys.exit()
438 6 Ruud Klaver
439 1 Adrian Georgescu
    def handle_notification(self, notification):
440 1 Adrian Georgescu
        if notification.name == "SIPSessionDidEnd":
441 1 Adrian Georgescu
            # if for whatever reason the session ended, stop the Engine
442 1 Adrian Georgescu
            print "Session ended"
443 1 Adrian Georgescu
            Engine().stop()
444 1 Adrian Georgescu
        elif notification.name == "SIPEngineDidEnd":
445 1 Adrian Georgescu
            # once the Engine has stopped, signal the (possibly) waiting main
446 1 Adrian Georgescu
            # thread through a threading.Event
447 1 Adrian Georgescu
            self.engine_ended_event.set()
448 1 Adrian Georgescu
449 1 Adrian Georgescu
# place an audio call from the specified account to the specified URI, through
450 1 Adrian Georgescu
# the specified SIP proxy
451 1 Adrian Georgescu
# edit this to reflect real settings
452 1 Adrian Georgescu
call = SimpleOutboundCall(SIPURI(user="bob", host="example.com"), Route("1.2.3.4"))
453 1 Adrian Georgescu
# block waiting for user input
454 1 Adrian Georgescu
print "Placing call, press enter to quit program"
455 26 Luci Stanescu
raw_input()
456 6 Ruud Klaver
# block in end() until the Engine has stopped
457 30 Adrian Georgescu
call.end()
458 30 Adrian Georgescu
}}}
459 47 Adrian Georgescu
460 50 Adrian Georgescu
== SessionManager ==
461 31 Adrian Georgescu
462 1 Adrian Georgescu
Implemented in [browser:sipsimple/session.py]
463 30 Adrian Georgescu
464 30 Adrian Georgescu
The {{{sipsimple.session.SessionManager}}} class is a singleton, which acts as the central aggregation point for sessions within the middleware.
465 30 Adrian Georgescu
Although it is mainly used internally, the application can use it to query information about all active sessions.
466 1 Adrian Georgescu
The SessionManager is implemented as a singleton, meaning that only one instance of this class exists within the middleware.
467 30 Adrian Georgescu
Note that, in order to be able to receive calls, the application has to instantiate this object.
468 30 Adrian Georgescu
469 50 Adrian Georgescu
=== Attributes ===
470 30 Adrian Georgescu
471 1 Adrian Georgescu
 '''sessions'''::
472 30 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.
473 30 Adrian Georgescu
474 50 Adrian Georgescu
=== Methods ===
475 30 Adrian Georgescu
476 30 Adrian Georgescu
 '''!__init!__'''(''self'')::
477 35 Luci Stanescu
  This either returns a new {{{SessionManager}}} object with default configuration objects, or returns a copy of the already existing instance.
478 1 Adrian Georgescu
479 35 Luci Stanescu
480 50 Adrian Georgescu
== Account ==
481 47 Adrian Georgescu
482 47 Adrian Georgescu
Implemented in [browser:sipsimple/account.py]
483 35 Luci Stanescu
484 40 Luci Stanescu
The {{{sipsimple.account.Account}}} objects represent the SIP accounts which are used by the middleware. It has a dual purpose: it acts as both a container for account-related settings and as a complex object which can be used to interact with various per-account functions, such as presence, registration etc. This page documents the latter case, while the former is explained in the [wiki:SipConfigurationAPI#Account Configuration API].
485 35 Luci Stanescu
486 35 Luci Stanescu
There is exactly one instance of {{{Account}}} per SIP account used and it is uniquely identifiable by its SIP ID, in the form ''user@domain''. It is a singleton, in the sense that instantiating {{{Account}}} using an already used SIP ID will return the same object. However, this is not the recommended way of accessing accounts, as this can lead to creation of new ones; the recommended way is by using the [wiki:SipMiddlewareApi#AccountManager AccountManager]. The next sections will use a lowercase, monospaced {{{account}}} to represent an instance of {{{Account}}}.
487 35 Luci Stanescu
488 50 Adrian Georgescu
=== States ===
489 35 Luci Stanescu
490 35 Luci Stanescu
The {{{Account}}} objects have a setting flag called {{{enabled}}} which, if set to {{{False}}} will deactivate it: none of the internal functions will work in this case; in addition, the application using the middleware should not do anything with a disabled account. After changing it's value, the {{{save()}}} method needs to be called, as the flag is a setting and will not be used until this method is called:
491 35 Luci Stanescu
{{{
492 35 Luci Stanescu
account.enabled = True
493 35 Luci Stanescu
account.save()
494 35 Luci Stanescu
}}}
495 37 Luci Stanescu
496 37 Luci Stanescu
The {{{Account}}} objects will activate automatically when they are loaded/created if the {{{enabled}}} flag is set to {{{True}}} and the {{{sipsimple.engine.Engine}}} is running; if it is not running, the accounts will activate after the engine starts.
497 39 Luci Stanescu
498 39 Luci Stanescu
In order to create a new account, just create a new instance of {{{Account}}} with an id which doesn't belong to any other account.
499 35 Luci Stanescu
500 35 Luci Stanescu
The other functions of {{{Account}}} which run automatically have other enabled flags as well. They will only be activated when both the global enabled flag is set and the function-specific one. These are:
501 35 Luci Stanescu
502 1 Adrian Georgescu
 '''Account.registration.enabled'''::
503 35 Luci Stanescu
  This flag controls the automatic registration of the account. The notifications '''SIPAccountRegistrationDidSucceed''', '''SIPAccountRegistrationDidFail''' and '''SIPAccountRegistrationDidEnd''' are used to inform the status of this registration.
504 35 Luci Stanescu
 '''Account.presence.enabled'''::
505 35 Luci Stanescu
  This flag controls the automatic subscription to buddies for the ''presence'' event and the publication of data in this event. (Not implemented yet)
506 35 Luci Stanescu
 '''Account.dialog_event.enabled'''::
507 35 Luci Stanescu
  This flag controls the automatic subscription to buddies for the ''dialog-info'' event and the publication of data in this event. (Not implemented yet)
508 35 Luci Stanescu
 '''Account.message_summary.enabled'''::
509 35 Luci Stanescu
  This flag controls the automatic subscription to the ''message-summary'' event in order to find out about voicemail messages. (Not implemented yet)
510 1 Adrian Georgescu
511 39 Luci Stanescu
The {{{save()}}} method needs to be called after changing these flags in order for them to take effect. The methods available on {{{Account}}} objects are inherited from [wiki:SipConfigurationAPI#SettingsObject SettingsObject].
512 36 Luci Stanescu
513 50 Adrian Georgescu
=== Attributes ===
514 36 Luci Stanescu
515 36 Luci Stanescu
The following attributes can be used on an Account object and need to be considered read-only.
516 36 Luci Stanescu
517 36 Luci Stanescu
 '''id'''::
518 36 Luci Stanescu
  This attribute is of type {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of {{{str}}}) and contains the SIP id of the account. It can be used as a normal string in the form ''user@domain'', but it also allows access to the components via the attributes {{{username}}} and {{{domain}}}.
519 36 Luci Stanescu
  {{{
520 36 Luci Stanescu
  account.id # 'alice@example.com'
521 36 Luci Stanescu
  account.id.username # 'alice'
522 36 Luci Stanescu
  account.id.domain # 'example.com'
523 36 Luci Stanescu
  }}}
524 36 Luci Stanescu
 '''contact'''::
525 36 Luci Stanescu
  This attribute can be used to construct the Contact URI for SIP requests sent on behalf of this account. It's type is {{{sipsimple.account.ContactURI}}} which is a subclass of {{{sipsimple.configuration.datatypes.SIPAddress}}}. In addition to the attributes defined in {{{SIPAddress}}}, it can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}} or {{{'tls'}}}) which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate port and transport parameter. The username part is a randomly generated 8 character string consisting of lowercase letters; the domain part is the IP address on which the {{{Engine}}} is listening (as specified by the SIPSimpleSettings.local_ip setting).
526 36 Luci Stanescu
  {{{
527 1 Adrian Georgescu
  account.contact # 'hnfkybrt@10.0.0.1'
528 36 Luci Stanescu
  account.contact.username # 'hnfkybrt'
529 36 Luci Stanescu
  account.contact.domain # '10.0.0.1'
530 36 Luci Stanescu
  account.contact['udp'] # <SIPURI "sip:hnfkybrt@10.0.0.1:53024">
531 36 Luci Stanescu
  account.contact['tls'] # <SIPURI "sip:hnfkybrt@10.0.0.1:54478;transport=tls">
532 36 Luci Stanescu
  }}}
533 36 Luci Stanescu
 '''credentials'''::
534 36 Luci Stanescu
  This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{id}}} attribute and {{{display_name}}} and {{{password}}} settings of the Account. Whenever one of these settings are changed, this attribute is updated.
535 36 Luci Stanescu
  {{{
536 36 Luci Stanescu
  account.credentials # <Credentials for '"Alice" <sip:alice@example.com>'>
537 36 Luci Stanescu
  }}}
538 37 Luci Stanescu
539 50 Adrian Georgescu
=== Notifications ===
540 37 Luci Stanescu
541 37 Luci Stanescu
 '''CFGSettingsObjectDidChange'''::
542 37 Luci Stanescu
  This notification is sent when the {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the {{{SettingsObject}}} class, it is exaplained in detail in [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications].
543 37 Luci Stanescu
 '''SIPAccountDidActivate'''::
544 37 Luci Stanescu
  This notification is sent when the {{{Account}}} activates. This can happen when the {{{Account}}} is loaded if it's enabled flag is set and the Engine is running, and at any later time when the status of the Engine changes or the enabled flag is modified. The notification does not contain any data.
545 37 Luci Stanescu
 '''SIPAccountDidDeactivate'''::
546 37 Luci Stanescu
  This notification is sent when the {{{Account}}} deactivates. This can happend when the {{{Engine}}} is stopped or when the enabled flag of the account is set to {{{False}}}. The notification does not contain any data.
547 37 Luci Stanescu
 '''SIPAccountRegistrationDidSucceed'''::
548 37 Luci Stanescu
  This notification is sent when a REGISTER request sent for the account succeeds (it is also sent for each refresh of the registration). The data contained in this notification is:
549 37 Luci Stanescu
  [[BR]]''code'':[[BR]]
550 37 Luci Stanescu
   The status code of the response for the REGISTER request.
551 37 Luci Stanescu
  [[BR]]''reason'':[[BR]]
552 37 Luci Stanescu
   The reason of the response for the REGISTER request.
553 37 Luci Stanescu
  [[BR]]''contact_uri'':[[BR]]
554 37 Luci Stanescu
   The Contact URI which was registered.
555 37 Luci Stanescu
  [[BR]]''contact_uri_list'':[[BR]]
556 37 Luci Stanescu
   A list containing all the contact URIs registered for this SIP account.
557 37 Luci Stanescu
  [[BR]]''expires'':[[BR]]
558 37 Luci Stanescu
   The amount in seconds in which this registration will expire.
559 37 Luci Stanescu
  [[BR]]''registration'':[[BR]]
560 37 Luci Stanescu
   The {{{sipsimple.core.Registration}}} object used to register this account.
561 37 Luci Stanescu
 '''SIPAccountRegistrationDidFail'''::
562 37 Luci Stanescu
  This notification is sent when a REGISTER request sent for the account fails. It can fail either because a negative response was returned or because PJSIP considered the request failed (e.g. on timeout). The data contained in this notification is:
563 37 Luci Stanescu
  [[BR]]''code'':[[BR]]
564 37 Luci Stanescu
   The status code of the response for the REGISTER request. This is only present if the notification is sent as a result of a response being received.
565 37 Luci Stanescu
  [[BR]]''reason'':[[BR]]
566 37 Luci Stanescu
   The reason for the failure of the REGISTER request.
567 37 Luci Stanescu
  [[BR]]''registration'':[[BR]]
568 37 Luci Stanescu
   The {{{sipsimple.core.Registration}}} object which failed.
569 1 Adrian Georgescu
  [[BR]]''next_route'':[[BR]]
570 37 Luci Stanescu
   A {{{sipsimple.core.Route}}} object which will be tried next for registering the account, or {{{None}}} if a new DNS lookup needs to be performed.
571 37 Luci Stanescu
  [[BR]]''delay'':[[BR]]
572 37 Luci Stanescu
   The amount in seconds as a {{{float}}} after which the next route will be tried for registering the account.
573 37 Luci Stanescu
 '''SIPAccountRegistrationDidEnd'''::
574 1 Adrian Georgescu
  This notification is sent when a registration is ended (the account is unregistered). The data contained in this notification is:
575 37 Luci Stanescu
  [[BR]]''code'':[[BR]]
576 37 Luci Stanescu
   The status code of the response for the REGISTER with {{{Expires: 0}}} request. This is only present if a response was received.
577 1 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
578 37 Luci Stanescu
   The reason returned in the response for the Register with {{{Expires: 0}}} request. This is only present if a response was received
579 37 Luci Stanescu
  [[BR]]''registration'':[[BR]]
580 37 Luci Stanescu
   The {{{sipsimple.core.Registration}}} object which ended.
581 37 Luci Stanescu
582 50 Adrian Georgescu
== BonjourAccount ==
583 37 Luci Stanescu
584 48 Adrian Georgescu
Implemented in [browser:sipsimple/account.py]
585 48 Adrian Georgescu
586 37 Luci Stanescu
The {{{sipsimple.account.BonjourAccount}}} represents the SIP account used for P2P mode; it does not interact with any server. The class is a singleton, as there can only be one such account on a system. Similar to the {{{Account}}}, it is used both as a complex object, which implements the functions for bonjour mode, as well as a container for the related settings.
587 37 Luci Stanescu
588 50 Adrian Georgescu
=== States ===
589 38 Luci Stanescu
590 38 Luci Stanescu
The {{{BonjourAccount}}} has an {{{enabled}}} flags which controls whether this account will be used or not. If it is set to {{{False}}}, none of the internal functions will be activated and, in addition, the account should not be used by the application. The bonjour account can only activated if the Engine is running; once it is started, if the enabled flag is set, the account will activate. When the {{{BonjourAccount}}} is activated, it will broadcast the contact address on the LAN. (Not implemented yet)
591 38 Luci Stanescu
592 50 Adrian Georgescu
=== Attributes ===
593 38 Luci Stanescu
594 38 Luci Stanescu
The following attributes can be used on an BonjourAccount object and need to be considered read-only.
595 38 Luci Stanescu
596 38 Luci Stanescu
 '''id'''::
597 38 Luci Stanescu
  This attribute is of type {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of {{{str}}}) and contains the SIP id of the account, which is {{{'bonjour@local'}}}. It can be used as a normal string, but it also allows access to the components via the attributes {{{username}}} and {{{domain}}}.
598 38 Luci Stanescu
  {{{
599 38 Luci Stanescu
  bonjour_account.id # 'bonjour@local'
600 38 Luci Stanescu
  bonjour_account.id.username # 'bonjour'
601 38 Luci Stanescu
  bonjour_account.id.domain # 'local'
602 1 Adrian Georgescu
  }}}
603 38 Luci Stanescu
 '''contact'''::
604 38 Luci Stanescu
  This attribute can be used to construct the Contact URI for SIP requests sent on behalf of this account. It's type is {{{sipsimple.account.ContactURI}}} which is a subclass of {{{sipsimple.configuration.datatypes.SIPAddress}}}. In addition to the attributes defined in {{{SIPAddress}}}, it can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}} or {{{'tls'}}}) which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate port and transport parameter. The username part is a randomly generated 8 character string consisting of lowercase letters; the domain part is the IP address on which the {{{Engine}}} is listening (as specified by the SIPSimpleSettings.local_ip setting).
605 38 Luci Stanescu
  {{{
606 38 Luci Stanescu
  account.contact # 'lxzvgack@10.0.0.1'
607 38 Luci Stanescu
  account.contact.username # 'lxzvgack'
608 38 Luci Stanescu
  account.contact.domain # '10.0.0.1'
609 38 Luci Stanescu
  account.contact['udp'] # <SIPURI "sip:lxzvgack@10.0.0.1:53024">
610 38 Luci Stanescu
  account.contact['tls'] # <SIPURI "sip:lxzvgack@10.0.0.1:54478;transport=tls">
611 1 Adrian Georgescu
  }}}
612 38 Luci Stanescu
 '''credentials'''::
613 38 Luci Stanescu
  This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{contact}}} attribute and {{{display_name}}} setting of the BonjourAccount; the password is set to the empty string. Whenever the display_name setting is changed, this attribute is updated.
614 38 Luci Stanescu
  {{{
615 1 Adrian Georgescu
  account.credentials # <Credentials for '"Alice" <sip:lxzvgack@10.0.0.1>'>
616 1 Adrian Georgescu
  }}}
617 39 Luci Stanescu
618 50 Adrian Georgescu
=== Notifications ===
619 39 Luci Stanescu
620 39 Luci Stanescu
 '''CFGSettingsObjectDidChange'''::
621 39 Luci Stanescu
  This notification is sent when the {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the {{{SettingsObject}}} class, it is exaplained in detail in [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications].
622 39 Luci Stanescu
 '''SIPAccountDidActivate'''::
623 39 Luci Stanescu
  This notification is sent when the {{{BonjourAccount}}} activates. This can happen when the {{{BonjourAccount}}} is loaded if it's enabled flag is set and the Engine is running, and at any later time when the status of the Engine changes or the enabled flag is modified. The notification does not contain any data.
624 39 Luci Stanescu
 '''SIPAccountDidDeactivate'''::
625 39 Luci Stanescu
  This notification is sent when the {{{BonjourAccount}}} deactivates. This can happend when the {{{Engine}}} is stopped or when the enabled flag of the account is set to {{{False}}}. The notification does not contain any data.
626 39 Luci Stanescu
627 39 Luci Stanescu
628 50 Adrian Georgescu
== AccountManager ==
629 48 Adrian Georgescu
630 39 Luci Stanescu
Implemented in [browser:sipsimple/account.py]
631 39 Luci Stanescu
632 39 Luci Stanescu
The {{{sipsimple.account.AccountManager}}} is the entity responsible for loading and keeping track of the existing accounts. It is a singleton and can be instantiated anywhere, obtaining the same instance. It cannot be used until its {{{start}}} method has been called.
633 39 Luci Stanescu
634 50 Adrian Georgescu
=== Methods ===
635 39 Luci Stanescu
636 39 Luci Stanescu
 '''!__init!__'''(''self'')::
637 39 Luci Stanescu
  The {{{__init__}}} method allows the {{{AccountManager}}} to be instantiated without passing any parameters. A reference to the {{{AccountManager}}} can be obtained anywhere before it is started.
638 39 Luci Stanescu
 '''start'''(''self'')::
639 39 Luci Stanescu
  This method will load all the existing accounts from the configuration. If the Engine is running, the accounts will also activate. This method can only be called after the [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] has been started. A '''SIPAccountManagerDidAddAccount''' will be sent for each account loaded.
640 39 Luci Stanescu
 '''stop'''(''self'')::
641 39 Luci Stanescu
  Calling this method will deactivate all accounts managed by the {{{AccountManager}}}.
642 39 Luci Stanescu
 '''has_account'''(''self'', '''id''')::
643 39 Luci Stanescu
  This method returns {{{True}}} if an account which has the specifed SIP ID (must be a string) exists and {{{False}}} otherwise.
644 39 Luci Stanescu
 '''get_account'''(''self'', '''id''')::
645 39 Luci Stanescu
  Returns the account (either an {{{Account}}} instance or the {{{BonjourAccount}}} instance) with the specified SIP ID. Will raise a {{{KeyError}}} if such an account does not exist.
646 39 Luci Stanescu
 '''get_accounts'''(''self'')::
647 39 Luci Stanescu
  Returns a list containing all the managed accounts.
648 39 Luci Stanescu
 '''iter_accounts'''(''self'')::
649 39 Luci Stanescu
  Returns an iterator through all the managed accounts.
650 39 Luci Stanescu
 '''find_account'''(''self'', '''contact_uri''')::
651 39 Luci Stanescu
  Returns an account with matches the specified {{{contact_uri}}} which must be a {{{sipsimple.core.SIPURI}}} instance. Only the accounts with the enabled flag set will be considered. Returns None if such an account does not exist.
652 39 Luci Stanescu
653 50 Adrian Georgescu
=== Notifications ===
654 39 Luci Stanescu
655 39 Luci Stanescu
 '''SIPAccountManagerDidAddAccount'''::
656 39 Luci Stanescu
  This notification is sent when a new account becomes available to the {{{AccountManager}}}. The notification is also sent when the accounts are loaded from the configuration. The data contains a single attribute, {{{account}}} which is the account object which was added.
657 39 Luci Stanescu
 '''SIPAccountManagerDidRemoveAccount'''::
658 39 Luci Stanescu
  This notification is sent when an account is deleted using the {{{delete}}} method. The data contains a single attribute, {{{account}}} which is the account object which was deleted.
659 39 Luci Stanescu
 '''SIPAccountManagerDidChangeDefaultAccount'''::
660 39 Luci Stanescu
  This notification is sent when the default account changes. The notification contains two attributes:
661 39 Luci Stanescu
  [[BR]]''old_account'':[[BR]]
662 39 Luci Stanescu
   This is the account object which used to be the default account.
663 39 Luci Stanescu
  [[BR]]''account'':[[BR]]
664 39 Luci Stanescu
   This is the account object which is the new default account.
665 55 Adrian Georgescu
666 55 Adrian Georgescu
== IMediaStream ==
667 55 Adrian Georgescu
668 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/__init__.py]
669 55 Adrian Georgescu
670 55 Adrian Georgescu
This module automatically registers media streams to a stream registry
671 55 Adrian Georgescu
allowing for a plug and play mechanism of various types of media negoticated
672 55 Adrian Georgescu
in a SIP session that can be added to this library by using a generic API.
673 55 Adrian Georgescu
674 55 Adrian Georgescu
For actual usage see rtp.py and msrp.py that implement media streams based
675 55 Adrian Georgescu
on their respective RTP and MSRP protocols.
676 55 Adrian Georgescu
677 55 Adrian Georgescu
678 55 Adrian Georgescu
=== Atributes ===
679 55 Adrian Georgescu
680 55 Adrian Georgescu
 '''type''' (class attribute)::
681 55 Adrian Georgescu
 A string identifying the stream type (ex: audio, video, ...)
682 55 Adrian Georgescu
 '''priority'''::
683 55 Adrian Georgescu
 An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority)
684 55 Adrian Georgescu
 '''hold_supported'''::
685 55 Adrian Georgescu
 True if the stream supports hold
686 55 Adrian Georgescu
 '''on_hold_by_local'''::
687 55 Adrian Georgescu
 True if the stream is on hold by the local party
688 55 Adrian Georgescu
 '''on_hold_by_remote'''::
689 55 Adrian Georgescu
 True if the stream is on hold by the remote
690 55 Adrian Georgescu
 '''on_hold'''::
691 55 Adrian Georgescu
 True if either on_hold_by_local or on_hold_by_remote is true
692 55 Adrian Georgescu
693 55 Adrian Georgescu
=== Methods ===
694 55 Adrian Georgescu
695 55 Adrian Georgescu
 '''!__init!__'''(''self'', ''account'')::
696 55 Adrian Georgescu
 Initializes the generic stream instance.
697 55 Adrian Georgescu
 '''new_from_sdp'''(''cls'', ''account'', ''remote_sdp'', ''stream_index'')::
698 55 Adrian Georgescu
 '''get_local_media'''(''self'', ''for_offer'')::
699 55 Adrian Georgescu
 '''initialize'''(''self'', ''session'', ''direction'')::
700 55 Adrian Georgescu
 Initializes the stream 
701 55 Adrian Georgescu
 '''start'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
702 55 Adrian Georgescu
 Completes the stream related connection. [[BR]]
703 55 Adrian Georgescu
 When done, must fire StreamChatDidStart notification. 
704 55 Adrian Georgescu
 '''end'''(''self'')::
705 55 Adrian Georgescu
 Ends the stream.  When done, must fire StreamChatDidEnd notification. 
706 1 Adrian Georgescu
 '''validate_update'''(''self'', ''remote_sdp'', ''stream_index'')::
707 55 Adrian Georgescu
 '''update'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index'')::
708 58 Adrian Georgescu
 '''deactivate'''(''self'')::
709 55 Adrian Georgescu
 '''hold'''(''self'')::
710 55 Adrian Georgescu
 Puts the stream on hold if supported by the stream. Typically used by audio and video streams.
711 55 Adrian Georgescu
 '''unhold'''(''self'')::
712 55 Adrian Georgescu
 Takes the stream off hold.
713 55 Adrian Georgescu
714 55 Adrian Georgescu
=== Notifications ===
715 55 Adrian Georgescu
716 55 Adrian Georgescu
These notifications must be generated by all streams in order for the upper layer (SIP session) to perform the right decissions.
717 55 Adrian Georgescu
718 55 Adrian Georgescu
 '''MediaStreamDidInitialize'''::
719 55 Adrian Georgescu
 Sent when the {{{Stream}}} instance is initialized
720 55 Adrian Georgescu
 '''MediaStreamDidStart'''::
721 55 Adrian Georgescu
 Sent when the {{{Stream}}} instance has started.
722 55 Adrian Georgescu
 '''MediaStreamDidFail'''::
723 55 Adrian Georgescu
 Sent when the {{{Stream}}} instance has failed.
724 55 Adrian Georgescu
 '''MediaStreamWillEnd'''::
725 55 Adrian Georgescu
 Sent before the {{{Stream}}} instance will end.
726 55 Adrian Georgescu
 '''MediaStreamDidEnd'''::
727 55 Adrian Georgescu
 Sent when the {{{Stream}}} instance did ended.
728 55 Adrian Georgescu
729 55 Adrian Georgescu
== MediaStreamRegistry ==
730 55 Adrian Georgescu
731 55 Adrian Georgescu
The MediaStream registry is used to register streams that can be automatically dealt with by the SIP session layer.
732 55 Adrian Georgescu
733 55 Adrian Georgescu
There are several pre-built streams based on the '''iMediaStream''' API:
734 55 Adrian Georgescu
735 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.MSRPStreamBase}}}  - MSRP base stream, all MSRP derived streams inherit this
736 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.ChatStream}}} - Chat stream based on MSRP 
737 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.FileSelector}}} - Helper for selecting a file for FileTransferStream
738 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.FileTransferStream}}} - File Transfer stream based on MSRP 
739 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.VNCConnectionError}}} - Helper class for DesktopSharingStream
740 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.DesktopSharingHandlerBase}}}  - Helper class for DesktopSharingStream
741 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.InternalVNCViewerHandler}}} - Helper class for DesktopSharingStream
742 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.InternalVNCViewerHandler}}}  - Helper class for DesktopSharingStream
743 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.ExternalVNCViewerHandler}}}  - Helper class for DesktopSharingStream
744 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.ExternalVNCServerHandler}}}  - Helper class for DesktopSharingStream
745 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.DesktopSharingStream}}} -  Desktop Sharing stream based on VNC over MSRP 
746 55 Adrian Georgescu
 * {{{sipsimple.streams.msrp.NotificationProxyLogger}}} - Helper class for handling MSRP library logs
747 55 Adrian Georgescu
748 55 Adrian Georgescu
These classes are used internally by [wiki:SipMiddlewareApi#Session Session], which provides the necessary methods to access their features. The notifications posted by these classes are also handled internally by [wiki:SipMiddlewareApi#Session Session]. The notifications that are relevant to the user are then reposted by the Session instance. Refer to [wiki:SipMiddlewareApi#Session Session documentation] for details on the Session API. 
749 55 Adrian Georgescu
750 55 Adrian Georgescu
== AudioStream ==
751 55 Adrian Georgescu
752 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/rtp.py]
753 55 Adrian Georgescu
754 57 Adrian Georgescu
=== SDP Example ===
755 57 Adrian Georgescu
756 57 Adrian Georgescu
{{{
757 57 Adrian Georgescu
Content-Type: application/sdp
758 57 Adrian Georgescu
Content-Length:  1093
759 57 Adrian Georgescu
760 57 Adrian Georgescu
v=0
761 57 Adrian Georgescu
o=- 3467525278 3467525278 IN IP4 192.168.1.6
762 57 Adrian Georgescu
s=blink-0.10.7-beta
763 57 Adrian Georgescu
c=IN IP4 80.101.96.20
764 57 Adrian Georgescu
t=0 0
765 57 Adrian Georgescu
m=audio 55328 RTP/AVP 104 103 102 3 9 0 8 101
766 57 Adrian Georgescu
a=rtcp:55329 IN IP4 80.101.96.20
767 57 Adrian Georgescu
a=rtpmap:104 speex/32000
768 57 Adrian Georgescu
a=rtpmap:103 speex/16000
769 57 Adrian Georgescu
a=rtpmap:102 speex/8000
770 57 Adrian Georgescu
a=rtpmap:3 GSM/8000
771 57 Adrian Georgescu
a=rtpmap:9 G722/8000
772 57 Adrian Georgescu
a=rtpmap:0 PCMU/8000
773 57 Adrian Georgescu
a=rtpmap:8 PCMA/8000
774 57 Adrian Georgescu
a=rtpmap:101 telephone-event/8000
775 57 Adrian Georgescu
a=fmtp:101 0-15
776 57 Adrian Georgescu
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:esI6DbLY1+Aceu0JNswN9Z10DcFx5cZwqJcu91jb
777 57 Adrian Georgescu
a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:SHuEMm1BYJqOF4udKl73EaCwnsI57pO86bYKsg70
778 57 Adrian Georgescu
a=ice-ufrag:2701ed80
779 57 Adrian Georgescu
a=ice-pwd:6f8f8281
780 57 Adrian Georgescu
a=candidate:S 1 UDP 31 80.101.96.20 55328 typ srflx raddr 192.168.1.6 rport 55328
781 57 Adrian Georgescu
a=candidate:H 1 UDP 23 192.168.1.6 55328 typ host
782 57 Adrian Georgescu
a=candidate:H 1 UDP 23 10.211.55.2 55328 typ host
783 57 Adrian Georgescu
a=candidate:H 1 UDP 23 10.37.129.2 55328 typ host
784 57 Adrian Georgescu
a=candidate:S 2 UDP 30 80.101.96.20 55329 typ srflx raddr 192.168.1.6 rport 55329
785 57 Adrian Georgescu
a=candidate:H 2 UDP 22 192.168.1.6 55329 typ host
786 57 Adrian Georgescu
a=candidate:H 2 UDP 22 10.211.55.2 55329 typ host
787 57 Adrian Georgescu
a=candidate:H 2 UDP 22 10.37.129.2 55329 typ host
788 57 Adrian Georgescu
a=sendrecv
789 57 Adrian Georgescu
}}}
790 57 Adrian Georgescu
791 55 Adrian Georgescu
=== Atributes ===
792 55 Adrian Georgescu
793 55 Adrian Georgescu
 '''recording_file_name''' (class attribute)::
794 55 Adrian Georgescu
 '''sample_rate''' (class attribute)::
795 55 Adrian Georgescu
 '''local_rtp_address''' (class attribute)::
796 55 Adrian Georgescu
 '''local_rtp_port''' (class attribute)::
797 55 Adrian Georgescu
 '''remote_rtp_address''' (class attribute)::
798 55 Adrian Georgescu
 '''remote_rtp_port''' (class attribute)::
799 55 Adrian Georgescu
 '''srtp_active''' (class attribute)::
800 1 Adrian Georgescu
 '''statistics''' (class attribute)::
801 1 Adrian Georgescu
802 58 Adrian Georgescu
=== Methods ===
803 58 Adrian Georgescu
804 58 Adrian Georgescu
 '''send_dtmf'''(''digit'')::
805 58 Adrian Georgescu
 '''start_recording'''(''file_name=None'', ''separate=False'')::
806 58 Adrian Georgescu
 '''stop_recording'''()::
807 58 Adrian Georgescu
 
808 55 Adrian Georgescu
=== Notifications ===
809 55 Adrian Georgescu
810 55 Adrian Georgescu
 '''AudioStreamDidChangeHoldState'''::
811 55 Adrian Georgescu
 '''AudioStreamDidStartRecordingAudio'''::
812 55 Adrian Georgescu
 '''AudioStreamDidStopRecordingAudio'''::
813 55 Adrian Georgescu
 '''AudioStreamGotDTMF'''::
814 55 Adrian Georgescu
 '''AudioStreamWillStartRecordingAudio''::
815 55 Adrian Georgescu
 '''AudioStreamWillStopRecordingAudio'''::
816 55 Adrian Georgescu
 
817 55 Adrian Georgescu
== MSRPStreamBase ==
818 55 Adrian Georgescu
819 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
820 55 Adrian Georgescu
821 55 Adrian Georgescu
=== Atributes ===
822 55 Adrian Georgescu
823 55 Adrian Georgescu
 '''media_type'''::
824 55 Adrian Georgescu
 '''accept_types'''::
825 55 Adrian Georgescu
 '''accept_wrapped_types'''::
826 55 Adrian Georgescu
 '''use_msrp_session'''::
827 55 Adrian Georgescu
828 55 Adrian Georgescu
=== Notifications ===
829 55 Adrian Georgescu
830 55 Adrian Georgescu
 '''MSRPLibraryLog'''::
831 55 Adrian Georgescu
 '''MSRPTransportTrace'''::
832 55 Adrian Georgescu
833 55 Adrian Georgescu
== ChatStream ==
834 55 Adrian Georgescu
835 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
836 55 Adrian Georgescu
837 55 Adrian Georgescu
{{{sipsimple.streams.msrp.ChatStream}}} implements Instant Messaging (IM) over MSRP for the [wiki:SipMiddlewareApi middleware]. This class performs the following functions:
838 55 Adrian Georgescu
839 55 Adrian Georgescu
 * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types
840 55 Adrian Georgescu
 * unwraps incoming Message/CPIM messages; for each incoming message, {{{ChatStreamGotMessage}}} is posted
841 55 Adrian Georgescu
 * plays notification sounds on received/sent message
842 55 Adrian Georgescu
 * reacts to and composes iscomposing payloads
843 55 Adrian Georgescu
844 57 Adrian Georgescu
=== SDP Example ===
845 57 Adrian Georgescu
846 57 Adrian Georgescu
{{{
847 57 Adrian Georgescu
Content-Type: application/sdp
848 57 Adrian Georgescu
Content-Length:   283
849 57 Adrian Georgescu
850 57 Adrian Georgescu
v=0
851 57 Adrian Georgescu
o=- 3467525214 3467525214 IN IP4 192.168.1.6
852 57 Adrian Georgescu
s=blink-0.10.7-beta
853 57 Adrian Georgescu
c=IN IP4 192.168.1.6
854 57 Adrian Georgescu
t=0 0
855 57 Adrian Georgescu
m=message 2855 TCP/TLS/MSRP *
856 57 Adrian Georgescu
a=path:msrps://192.168.1.6:2855/ca7940f12ddef14c3c32;tcp
857 57 Adrian Georgescu
a=accept-types:message/cpim text/* application/im-iscomposing+xml
858 57 Adrian Georgescu
a=accept-wrapped-types:*
859 57 Adrian Georgescu
}}}
860 57 Adrian Georgescu
861 55 Adrian Georgescu
=== Methods ===
862 55 Adrian Georgescu
863 55 Adrian Georgescu
 '''!__init!__'''(''self'', ''account'', ''direction'')::
864 55 Adrian Georgescu
 Initializes the ChatStream instance.
865 55 Adrian Georgescu
866 55 Adrian Georgescu
 '''initialize'''(''self'')::
867 55 Adrian Georgescu
 Initializes the MSRP connection; connects to the relay if necessary. When done, fires ChatStreamDidInitialize (with 'sdpmedia' attribute, containing the appropriate 'SDPMedia' instance)
868 55 Adrian Georgescu
869 55 Adrian Georgescu
 '''start'''(''self'', ''remote_media'')::
870 55 Adrian Georgescu
 Completes the MSRP connection establishment; this includes binding the MSRP session. [[BR]]
871 55 Adrian Georgescu
 When done, fires MSRPChatDidStart notification. At this point each incoming message is posted as a {{{ChatStreamGotMessage}}} notification
872 55 Adrian Georgescu
873 55 Adrian Georgescu
 '''end'''(''self'')::
874 55 Adrian Georgescu
 Closes the MSRP connection or cleans up after initialize(), whatever is necessary. [[BR]]
875 55 Adrian Georgescu
 Before doing anything posts {{{ChatStreamWillEnd}}} notification.
876 55 Adrian Georgescu
 When done, posts {{{ChatStreamDidEnd}}} notification. If there was an error, posts {{{ChatStreamDidFail}}} notification. 
877 55 Adrian Georgescu
 {{{ChatStreamDidEnd}}} notification will be posted anyway.
878 55 Adrian Georgescu
879 55 Adrian Georgescu
 '''send_message'''(''self'', ''content'', ''content_type''={{{'text/plain'}}}, ''to_uri''={{{None}}}, ''dt''={{{None}}})::
880 55 Adrian Georgescu
 Sends IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be
881 55 Adrian Georgescu
 queued until ChatStreamDidStart notification.
882 55 Adrian Georgescu
883 55 Adrian Georgescu
 Returns the generated MSRP chunk (MSRPData instance); to get Message-ID use its 'message_id' attribute.
884 55 Adrian Georgescu
885 55 Adrian Georgescu
 ''content'' str:[[BR]]
886 55 Adrian Georgescu
 content of the message
887 55 Adrian Georgescu
888 55 Adrian Georgescu
 ''to_uri'' SIPURI:[[BR]]
889 55 Adrian Georgescu
 "To" header of CPIM wrapper; use to override the default supplied to {{{__init__}}}.
890 55 Adrian Georgescu
 May only differ from the one supplied in __init__ if the remote party supports private messages. If it does not, {{{MSRPChatError}}} will be raised;
891 55 Adrian Georgescu
892 55 Adrian Georgescu
 ''content_type'' str:[[BR]]
893 55 Adrian Georgescu
 Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case);
894 55 Adrian Georgescu
 otherwise, Content-Type of MSRP message.
895 55 Adrian Georgescu
896 55 Adrian Georgescu
 These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses:
897 55 Adrian Georgescu
{{{
898 55 Adrian Georgescu
Failure-Report: partial
899 55 Adrian Georgescu
Success-Report: yes
900 55 Adrian Georgescu
}}}
901 55 Adrian Georgescu
902 55 Adrian Georgescu
 '''send_composing_indication'''(''self'', ''state'', ''refresh'', ''last_active=None'', ''remote_identity=None'')::
903 55 Adrian Georgescu
 Send is composing notification.
904 55 Adrian Georgescu
905 55 Adrian Georgescu
=== Notifications ===
906 55 Adrian Georgescu
907 55 Adrian Georgescu
To communicate with the middleware, MSRPChat class uses the notification system provided by the [http://pypi.python.org/pypi/python-application python-application] package.
908 55 Adrian Georgescu
909 55 Adrian Georgescu
 '''ChatStreamGotMessage'''::
910 55 Adrian Georgescu
 Sent whenever a new incoming message is received,
911 55 Adrian Georgescu
  [[BR]]''content'':[[BR]]
912 55 Adrian Georgescu
  The string that the remote user has typed.
913 55 Adrian Georgescu
  [[BR]]''content_type'':[[BR]]
914 55 Adrian Georgescu
  Content-Type of the user message.
915 55 Adrian Georgescu
  [[BR]]''cpim_headers'':[[BR]]
916 55 Adrian Georgescu
  A dictionary of CPIM headers. (Empty dictionary if no CPIM wrapper was used).
917 55 Adrian Georgescu
  [[BR]]''message'':[[BR]]
918 55 Adrian Georgescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the chunk.
919 55 Adrian Georgescu
 '''ChatStreamDidDeliverMessage'''::
920 55 Adrian Georgescu
 Sent when a successful report is received.
921 55 Adrian Georgescu
  [[BR]]''message_id'':[[BR]]
922 55 Adrian Georgescu
  Text identifier of the message.
923 55 Adrian Georgescu
  [[BR]]''code'':[[BR]]
924 55 Adrian Georgescu
  Integer result code.
925 55 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
926 55 Adrian Georgescu
  Text comment.
927 55 Adrian Georgescu
  [[BR]]''message'':[[BR]]
928 55 Adrian Georgescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
929 55 Adrian Georgescu
 '''ChatStreamDidNotDeliverMessage'''::
930 55 Adrian Georgescu
 Sent when a failure report of failure transaction response is received.
931 55 Adrian Georgescu
  [[BR]]''message_id'':[[BR]]
932 55 Adrian Georgescu
  Text identifier of the message.
933 55 Adrian Georgescu
  [[BR]]''code'':[[BR]]
934 55 Adrian Georgescu
  Integer result code.
935 55 Adrian Georgescu
  [[BR]]''reason'':[[BR]]
936 55 Adrian Georgescu
  Text comment.
937 55 Adrian Georgescu
  [[BR]]''message'':[[BR]]
938 55 Adrian Georgescu
  A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report.
939 55 Adrian Georgescu
 '''ChatStreamDidSendMessage'''::
940 55 Adrian Georgescu
 Sent when an outgoing message has been sent.
941 55 Adrian Georgescu
 '''ChatStreamGotComposingIndication'''::
942 55 Adrian Georgescu
 Sent when a iscomposing payload is received.
943 55 Adrian Georgescu
944 55 Adrian Georgescu
945 55 Adrian Georgescu
== FileTransferStream ==
946 55 Adrian Georgescu
947 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
948 55 Adrian Georgescu
949 57 Adrian Georgescu
=== SDP Example ===
950 57 Adrian Georgescu
951 57 Adrian Georgescu
{{{
952 57 Adrian Georgescu
Content-Type: application/sdp
953 57 Adrian Georgescu
Content-Length:   383
954 57 Adrian Georgescu
955 57 Adrian Georgescu
v=0
956 57 Adrian Georgescu
o=- 3467525166 3467525166 IN IP4 192.168.1.6
957 57 Adrian Georgescu
s=blink-0.10.7-beta
958 57 Adrian Georgescu
c=IN IP4 192.168.1.6
959 57 Adrian Georgescu
t=0 0
960 57 Adrian Georgescu
m=message 2855 TCP/TLS/MSRP *
961 57 Adrian Georgescu
a=path:msrps://192.168.1.6:2855/e593357dc9abe90754bd;tcp
962 57 Adrian Georgescu
a=sendonly
963 57 Adrian Georgescu
a=accept-types:*
964 57 Adrian Georgescu
a=accept-wrapped-types:*
965 57 Adrian Georgescu
a=file-selector:name:"reblink.pdf" type:com.adobe.pdf size:268759 hash:sha1:60:A1:BE:8D:71:DB:E3:8E:84:C9:2C:62:9E:F2:99:78:9D:68:79:F6
966 57 Adrian Georgescu
}}}
967 57 Adrian Georgescu
968 55 Adrian Georgescu
=== Methods ===
969 55 Adrian Georgescu
=== Notifications ===
970 55 Adrian Georgescu
971 55 Adrian Georgescu
 '''FileTransferStreamDidDeliverChunk'''::
972 55 Adrian Georgescu
 '''FileTransferStreamDidFinish'''::
973 55 Adrian Georgescu
 '''FileTransferStreamDidNotDeliverChunk'''::
974 55 Adrian Georgescu
 '''FileTransferStreamGotChunk'''::
975 55 Adrian Georgescu
976 55 Adrian Georgescu
== DesktopSharingStream ==
977 55 Adrian Georgescu
978 55 Adrian Georgescu
Implemented in [browser:sipsimple/streams/msrp.py]
979 56 Adrian Georgescu
980 56 Adrian Georgescu
There is no standard defining this usage but is fairly easy to implement in clients that already support MSRP. To traverse a NAT-ed router, a [http://msrprelay.org MSRP relay] configured for the called party domain is needed. Below is an example of the Session Description Protocol used for establishing a Desktop sharing session. 
981 1 Adrian Georgescu
982 57 Adrian Georgescu
=== SDP Example ===
983 56 Adrian Georgescu
984 56 Adrian Georgescu
{{{
985 56 Adrian Georgescu
m=application 2855 TCP/TLS/MSRP *
986 56 Adrian Georgescu
a=path:msrps://10.0.1.19:2855/b599b22d1b1d6a3324c8;tcp
987 56 Adrian Georgescu
a=accept-types:application/x-rfb
988 56 Adrian Georgescu
a=setup:active
989 56 Adrian Georgescu
}}}
990 56 Adrian Georgescu
991 56 Adrian Georgescu
992 55 Adrian Georgescu
=== Methods ===
993 55 Adrian Georgescu
994 55 Adrian Georgescu
=== Notifications ===
995 55 Adrian Georgescu
996 55 Adrian Georgescu
 '''DesktopSharingHandlerDidFail'''::
997 55 Adrian Georgescu
 '''DesktopSharingStreamGotData'''::