SipMiddlewareApi » History » Version 140
Anonymous, 04/21/2011 01:49 PM
1 | 1 | Adrian Georgescu | = Middleware API = |
---|---|---|---|
2 | |||
3 | 132 | Adrian Georgescu | [[TOC(SipMiddlewareApi, SipConfigurationAPI, SipCoreApiDocumentation, SipMSRPApi, ThreadingApi, depth=3)]] |
4 | 104 | Adrian Georgescu | |
5 | 102 | Adrian Georgescu | This chapter describes the ''Middleware API'' for SIP SIMPLE client SDK that can be used for developing a user interface (e.g. Graphical User Interface). The Middleware provides a ''non-blocking'' API that communicates with the user interface asynchronously by using ''Notifications''. For its configuration, the Middleware uses the [wiki:SipConfigurationAPI Configuration API]. |
6 | 1 | Adrian Georgescu | |
7 | 101 | Adrian Georgescu | [[Image(sipsimple-middleware.png, align=center, width=700)]] |
8 | 1 | Adrian Georgescu | |
9 | == SIPApplication == |
||
10 | |||
11 | 62 | Luci Stanescu | Implemented in [browser:sipsimple/application.py] |
12 | 1 | Adrian Georgescu | |
13 | 62 | Luci Stanescu | Implements a high-level application responsable for starting and stopping various sub-systems required to implement a fully featured SIP User Agent application. The SIPApplication class is a Singleton and can be instantiated from any part of the code, obtaining a reference to the same object. The SIPApplication takes care of initializing the following components: |
14 | * the twisted thread |
||
15 | 93 | Adrian Georgescu | * the configuration system, via the [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] |
16 | 62 | Luci Stanescu | * the core [wiki:SipCoreApiDocumentation#Engine Engine] using the settings in the configuration |
17 | * the [wiki:SipMiddlewareApi#AccountManager AccountManager], using the accounts in the configuration |
||
18 | 63 | Luci Stanescu | * the [wiki:SipMiddlewareApi#SessionManager SessionManager], in order to handle incoming sessions |
19 | 62 | Luci Stanescu | * two [wiki:SipMiddlewareApi#AudioBridge AudioBridges], using the settings in the configuration |
20 | 1 | Adrian Georgescu | |
21 | 62 | Luci Stanescu | The attributes in this class can be set and accessed on both this class and its subclasses, as they are implemented using descriptors which keep single value for each attribute, irrespective of the class from which that attribute is set/accessed. Usually, all attributes should be considered read-only. |
22 | 1 | Adrian Georgescu | |
23 | 95 | Adrian Georgescu | ==== methods ==== |
24 | 62 | Luci Stanescu | |
25 | 94 | Adrian Georgescu | |
26 | 62 | Luci Stanescu | '''!__init!__'''(''self''):: |
27 | Instantiates a new SIPApplication. |
||
28 | 94 | Adrian Georgescu | |
29 | 62 | Luci Stanescu | '''start'''(''self'', '''config_backend'''):: |
30 | Starts the {{{SIPApplication}}} which initializes all the components in the correct order. The {{{config_backend}}} is used to start the {{{ConfigurationManager}}}. If any error occurs with loading the configuration, the exception raised by the {{{ConfigurationManager}}} is propagated by this method and {{{SIPApplication}}} can be started again. After this, any fatal errors will result in the SIPApplication being stopped and unusable, which means the whole application will need to stop. This method returns as soon as the twisted thread has been started, which means the application must wait for the {{{SIPApplicationDidStart}}} notification in order to know that the application started. |
||
31 | 94 | Adrian Georgescu | |
32 | 62 | Luci Stanescu | '''stop'''(''self''):: |
33 | Stop all the components started by the SIPApplication. This method returns immediately, but a {{{SIPApplicationDidEnd}}} notification is sent when all the components have been stopped. |
||
34 | |||
35 | 95 | Adrian Georgescu | ==== attributes ==== |
36 | 1 | Adrian Georgescu | |
37 | 94 | Adrian Georgescu | |
38 | 62 | Luci Stanescu | '''running''':: |
39 | {{{True}}} if the SIPApplication is running (it has been started and it has not been told to stop), {{{False}}} otherwise. |
||
40 | 94 | Adrian Georgescu | |
41 | |||
42 | 62 | Luci Stanescu | '''alert_audio_mixer''':: |
43 | The {{{AudioMixer}}} object created on the alert audio device as defined by the configuration (by SIPSimpleSettings.audio.alert_device). |
||
44 | 94 | Adrian Georgescu | |
45 | 62 | Luci Stanescu | '''alert_audio_bridge''':: |
46 | An {{{AudioBridge}}} where {{{IAudioPort}}} objects can be added to playback sound to the alert device. |
||
47 | 94 | Adrian Georgescu | |
48 | 62 | Luci Stanescu | '''alert_audio_device''':: |
49 | An {{{AudioDevice}}} which corresponds to the alert device as defined by the configuration. This will always be part of the alert_audio_bridge. |
||
50 | 94 | Adrian Georgescu | |
51 | 62 | Luci Stanescu | '''voice_audio_mixer''':: |
52 | The {{{AudioMixer}}} object created on the voice audio device as defined by the configuration (by SIPSimpleSettings.audio.input_device and SIPSimpleSettings.audio.output_device). |
||
53 | 94 | Adrian Georgescu | |
54 | 62 | Luci Stanescu | '''voice_audio_bridge''':: |
55 | An {{{AudioBridge}}} where {{{IAudioPort}}} objects can be added to playback sound to the output device or record sound from the input device. |
||
56 | 94 | Adrian Georgescu | |
57 | 62 | Luci Stanescu | '''voice_audio_device''':: |
58 | An {{{AudioDevice}}} which corresponds to the voice device as defined by the configuration. This will always be part of the voice_audio_bridge. |
||
59 | 1 | Adrian Georgescu | |
60 | 95 | Adrian Georgescu | ==== notifications ==== |
61 | 62 | Luci Stanescu | |
62 | 94 | Adrian Georgescu | |
63 | 62 | Luci Stanescu | '''SIPApplicationWillStart''':: |
64 | This notification is sent just after the configuration has been loaded and the twisted thread started, but before any other components have been initialized. |
||
65 | [[BR]]timestamp:[[BR]] |
||
66 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
67 | 94 | Adrian Georgescu | |
68 | 62 | Luci Stanescu | '''SIPApplicationDidStart''':: |
69 | This notification is sent when all the components have been initialized. Note: it doesn't mean that all components have succeeded, for example, the account might not have registered by this time, but the registration process will have started. |
||
70 | [[BR]]timestamp:[[BR]] |
||
71 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
72 | 94 | Adrian Georgescu | |
73 | 62 | Luci Stanescu | '''SIPApplicationWillEnd''':: |
74 | This notification is sent as soon as the {{{stop()}}} method has been called. |
||
75 | [[BR]]timestamp:[[BR]] |
||
76 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
77 | 94 | Adrian Georgescu | |
78 | 62 | Luci Stanescu | '''SIPApplicationDidEnd''':: |
79 | This notification is sent when all the components have been stopped. All components have been given reasonable time to shutdown gracefully, such as the account unregistering. However, because of factors outside the control of the middleware, such as network problems, some components might not have actually shutdown gracefully; this is needed because otherwise the SIPApplication could hang indefinitely (for example because the system is no longer connected to a network and it cannot be determined when it will be again). |
||
80 | [[BR]]timestamp:[[BR]] |
||
81 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
82 | 94 | Adrian Georgescu | |
83 | 62 | Luci Stanescu | '''SIPApplicationFailedToStartTLS''':: |
84 | This notification is sent when a problem arises with initializing the TLS transport. In this case, the Engine will be started without TLS support and this notification contains the error which identifies the cause for not being able to start the TLS transport. |
||
85 | [[BR]]timestamp:[[BR]] |
||
86 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
87 | [[BR]]error:[[BR]] |
||
88 | The exception raised by the Engine which identifies the cause for not being able to start the TLS transport. |
||
89 | 50 | Adrian Georgescu | |
90 | 1 | Adrian Georgescu | |
91 | 63 | Luci Stanescu | == SIP Sessions == |
92 | 1 | Adrian Georgescu | |
93 | 63 | Luci Stanescu | SIP sessions are supported by the {{{sipsimple.session.Session}}} class and independent stream classes, which need to implement the {{{sipsimple.streams.IMediaStream}}} interface. The {{{Session}}} class takes care of the signalling, while the streams offer the actual media support which is negotiated by the {{{Session}}}. The streams which are implemented in the SIP SIMPLE middleware are provided in modules within the {{{sipsimple.streams}}} package, but they are accessible for import directly from {{{sipsimple.streams}}}. Currently, the middleware implements two types of streams, one for RTP data, with a concrete implementation in the {{{AudioStream}}} class, and one for MSRP sessions, with concrete implementations in the {{{ChatStream}}}, {{{FileTransferStream}}} and {{{DesktopSharingStream}}} classes. However, the application can provide its own stream implementation, provided they respect the {{{IMediaStream}}} interface. |
94 | |||
95 | 74 | Luci Stanescu | The {{{sipsimple.streams}}} module also provides a mechanism for automatically registering media streams in order for them to be used for incoming sessions. This is explained in more detail in [wiki:SipMiddlewareApi#MediaStreamRegistry MediaStreamRegistry]. |
96 | 65 | Luci Stanescu | |
97 | 91 | Adrian Georgescu | |
98 | === SessionManager === |
||
99 | |||
100 | Implemented in [browser:sipsimple/session.py] |
||
101 | |||
102 | The {{{sipsimple.session.SessionManager}}} class is a singleton, which acts as the central aggregation point for sessions within the middleware. |
||
103 | Although it is mainly used internally, the application can use it to query information about all active sessions. |
||
104 | 115 | Luci Stanescu | The SessionManager is implemented as a singleton, meaning that only one instance of this class exists within the middleware. The SessionManager is started by the SIPApplication and takes care of handling incoming sessions and closing all sessions when SIPApplication is stopped. |
105 | 91 | Adrian Georgescu | |
106 | ==== attributes ==== |
||
107 | |||
108 | 94 | Adrian Georgescu | |
109 | 91 | Adrian Georgescu | '''sessions''':: |
110 | 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. |
||
111 | |||
112 | ==== methods ==== |
||
113 | |||
114 | 94 | Adrian Georgescu | |
115 | 91 | Adrian Georgescu | '''!__init!__'''(''self''):: |
116 | Instantiate a new {{{SessionManager}}} object. |
||
117 | |||
118 | 94 | Adrian Georgescu | |
119 | 1 | Adrian Georgescu | '''start'''(''self''):: |
120 | 115 | Luci Stanescu | Start the {{{SessionManager}}} in order to be able to handle incoming sessions. This method is called automatically when SIPApplication is started. The application should not call this method directly. |
121 | |||
122 | '''stop'''(''self''):: |
||
123 | End all connected sessions. This method is called automatically when SIPApplication is stopped. The application should not call this method directly. |
||
124 | 91 | Adrian Georgescu | |
125 | 44 | Adrian Georgescu | === Session === |
126 | 1 | Adrian Georgescu | |
127 | Implemented in [browser:sipsimple/session.py] |
||
128 | 26 | Luci Stanescu | |
129 | 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. |
130 | |||
131 | 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. |
||
132 | 2 | Adrian Georgescu | State changes are triggered by methods called on the object by the application or by received network events. |
133 | 1 | Adrian Georgescu | These states and their transitions are represented in the following diagram: |
134 | 63 | Luci Stanescu | |
135 | 105 | Adrian Georgescu | [[Image(/raw-attachment/wiki/SipCoreApiDocumentation/sipsimple-core-invite-state-machine.png)]] |
136 | |||
137 | 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 set of notifications is also emitted, which provide all the necessary information to the application. |
138 | 63 | Luci Stanescu | |
139 | The {{{Session}}} is completely independent of the streams it contains, which need to be implementations of the {{{sipsimple.streams.IMediaStream}}} interface. This interface provides the API by which the {{{Session}}} communicates with the streams. This API should not be used by the application, unless it also provides stream implementations or a SIP INVITE session implementation. |
||
140 | |||
141 | ==== methods ==== |
||
142 | |||
143 | 94 | Adrian Georgescu | |
144 | 63 | Luci Stanescu | '''!__init!__'''(''self'', '''account'''):: |
145 | Creates a new {{{Session}}} object in the {{{None}}} state. |
||
146 | [[BR]]''account'':[[BR]] |
||
147 | The local account to be associated with this {{{Session}}}. |
||
148 | 94 | Adrian Georgescu | |
149 | 139 | Adrian Georgescu | '''connect'''(''self'', '''to_header''', '''routes''', '''streams''', '''is_focus'''={{{False}}}, '''subject'''={{{None}}}):: |
150 | 63 | Luci Stanescu | Will set up the {{{Session}}} as outbound and propose the new session to the specified remote party and move the state machine to the {{{outgoing}}} state. |
151 | Before contacting the remote party, a {{{SIPSessionNewOutgoing}}} notification will be emitted. |
||
152 | If there is a failure or the remote party rejected the offer, a {{{SIPSessionDidFail}}} notification will be sent. |
||
153 | Any time a ringing indication is received from the remote party, a {{{SIPSessionGotRingIndication}}} notification is sent. |
||
154 | If the remote party accepted the session, a {{{SIPSessionWillStart}}} notification will be sent, followed by a {{{SIPSessionDidStart}}} notification when the session is actually established. |
||
155 | This method may only be called while in the {{{None}}} state. |
||
156 | [[BR]]''to_header'':[[BR]] |
||
157 | A {{{sipsimple.core.ToHeader}}} object representing the remote identity to initiate the session to. |
||
158 | [[BR]]''routes'':[[BR]] |
||
159 | An iterable of {{{sipsimple.util.Route}}} objects, specifying the IP, port and transport to the outbound proxy. |
||
160 | These routes will be tried in order, until one of them succeeds. |
||
161 | [[BR]]''streams'':[[BR]] |
||
162 | 1 | Adrian Georgescu | A list of stream objects which will be offered to the remote endpoint. |
163 | 139 | Adrian Georgescu | [[BR]]''is_focus'':[[BR]] |
164 | Boolean flag indicating if the {{{isfocus}}} parameter should be added to the {{{Contact}}} header according to RFC 4579. |
||
165 | [[BR]]''subject'':[[BR]] |
||
166 | Session subject. If not None a {{{Subject}}} header will be added with the specified value. |
||
167 | 94 | Adrian Georgescu | |
168 | 63 | Luci Stanescu | '''send_ring_indication'''(''self''):: |
169 | Sends a 180 provisional response in the case of an incoming session. |
||
170 | 94 | Adrian Georgescu | |
171 | 63 | Luci Stanescu | '''accept'''(''self'', '''streams'''):: |
172 | Calling this methods will accept an incoming session and move the state machine to the {{{accepting}}} state. |
||
173 | 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. |
||
174 | After this method is called, {{{SIPSessionWillStart}}} followed by {{{SIPSessionDidStart}}} will be emitted, or {{{SIPSessionDidFail}}} on an error. |
||
175 | This method may only be called while in the {{{incoming}}} state. |
||
176 | [[BR]]''streams'':[[BR]] |
||
177 | A list of streams which needs to be a subset of the proposed streams which indicates which streams are to be accepted. All the other proposed streams will be rejected. |
||
178 | 94 | Adrian Georgescu | |
179 | 63 | Luci Stanescu | '''reject'''(''self'', '''code'''={{{603}}}, '''reason'''={{{None}}}):: |
180 | 114 | Adrian Georgescu | Reject an incoming session and move it to the {{{terminating}}} state, which eventually leads to the {{{terminated}}} state. |
181 | 63 | Luci Stanescu | Calling this method will cause the {{{Session}}} object to emit a {{{SIPSessionDidFail}}} notification once the session has been rejected. |
182 | This method may only be called while in the {{{incoming}}} state. |
||
183 | [[BR]]''code'':[[BR]] |
||
184 | An integer which represents the SIP status code in the response which is to be sent. Usually, this is either 486 (Busy) or 603 (Decline/Busy Everywhere). |
||
185 | [[BR]]''reason'':[[BR]] |
||
186 | The string which is to be sent as the SIP status reason in the response, or None if PJSIP's default reason for the specified code is to be sent. |
||
187 | 94 | Adrian Georgescu | |
188 | 63 | Luci Stanescu | '''accept_proposal'''(''self'', '''streams'''):: |
189 | When the remote party proposes to add some new streams, signaled by the {{{SIPSessionGotProposal}}} notification, the application can use this method to accept the stream(s) being proposed. |
||
190 | After calling this method a {{{SIPSessionGotAcceptProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a {{{SIPSessionHadProposalFailure}}} notification is sent and a rejection is sent to the remote party. As with any action which causes the streams in the session to change, a {{{SIPSessionDidRenegotiateStreams}}} notification is also sent. |
||
191 | This method may only be called while in the {{{received_proposal}}} state. |
||
192 | [[BR]]''streams'':[[BR]] |
||
193 | A list of streams which needs to be a subset of the proposed streams which indicates which streams are to be accepted. All the other proposed streams will be rejected. |
||
194 | 94 | Adrian Georgescu | |
195 | 63 | Luci Stanescu | '''reject_proposal'''(''self'', '''code'''={{{488}}}, '''reason'''={{{None}}}):: |
196 | When the remote party proposes new streams that the application does not want to accept, this method can be used to reject the proposal, after which a {{{SIPSessionGotRejectProposal}}} or {{{SIPSessionHadProposalFailure}}} notification is sent. |
||
197 | This method may only be called while in the {{{received_proposal}}} state. |
||
198 | [[BR]]''code'':[[BR]] |
||
199 | An integer which represents the SIP status code in the response which is to be sent. Usually, this is 488 (Not Acceptable Here). |
||
200 | [[BR]]''reason'':[[BR]] |
||
201 | The string which is to be sent as the SIP status reason in the response, or None if PJSIP's default reason for the specified code is to be sent. |
||
202 | 94 | Adrian Georgescu | |
203 | 63 | Luci Stanescu | '''add_stream'''(''self'', '''stream'''):: |
204 | Proposes a new stream to the remote party. |
||
205 | Calling this method will cause a {{{SIPSessionGotProposal}}} notification to be emitted. |
||
206 | After this, the state machine will move into the {{{sending_proposal}}} state until either a {{{SIPSessionGotAcceptProposal}}}, {{{SIPSessionGotRejectProposal}}} or {{{SIPSessionHadProposalFailure}}} notification is sent, informing the application if the remote party accepted the proposal. As with any action which causes the streams in the session to change, a {{{SIPSessionDidRenegotiateStreams}}} notification is also sent. |
||
207 | This method may only be called while in the {{{connected}}} state. |
||
208 | 94 | Adrian Georgescu | |
209 | 63 | Luci Stanescu | '''remove_stream'''(''self'', '''stream'''):: |
210 | Stop the stream and remove it from the session, informing the remote party of this. Although technically this is also done via an SDP negotiation which may fail, the stream will always get remove (if the remote party refuses the re-INVITE, the result will be that the remote party will have a different view of the active streams than the local party). |
||
211 | This method may only be called while in the {{{connected}}} state. |
||
212 | 94 | Adrian Georgescu | |
213 | 63 | Luci Stanescu | '''cancel_proposal'''(''self''):: |
214 | This method cancels a proposal of adding a stream to the session by sending a CANCEL request. A {{{SIPSessionGotRejectProposal}}} notification will be sent with code 487. |
||
215 | 94 | Adrian Georgescu | |
216 | 63 | Luci Stanescu | '''hold'''(''self''):: |
217 | Put the streams of the session which support the notion of hold on hold. |
||
218 | This will cause a {{{SIPSessionDidChangeHoldState}}} notification to be sent. |
||
219 | This method may be called in any state and will send the re-INVITE as soon as it is possible. |
||
220 | 94 | Adrian Georgescu | |
221 | 63 | Luci Stanescu | '''unhold'''(''self''):: |
222 | Take the streams of the session which support the notion of hold out of hold. |
||
223 | This will cause a {{{SIPSessionDidChangeHoldState}}} notification to be sent. |
||
224 | This method may be called in any state and will send teh re-INVITE as soon as it is possible. |
||
225 | 94 | Adrian Georgescu | |
226 | 63 | Luci Stanescu | '''end'''(''self''):: |
227 | This method may be called any time after the {{{Session}}} has started in order to terminate the session by sending a BYE request. |
||
228 | 1 | Adrian Georgescu | Right before termination a {{{SIPSessionWillEnd}}} notification is sent, after termination {{{SIPSessionDidEnd}}} is sent. |
229 | |||
230 | 64 | Luci Stanescu | ==== attributes ==== |
231 | 1 | Adrian Georgescu | |
232 | 94 | Adrian Georgescu | |
233 | 1 | Adrian Georgescu | '''state''':: |
234 | The state the object is currently in, being one of the states from the diagram above. |
||
235 | 94 | Adrian Georgescu | |
236 | 1 | Adrian Georgescu | '''account''':: |
237 | 19 | Ruud Klaver | The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object that the {{{Session}}} is associated with. |
238 | 1 | Adrian Georgescu | On an outbound session, this is the account the application specified on object instantiation. |
239 | 94 | Adrian Georgescu | |
240 | 1 | Adrian Georgescu | '''direction''':: |
241 | 32 | Adrian Georgescu | A string indicating the direction of the initial negotiation of the session. |
242 | 63 | Luci Stanescu | This can be either {{{None}}}, "incoming" or "outgoing". |
243 | 94 | Adrian Georgescu | |
244 | 63 | Luci Stanescu | '''transport''':: |
245 | 1 | Adrian Georgescu | A string representing the transport this {{{Session}}} is using: {{{"udp"}}}, {{{"tcp"}}} or {{{"tls"}}}. |
246 | 94 | Adrian Georgescu | |
247 | 1 | Adrian Georgescu | '''start_time''':: |
248 | The time the session started as a {{{datetime.datetime}}} object, or {{{None}}} if the session was not yet started. |
||
249 | 94 | Adrian Georgescu | |
250 | 1 | Adrian Georgescu | '''stop_time''':: |
251 | The time the session stopped as a {{{datetime.datetime}}} object, or {{{None}}} if the session has not yet terminated. |
||
252 | 94 | Adrian Georgescu | |
253 | 1 | Adrian Georgescu | '''on_hold''':: |
254 | Boolean indicating whether the session was put on hold, either by the local or the remote party. |
||
255 | 94 | Adrian Georgescu | |
256 | 1 | Adrian Georgescu | '''remote_user_agent''':: |
257 | A string indicating the remote user agent, if it provided one. |
||
258 | 63 | Luci Stanescu | Initially this will be {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never). |
259 | 94 | Adrian Georgescu | |
260 | 63 | Luci Stanescu | '''local_identity''':: |
261 | The {{{sipsimple.core.FrozenFromHeader}}} or {{{sipsimple.core.FrozenToHeader}}} identifying the local party, if the session is active, {{{None}}} otherwise. |
||
262 | 94 | Adrian Georgescu | |
263 | 63 | Luci Stanescu | '''remote_identity''':: |
264 | The {{{sipsimple.core.FrozenFromHeader}}} or {{{sipsimple.core.FrozenToHeader}}} identifying the remote party, if the session is active, {{{None}}} otherwise. |
||
265 | 94 | Adrian Georgescu | |
266 | 63 | Luci Stanescu | '''streams''':: |
267 | A list of the currently active streams in the {{{Session}}}. |
||
268 | 94 | Adrian Georgescu | |
269 | 63 | Luci Stanescu | '''proposed_streams''':: |
270 | 1 | Adrian Georgescu | A list of the currently proposed streams in the {{{Session}}}, or {{{None}}} if there is no proposal in progress. |
271 | |||
272 | 140 | Adrian Georgescu | '''conference''':: |
273 | A {{{ConferenceHandler}}} object instance (or Null). It can be later used to add/remove participants from a remote conference. |
||
274 | |||
275 | '''subject''':: |
||
276 | The session subject as a unicode object. |
||
277 | |||
278 | 64 | Luci Stanescu | ==== notifications ==== |
279 | 1 | Adrian Georgescu | |
280 | 94 | Adrian Georgescu | |
281 | 1 | Adrian Georgescu | '''SIPSessionNewIncoming''':: |
282 | 26 | Luci Stanescu | Will be sent when a new incoming {{{Session}}} is received. |
283 | 63 | Luci Stanescu | The application should listen for this notification to get informed of incoming sessions. |
284 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
285 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
286 | [[BR]]''streams'':[[BR]] |
||
287 | 63 | Luci Stanescu | A list of streams that were proposed by the remote party. |
288 | 94 | Adrian Georgescu | |
289 | 1 | Adrian Georgescu | '''SIPSessionNewOutgoing''':: |
290 | 138 | Adrian Georgescu | Will be sent when the application requests a new outgoing {{{Session}}}. |
291 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
292 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
293 | [[BR]]''streams'':[[BR]] |
||
294 | 63 | Luci Stanescu | A list of streams that were proposed to the remote party. |
295 | 94 | Adrian Georgescu | |
296 | 1 | Adrian Georgescu | '''SIPSessionGotRingIndication''':: |
297 | Will be sent when an outgoing {{{Session}}} receives an indication that a remote device is ringing. |
||
298 | [[BR]]''timestamp'':[[BR]] |
||
299 | 26 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
300 | 94 | Adrian Georgescu | |
301 | 63 | Luci Stanescu | '''SIPSessionGotProvisionalResponse''':: |
302 | Will be sent whenever the {{{Session}}} receives a provisional response as a result of sending a (re-)INVITE. |
||
303 | [[BR]]''timestamp'':[[BR]] |
||
304 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
305 | [[BR]]''code'':[[BR]] |
||
306 | The SIP status code received. |
||
307 | [[BR]]''reason'':[[BR]] |
||
308 | The SIP status reason received. |
||
309 | 94 | Adrian Georgescu | |
310 | 1 | Adrian Georgescu | '''SIPSessionWillStart''':: |
311 | Will be sent just before a {{{Session}}} completes negotiation. |
||
312 | In terms of SIP, this is sent after the final response to the {{{INVITE}}}, but before the {{{ACK}}}. |
||
313 | [[BR]]''timestamp'':[[BR]] |
||
314 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
315 | 94 | Adrian Georgescu | |
316 | 1 | Adrian Georgescu | '''SIPSessionDidStart''':: |
317 | 63 | Luci Stanescu | Will be sent when a {{{Session}}} completes negotiation and all the streams have started. |
318 | 26 | Luci Stanescu | In terms of SIP this is sent after the {{{ACK}}} was sent or received. |
319 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
320 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
321 | 63 | Luci Stanescu | [[BR]]''streams'':[[BR]] |
322 | The list of streams which now form the active streams of the {{{Session}}}. |
||
323 | 94 | Adrian Georgescu | |
324 | 1 | Adrian Georgescu | '''SIPSessionDidFail''':: |
325 | 63 | Luci Stanescu | This notification is sent whenever the session fails before it starts. |
326 | 5 | Redmine Admin | The failure reason is included in the data attributes. |
327 | 63 | Luci Stanescu | This notification is never followed by {{{SIPSessionDidEnd}}}. |
328 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
329 | 26 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
330 | 1 | Adrian Georgescu | [[BR]]''originator'':[[BR]] |
331 | 63 | Luci Stanescu | A string indicating the originator of the {{{Session}}}. This will either be "local" or "remote". |
332 | 1 | Adrian Georgescu | [[BR]]''code'':[[BR]] |
333 | The SIP error code of the failure. |
||
334 | [[BR]]''reason'':[[BR]] |
||
335 | 63 | Luci Stanescu | A SIP status reason. |
336 | [[BR]]''failure_reason'':[[BR]] |
||
337 | A string which represents the reason for the failure, such as {{{"user_request"}}}, {{{"missing ACK"}}}, {{{"SIP core error..."}}}. |
||
338 | 94 | Adrian Georgescu | |
339 | 1 | Adrian Georgescu | '''SIPSessionWillEnd''':: |
340 | 63 | Luci Stanescu | Will be sent just before terminating a {{{Session}}}. |
341 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
342 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
343 | 94 | Adrian Georgescu | |
344 | 1 | Adrian Georgescu | '''SIPSessionDidEnd''':: |
345 | 63 | Luci Stanescu | Will be sent always when a {{{Session}}} ends as a result of remote or local session termination. |
346 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
347 | 19 | Ruud Klaver | A {{{datetime.datetime}}} object indicating when the notification was sent. |
348 | [[BR]]''originator'':[[BR]] |
||
349 | 63 | Luci Stanescu | A string indicating who originated the termination. This will either be "local" or "remote". |
350 | [[BR]]''end_reason'':[[BR]] |
||
351 | A string representing the termination reason, such as {{{"user_request"}}}, {{{"SIP core error..."}}}. |
||
352 | 94 | Adrian Georgescu | |
353 | 63 | Luci Stanescu | '''SIPSessionDidChangeHoldState''':: |
354 | Will be sent when the session got put on hold or removed from hold, either by the local or the remote party. |
||
355 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
356 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
357 | [[BR]]''originator'':[[BR]] |
||
358 | A string indicating who originated the hold request, and consequently in which direction the session got put on hold. |
||
359 | 63 | Luci Stanescu | [[BR]]''on_hold'':[[BR]] |
360 | {{{True}}} if there is at least one stream which is on hold and {{{False}}} otherwise. |
||
361 | [[BR]]''partial'':[[BR]] |
||
362 | {{{True}}} if there is at least one stream which is on hold and one stream which supports hold but is not on hold and {{{False}}} otherwise. |
||
363 | 94 | Adrian Georgescu | |
364 | 63 | Luci Stanescu | '''SIPSessionGotProposal''':: |
365 | Will be sent when either the local or the remote party proposes to add streams to the session. |
||
366 | 26 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
367 | 23 | Ruud Klaver | A {{{datetime.datetime}}} object indicating when the notification was sent. |
368 | [[BR]]''originator'':[[BR]] |
||
369 | 63 | Luci Stanescu | The party that initiated the stream proposal, can be either "local" or "remote". |
370 | [[BR]]''streams'':[[BR]] |
||
371 | A list of streams that were proposed. |
||
372 | 94 | Adrian Georgescu | |
373 | 63 | Luci Stanescu | '''SIPSessionGotRejectProposal''':: |
374 | Will be sent when either the local or the remote party rejects a proposal to have streams added to the session. |
||
375 | 6 | Ruud Klaver | [[BR]]''timestamp'':[[BR]] |
376 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
377 | 63 | Luci Stanescu | [[BR]]''originator'':[[BR]] |
378 | The party that initiated the stream proposal, can be either "local" or "remote". |
||
379 | 6 | Ruud Klaver | [[BR]]''code'':[[BR]] |
380 | 63 | Luci Stanescu | The code with which the proposal was rejected. |
381 | 1 | Adrian Georgescu | [[BR]]''reason'':[[BR]] |
382 | 63 | Luci Stanescu | The reason for rejecting the stream proposal. |
383 | [[BR]]''streams'':[[BR]] |
||
384 | The list of streams which were rejected. |
||
385 | 94 | Adrian Georgescu | |
386 | 63 | Luci Stanescu | '''SIPSessionGotAcceptProposal''':: |
387 | Will be sent when either the local or the remote party accepts a proposal to have stream( added to the session. |
||
388 | 24 | Ruud Klaver | [[BR]]''timestamp'':[[BR]] |
389 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
390 | 63 | Luci Stanescu | [[BR]]''originator'':[[BR]] |
391 | The party that initiated the stream proposal, can be either "local" or "remote". |
||
392 | 1 | Adrian Georgescu | [[BR]]''streams'':[[BR]] |
393 | 63 | Luci Stanescu | The list of streams which were accepted. |
394 | 116 | Luci Stanescu | [[BR]]''proposed_streams'':[[BR]] |
395 | The list of streams which were originally proposed. |
||
396 | 94 | Adrian Georgescu | |
397 | 63 | Luci Stanescu | '''SIPSessionHadProposalFailure''':: |
398 | 24 | Ruud Klaver | Will be sent when a re-INVITE fails because of an internal reason (such as a stream not being able to start). |
399 | [[BR]]''timestamp'':[[BR]] |
||
400 | 63 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
401 | [[BR]]''failure_reason'':[[BR]] |
||
402 | The error which caused the proposal to fail. |
||
403 | [[BR]]''streams'':[[BR]] |
||
404 | 108 | Adrian Georgescu | The streams which were part of this proposal. |
405 | 94 | Adrian Georgescu | |
406 | 24 | Ruud Klaver | '''SIPSessionDidRenegotiateStreams''':: |
407 | 6 | Ruud Klaver | Will be sent when a media stream is either activated or deactivated. |
408 | 26 | Luci Stanescu | An application should listen to this notification in order to know when a media stream can be used. |
409 | 63 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
410 | 39 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
411 | [[BR]]''action'':[[BR]] |
||
412 | A string which is either {{{"add"}}} or {{{"remove"}}} which specifies what happened to the streams the notificaton referes to |
||
413 | 1 | Adrian Georgescu | [[BR]]''streams'':[[BR]] |
414 | 50 | Adrian Georgescu | A list with the streams which were added or removed. |
415 | 94 | Adrian Georgescu | |
416 | 39 | Luci Stanescu | '''SIPSessionDidProcessTransaction''':: |
417 | Will be sent whenever a SIP transaction is complete in order to provide low-level details of the progress of the INVITE dialog. |
||
418 | 64 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
419 | 39 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
420 | [[BR]]''originator'':[[BR]] |
||
421 | The initiator of the transaction, {{{"local"}}} or {{{"remote"}}}. |
||
422 | [[BR]]''method'':[[BR]] |
||
423 | 64 | Luci Stanescu | The method of the request. |
424 | 39 | Luci Stanescu | [[BR]]''code'':[[BR]] |
425 | The SIP status code of the response. |
||
426 | [[BR]]''reason'':[[BR]] |
||
427 | The SIP status reason of the response. |
||
428 | [[BR]]''ack_received'':[[BR]] |
||
429 | This attribute is only present for INVITE transactions and has one of the values {{{True}}}, {{{False}}} or {{{"unknown"}}}. The last value may occur then PJSIP does not let us know whether the ACK was received or not. |
||
430 | 1 | Adrian Georgescu | |
431 | 65 | Luci Stanescu | As an example for how to use the {{{Session}}} object, the following provides a basic Python program that initiates an outgoing SIP session request see [wiki:SipSessionExample Minimalist Session Example code]. |
432 | 39 | Luci Stanescu | |
433 | === IMediaStream === |
||
434 | 1 | Adrian Georgescu | |
435 | 65 | Luci Stanescu | Implemented in [browser:sipsimple/streams/__init__.py] |
436 | 1 | Adrian Georgescu | |
437 | 66 | Luci Stanescu | This interface describes the API which the {{{Session}}} uses to communicate with the streams. All streams used by the {{{Session}}} __must__ respect this interface. |
438 | 1 | Adrian Georgescu | |
439 | ==== methods ==== |
||
440 | 65 | Luci Stanescu | |
441 | 94 | Adrian Georgescu | |
442 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', ''account''):: |
443 | 65 | Luci Stanescu | Initializes the generic stream instance. |
444 | 94 | Adrian Georgescu | |
445 | 65 | Luci Stanescu | '''new_from_sdp'''(''cls'', ''account'', ''remote_sdp'', ''stream_index''):: |
446 | A classmethod which returns an instance of this stream implementation if the sdp is accepted by the stream or None otherwise. |
||
447 | [[BR]]account:[[BR]] |
||
448 | The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} object the session which this stream would be part of is associated with. |
||
449 | [[BR]]remote_sdp:[[BR]] |
||
450 | The {{{FrozenSDPSession}}} which was received by the remote offer. |
||
451 | 1 | Adrian Georgescu | [[BR]]stream_index:[[BR]] |
452 | 65 | Luci Stanescu | An integer representing the index within the list of media streams within the whole SDP which this stream would be instantiated for. |
453 | 94 | Adrian Georgescu | |
454 | 65 | Luci Stanescu | '''get_local_media'''(''self'', ''for_offer''):: |
455 | Return an {{{SDPMediaStream}}} which represents an offer for using this stream if {{{for_offer}}} is {{{True}}} and a response to an SDP proposal otherwise. |
||
456 | 1 | Adrian Georgescu | [[BR]]for_offer:[[BR]] |
457 | 65 | Luci Stanescu | {{{True}}} if the {{{SDPMediaStream}}} will be used for an SDP proposal and {{{False}}} if for a response. |
458 | 94 | Adrian Georgescu | |
459 | 65 | Luci Stanescu | '''initialize'''(''self'', ''session'', ''direction''):: |
460 | Initializes the stream. This method will get called as soon as the stream is known to be at least offered as part of the {{{Session}}}. If initialization goes fine, the stream must send a {{{MediaStreamDidInitialize}}} notification or a {{{MediaStreamDidFail}}} notification otherwise. |
||
461 | [[BR]]session:[[BR]] |
||
462 | The {{{Session}}} object this stream will be part of. |
||
463 | 1 | Adrian Georgescu | [[BR]]direction:[[BR]] |
464 | 65 | Luci Stanescu | {{{"incoming"}}} if the stream was created because of a received proposal and {{{"outgoing"}}} if a proposal was sent. Note that this need not be the same as the initial direction of the {{{Session}}} since streams can be proposed in either way using re-INVITEs. |
465 | 94 | Adrian Georgescu | |
466 | 65 | Luci Stanescu | '''start'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index''):: |
467 | Starts the stream. This method will be called as soon is known to be used in the {{{Session}}} (eg. only called for an incoming proposal if the local party accepts the proposed stream). If starting succeeds, the stream must send a {{{MediaStreamDidStart}}} notification or a {{{MediaStreamDidFail}}} notification otherwise. |
||
468 | [[BR]]local_sdp:[[BR]] |
||
469 | The {{{FrozenSDPSession}}} which is used by the local endpoint. |
||
470 | [[BR]]remote_sdp:[[BR]] |
||
471 | The {{{FrozenSDPSession}}} which is used by the remote endpoint. |
||
472 | 1 | Adrian Georgescu | [[BR]]stream_index:[[BR]] |
473 | 65 | Luci Stanescu | An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. |
474 | 94 | Adrian Georgescu | |
475 | 65 | Luci Stanescu | '''validate_update'''(''self'', ''remote_sdp'', ''stream_index''):: |
476 | This method will be called when a re-INVITE is received which changes the parameters of the stream within the SDP. The stream must return {{{True}}} if the changes are acceptable or {{{False}}} otherwise. If any changed streams return {{{False}}} for a re-INVITE, the re-INVITE will be refused with a negative response. This means that streams must not changed any internal data when this method is called as the update is not guaranteed to be applied even if the stream returns {{{True}}}. |
||
477 | [[BR]]remote_sdp:[[BR]] |
||
478 | The {{{FrozenSDPSession}}} which is used by the remote endpoint. |
||
479 | 1 | Adrian Georgescu | [[BR]]stream_index:[[BR]] |
480 | 65 | Luci Stanescu | An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. |
481 | 94 | Adrian Georgescu | |
482 | 65 | Luci Stanescu | '''update'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index''):: |
483 | This method is called when the an SDP negotiation initiated by either the local party or the remote party succeeds. The stream must update its internal state according to the new SDP in use. |
||
484 | [[BR]]local_sdp:[[BR]] |
||
485 | The {{{FrozenSDPSession}}} which is used by the local endpoint. |
||
486 | [[BR]]remote_sdp:[[BR]] |
||
487 | The {{{FrozenSDPSession}}} which is used by the remote endpoint. |
||
488 | 55 | Adrian Georgescu | [[BR]]stream_index:[[BR]] |
489 | 65 | Luci Stanescu | An integer representing the index within the list of media streams within the whole SDP which this stream is represented by. |
490 | 94 | Adrian Georgescu | |
491 | 55 | Adrian Georgescu | '''hold'''(''self''):: |
492 | 65 | Luci Stanescu | Puts the stream on hold if supported by the stream. Typically used by audio and video streams. The stream must immediately stop sending/receiving data and calls to {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state. |
493 | 94 | Adrian Georgescu | |
494 | 65 | Luci Stanescu | '''unhold'''(''self''):: |
495 | Takes the stream off hold. Typically used by audio and video streams. Calls to {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state. |
||
496 | 94 | Adrian Georgescu | |
497 | 65 | Luci Stanescu | '''deactivate'''(''self''):: |
498 | This method is called on a stream just before the stream will be removed from the {{{Session}}} (either as a result of a re-INVITE or a BYE). This method is needed because it avoids a race condition with streams using stateful protocols such as TCP: the stream connection might be terminated before the SIP signalling announces this due to network routing inconsistencies and the other endpoint would not be able to distinguish between this case and an error which caused the stream transport to fail. The stream must not take any action, but must consider that the transport being closed by the other endpoint after this method was called as a normal situation rather than an error condition. |
||
499 | 94 | Adrian Georgescu | |
500 | 55 | Adrian Georgescu | '''end'''(''self''):: |
501 | 65 | Luci Stanescu | Ends the stream. This must close the underlying transport connection. The stream must send a {{{MediaStreamWillEnd}}} just after this method is called and a {{{MediaStreamDidEnd}}} as soon as the operation is complete. This method is always be called by the {{{Session}}} on the stream if at least the {{{initialize()}}} method has been called. This means that once a stream sends the {{{MediaStreamDidFail}}} notification, the {{{Session}}} will still call this method. |
502 | 55 | Adrian Georgescu | |
503 | 96 | Adrian Georgescu | ==== attributes ==== |
504 | 65 | Luci Stanescu | |
505 | 94 | Adrian Georgescu | |
506 | 65 | Luci Stanescu | '''type''' (class attribute):: |
507 | A string identifying the stream type (eg: {{{"audio"}}}, {{{"video"}}}). |
||
508 | 94 | Adrian Georgescu | |
509 | 65 | Luci Stanescu | '''priority''' (class attribute):: |
510 | An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority). |
||
511 | 94 | Adrian Georgescu | |
512 | 65 | Luci Stanescu | '''hold_supported''':: |
513 | True if the stream supports hold |
||
514 | 94 | Adrian Georgescu | |
515 | 65 | Luci Stanescu | '''on_hold_by_local''':: |
516 | True if the stream is on hold by the local party |
||
517 | 94 | Adrian Georgescu | |
518 | 65 | Luci Stanescu | '''on_hold_by_remote''':: |
519 | True if the stream is on hold by the remote |
||
520 | 94 | Adrian Georgescu | |
521 | 55 | Adrian Georgescu | '''on_hold''':: |
522 | 65 | Luci Stanescu | True if either on_hold_by_local or on_hold_by_remote is true |
523 | |||
524 | ==== notifications ==== |
||
525 | |||
526 | 55 | Adrian Georgescu | These notifications must be generated by all streams in order for the {{{Session}}} to know the state of the stream. |
527 | 65 | Luci Stanescu | |
528 | 94 | Adrian Georgescu | |
529 | 55 | Adrian Georgescu | '''MediaStreamDidInitialize''':: |
530 | 65 | Luci Stanescu | Sent when the stream has been successfully initialized. |
531 | 94 | Adrian Georgescu | |
532 | 55 | Adrian Georgescu | '''MediaStreamDidStart''':: |
533 | 65 | Luci Stanescu | Sent when the stream has been successfully started. |
534 | 94 | Adrian Georgescu | |
535 | 55 | Adrian Georgescu | '''MediaStreamDidFail''':: |
536 | 65 | Luci Stanescu | Sent when the stream has failed either as a result of calling one of its methods, or during the normal operation of the stream (such as the transport connection being closed). |
537 | 94 | Adrian Georgescu | |
538 | 55 | Adrian Georgescu | '''MediaStreamWillEnd''':: |
539 | 65 | Luci Stanescu | Sent immediately after the {{{end()}}} method is called. |
540 | 94 | Adrian Georgescu | |
541 | 55 | Adrian Georgescu | '''MediaStreamDidEnd''':: |
542 | 66 | Luci Stanescu | Sent when the {{{end()}}} method finished closing the stream. |
543 | 55 | Adrian Georgescu | |
544 | 66 | Luci Stanescu | === MediaStreamRegistry === |
545 | 1 | Adrian Georgescu | |
546 | 66 | Luci Stanescu | The MediaStream registry is a collection of classes which implement {{{IMediaStream}}}. This collection is used by the {{{Session}}} to select a stream class for instantiation in the case of an incomming session. The streams are included in the collection in the descending order of their priority. Thus, streams with a higher priority will be tried first by the {{{Session}}}. This object is a Singleton so references to the same object can be obtained by a simple instantiation. |
547 | |||
548 | 1 | Adrian Georgescu | There are several pre-built streams based on the {{{IMediaStream}}} API: |
549 | * {{{sipsimple.streams.rtp.AudioStream}}} - Audio stream based on RTP |
||
550 | 66 | Luci Stanescu | * {{{sipsimple.streams.msrp.ChatStream}}} - Chat stream based on MSRP |
551 | 1 | Adrian Georgescu | * {{{sipsimple.streams.msrp.FileTransferStream}}} - File Transfer stream based on MSRP |
552 | 66 | Luci Stanescu | * {{{sipsimple.streams.msrp.DesktopSharingStream}}} - Desktop Sharing stream based on VNC over MSRP |
553 | |||
554 | Other streams which are created by the application must be registered in this registry. For a simple way of doing this, see [wiki:SipMiddlewareApi#MediaStreamRegistrar MediaStreamRegistrar]. |
||
555 | |||
556 | ==== methods ==== |
||
557 | |||
558 | 94 | Adrian Georgescu | |
559 | 66 | Luci Stanescu | '''!__init!__'''(''self''):: |
560 | Instantiate the MediaStreamRegistry. This will be called just once when first (and only) instance is created. |
||
561 | 94 | Adrian Georgescu | |
562 | 66 | Luci Stanescu | '''!__iter!__'''(''self''):: |
563 | This method allows the registry to be iterated through and will return classes which were registered to it. |
||
564 | 94 | Adrian Georgescu | |
565 | 66 | Luci Stanescu | '''add'''(''self'', '''cls'''):: |
566 | Add {{{cls}}} to the registry of streams. The class must implement the {{{IMediaStream}}} interface. |
||
567 | |||
568 | === MediaStreamRegistrar === |
||
569 | |||
570 | This is a convenience metaclass which automatically registers a defined class with the {{{MediaStreamRegistry}}}. In order to use this class, one simply needs to use it as the metaclass of the new stream. |
||
571 | |||
572 | {{{ |
||
573 | from zope.interface import implements |
||
574 | |||
575 | from sipsimple.streams import IMediaStream, MediaStreamRegistrar |
||
576 | |||
577 | |||
578 | class MyStream(object): |
||
579 | __metaclass__ = MediaStreamRegistrar |
||
580 | |||
581 | implements(IMediaStream) |
||
582 | |||
583 | 55 | Adrian Georgescu | [...] |
584 | 67 | Luci Stanescu | }}} |
585 | 55 | Adrian Georgescu | |
586 | === AudioStream === |
||
587 | |||
588 | 67 | Luci Stanescu | Implemented in [browser:sipsimple/streams/rtp.py] |
589 | 55 | Adrian Georgescu | |
590 | The {{{AudioStream}}} is an implementation of {{{IMediaStream}}} which supports audio data using the {{{AudioTransport}}} and {{{RTPTransport}}} of the SIP core. As such, it provides all features of these objects, including ICE negotiation. An example SDP created using the {{{AudioStream}}} is provided below: |
||
591 | |||
592 | {{{ |
||
593 | Content-Type: application/sdp |
||
594 | Content-Length: 1093 |
||
595 | |||
596 | v=0 |
||
597 | o=- 3467525278 3467525278 IN IP4 192.168.1.6 |
||
598 | s=blink-0.10.7-beta |
||
599 | 57 | Adrian Georgescu | c=IN IP4 80.101.96.20 |
600 | t=0 0 |
||
601 | m=audio 55328 RTP/AVP 104 103 102 3 9 0 8 101 |
||
602 | a=rtcp:55329 IN IP4 80.101.96.20 |
||
603 | a=rtpmap:104 speex/32000 |
||
604 | a=rtpmap:103 speex/16000 |
||
605 | a=rtpmap:102 speex/8000 |
||
606 | a=rtpmap:3 GSM/8000 |
||
607 | a=rtpmap:9 G722/8000 |
||
608 | a=rtpmap:0 PCMU/8000 |
||
609 | a=rtpmap:8 PCMA/8000 |
||
610 | a=rtpmap:101 telephone-event/8000 |
||
611 | a=fmtp:101 0-15 |
||
612 | a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:esI6DbLY1+Aceu0JNswN9Z10DcFx5cZwqJcu91jb |
||
613 | a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:SHuEMm1BYJqOF4udKl73EaCwnsI57pO86bYKsg70 |
||
614 | a=ice-ufrag:2701ed80 |
||
615 | a=ice-pwd:6f8f8281 |
||
616 | a=candidate:S 1 UDP 31 80.101.96.20 55328 typ srflx raddr 192.168.1.6 rport 55328 |
||
617 | a=candidate:H 1 UDP 23 192.168.1.6 55328 typ host |
||
618 | a=candidate:H 1 UDP 23 10.211.55.2 55328 typ host |
||
619 | a=candidate:H 1 UDP 23 10.37.129.2 55328 typ host |
||
620 | a=candidate:S 2 UDP 30 80.101.96.20 55329 typ srflx raddr 192.168.1.6 rport 55329 |
||
621 | a=candidate:H 2 UDP 22 192.168.1.6 55329 typ host |
||
622 | a=candidate:H 2 UDP 22 10.211.55.2 55329 typ host |
||
623 | a=candidate:H 2 UDP 22 10.37.129.2 55329 typ host |
||
624 | 1 | Adrian Georgescu | a=sendrecv |
625 | 67 | Luci Stanescu | }}} |
626 | 1 | Adrian Georgescu | |
627 | 67 | Luci Stanescu | As an implementation of {{{IAudioPort}}}, an {{{AudioStream}}} can be added to an {{{AudioBridge}}} to send or to read audio data to/from other audio objects. It is connected to the voice {{{AudioMixer}}} ({{{SIPApplication.voice_audio_mixer}}}) so it can only be added to bridges using the same {{{AudioMixer}}}. It also contains an {{{AudioBridge}}} on the {{{bridge}}} attribute which always contains an {{{AudioDevice}}} corresponding to the input and output devices; when the stream is active (started and not on hold), the bridge also contains the stream itself and when recording is active, the stream contains a {{{WaveRecorder}}} which records audio data. |
628 | |||
629 | ==== methods ==== |
||
630 | |||
631 | 94 | Adrian Georgescu | |
632 | 67 | Luci Stanescu | '''start_recording'''(''self'', '''filename'''={{{None}}}):: |
633 | If an audio stream is present within this session, calling this method will record the audio to a {{{.wav}}} file. |
||
634 | Note that when the session is on hold, nothing will be recorded to the file. |
||
635 | Right before starting the recording a {{{SIPSessionWillStartRecordingAudio}}} notification will be emitted, followed by a {{{SIPSessionDidStartRecordingAudio}}}. |
||
636 | This method may only be called while the stream is started. |
||
637 | [[BR]]''filename'':[[BR]] |
||
638 | The name of the {{{.wav}}} file to record to. |
||
639 | If this is set to {{{None}}}, a default file name including the session participants and the timestamp will be generated using the directory defined in the configuration. |
||
640 | 94 | Adrian Georgescu | |
641 | 67 | Luci Stanescu | '''stop_recording'''(''self''):: |
642 | This will stop a previously started recording. |
||
643 | Before stopping, a {{{SIPSessionWillStopRecordingAudio}}} notification will be sent, followed by a {{{SIPSessionDidStopRecordingAudio}}}. |
||
644 | 94 | Adrian Georgescu | |
645 | 67 | Luci Stanescu | '''send_dtmf'''(''self'', '''digit'''):: |
646 | If the audio stream is started, sends a DTMF digit to the remote party. |
||
647 | [[BR]]''digit'':[[BR]] |
||
648 | This should a string of length 1, containing a valid DTMF digit value (0-9, A-D, * or #). |
||
649 | |||
650 | 63 | Luci Stanescu | ==== attributes ==== |
651 | |||
652 | 94 | Adrian Georgescu | |
653 | 63 | Luci Stanescu | '''sample_rate''':: |
654 | 1 | Adrian Georgescu | If the audio stream was started, this attribute contains the sample rate of the audio negotiated. |
655 | 94 | Adrian Georgescu | |
656 | 1 | Adrian Georgescu | '''codec''':: |
657 | If the audio stream was started, this attribute contains the name of the audio codec that was negotiated. |
||
658 | 94 | Adrian Georgescu | |
659 | 67 | Luci Stanescu | '''srtp_active''':: |
660 | If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream. |
||
661 | 94 | Adrian Georgescu | |
662 | 1 | Adrian Georgescu | '''ice_active''':: |
663 | {{{True}}} if the ICE candidates negotiated are being used, {{{False}}} otherwise. |
||
664 | 94 | Adrian Georgescu | |
665 | 1 | Adrian Georgescu | '''local_rtp_address''':: |
666 | If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream. |
||
667 | 94 | Adrian Georgescu | |
668 | 1 | Adrian Georgescu | '''local_rtp_port''':: |
669 | If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream. |
||
670 | 94 | Adrian Georgescu | |
671 | 1 | Adrian Georgescu | '''remote_rtp_address_sdp''':: |
672 | If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to. |
||
673 | 94 | Adrian Georgescu | |
674 | 1 | Adrian Georgescu | '''remote_rtp_port_sdp''':: |
675 | If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to. |
||
676 | 94 | Adrian Georgescu | |
677 | 1 | Adrian Georgescu | '''remote_rtp_address_received''':: |
678 | If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received. |
||
679 | 94 | Adrian Georgescu | |
680 | 67 | Luci Stanescu | '''remote_rtp_port_received''':: |
681 | If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received. |
||
682 | 94 | Adrian Georgescu | |
683 | 67 | Luci Stanescu | '''local_rtp_candidate_type''':: |
684 | The local ICE candidate type which was selected by the ICE negotiation if it succeeded and {{{None}}} otherwise. |
||
685 | 94 | Adrian Georgescu | |
686 | 67 | Luci Stanescu | '''remote_rtp_candidate_type''':: |
687 | 63 | Luci Stanescu | The remote ICE candidate type which was selected by the ICE negotiation if it succeeded and {{{None}}} otherwise. |
688 | 94 | Adrian Georgescu | |
689 | 63 | Luci Stanescu | '''recording_filename''':: |
690 | 67 | Luci Stanescu | If the audio stream is currently being recorded to disk, this property contains the name of the {{{.wav}}} file being recorded to. |
691 | 55 | Adrian Georgescu | |
692 | ==== notifications ==== |
||
693 | 67 | Luci Stanescu | |
694 | 94 | Adrian Georgescu | |
695 | 67 | Luci Stanescu | '''AudioStreamDidChangeHoldState''':: |
696 | Will be sent when the hold state is changed as a result of either a SIP message received on the network or the application calling the {{{hold()/unhold()}}} methods on the {{{Session}}} this stream is part of. |
||
697 | [[BR]]''timestamp'':[[BR]] |
||
698 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
699 | [[BR]]originator:[[BR]] |
||
700 | A string representing the party which requested the hold change, {{{"local"}}} or {{{"remote"}}} |
||
701 | 1 | Adrian Georgescu | [[BR]]on_hold:[[BR]] |
702 | 67 | Luci Stanescu | A boolean indicating the new hold state from the point of view of the originator. |
703 | 94 | Adrian Georgescu | |
704 | 63 | Luci Stanescu | '''AudioStreamWillStartRecordingAudio'':: |
705 | Will be sent when the application requested that the audio stream be recorded to a {{{.wav}}} file, just before recording starts. |
||
706 | 67 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
707 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
708 | 55 | Adrian Georgescu | [[BR]]''filename'':[[BR]] |
709 | 67 | Luci Stanescu | The full path to the {{{.wav}}} file being recorded to. |
710 | 94 | Adrian Georgescu | |
711 | 63 | Luci Stanescu | '''AudioStreamDidStartRecordingAudio''':: |
712 | Will be sent when the application requested that the audio stream be recorded to a {{{.wav}}} file, just after recording started. |
||
713 | 67 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
714 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
715 | 63 | Luci Stanescu | [[BR]]''filename'':[[BR]] |
716 | The full path to the {{{.wav}}} file being recorded to. |
||
717 | 94 | Adrian Georgescu | |
718 | 63 | Luci Stanescu | '''AudioStreamWillStopRecordingAudio''':: |
719 | Will be sent when the application requested ending the recording to a {{{.wav}}} file, just before recording stops. |
||
720 | 67 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
721 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
722 | 57 | Adrian Georgescu | [[BR]]''filename'':[[BR]] |
723 | 67 | Luci Stanescu | The full path to the {{{.wav}}} file being recorded to. |
724 | 94 | Adrian Georgescu | |
725 | 63 | Luci Stanescu | '''AudioStreamDidStopRecordingAudio''':: |
726 | Will be sent when the application requested ending the recording to a {{{.wav}}} file, just after recording stoped. |
||
727 | 67 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
728 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
729 | [[BR]]''filename'':[[BR]] |
||
730 | The full path to the {{{.wav}}} file being recorded to. |
||
731 | 94 | Adrian Georgescu | |
732 | 63 | Luci Stanescu | '''AudioStreamDidChangeRTPParameters''':: |
733 | 1 | Adrian Georgescu | This notification is sent when the RTP parameters are changed, such as codec, sample rate, RTP port etc. |
734 | 63 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
735 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
736 | 94 | Adrian Georgescu | |
737 | 57 | Adrian Georgescu | '''AudioStreamGotDTMF''':: |
738 | 1 | Adrian Georgescu | Will be send if there is a DMTF digit received from the remote party on the audio stream. |
739 | 63 | Luci Stanescu | [[BR]]''timestamp'':[[BR]] |
740 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
741 | 67 | Luci Stanescu | [[BR]]''digit'':[[BR]] |
742 | The DTMF digit that was received, in the form of a string of length 1. |
||
743 | 94 | Adrian Georgescu | |
744 | 67 | Luci Stanescu | '''AudioStreamICENegotiationStateDidChange''':: |
745 | This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationStateDidChange}}}. |
||
746 | 94 | Adrian Georgescu | |
747 | 67 | Luci Stanescu | '''AudioStreamICENegotiationDidSucceed''':: |
748 | This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationDidSucceed}}}. |
||
749 | 94 | Adrian Georgescu | |
750 | 1 | Adrian Georgescu | '''AudioStreamICENegotiationDidFail''':: |
751 | 69 | Luci Stanescu | This notification is proxied from the {{{RTPTransport}}} and as such has the same data as the {{{RTPTransportICENegotiationDidFail}}}. |
752 | 136 | Adrian Georgescu | |
753 | '''AudioStreamDidTimeout''':: |
||
754 | This notification is proxied from the {{{RTPTransport}}}. It's sent when the RTP transport did not receive any data after the specified amount of time (rtp.timeout setting in the {{{Account}}}). |
||
755 | |||
756 | 1 | Adrian Georgescu | === MSRPStreamBase === |
757 | |||
758 | 68 | Luci Stanescu | Implemented in [browser:sipsimple/streams/msrp.py] |
759 | 1 | Adrian Georgescu | |
760 | 68 | Luci Stanescu | The {{{MSRPStreamBase}}} is used as a base class for streams using the MSRP protocol. Within the SIP SIMPLE middleware, this hold for the {{{ChatStream}}}, {{{FileTransferStream}}} and {{{DesktopSharingStream}}} classes, however the application can also make use of this class to implement some other streams based on the MSRP protocol as a transport. |
761 | |||
762 | ==== methods ==== |
||
763 | |||
764 | 69 | Luci Stanescu | Of the methods defined by the {{{IMediaStream}}} interface, only the {{{new_from_sdp}}} method is not implemented in this base class and needs to be provided by the subclasses. Also, the subclasses can defined methods of the form {{{_handle_XXX}}}, where XXX is a MSRP method name in order to handle incoming MSRP requests. Also, since this class registers as an observer for itself, it will receive the notifications it sends so subclasses can define methods having the signature {{{_NH_<notification name>(self, notification)}}} as used throughout the middleware in order to do various things at the different points within the life-cycle of the stream. |
765 | 68 | Luci Stanescu | |
766 | 96 | Adrian Georgescu | ==== attributes ==== |
767 | 68 | Luci Stanescu | |
768 | The attributes defined in the {{{IMediaStream}}} interface which are not provided by this class are: |
||
769 | * type |
||
770 | * priority |
||
771 | 1 | Adrian Georgescu | |
772 | 68 | Luci Stanescu | In addition, the following attributes need to be defined in the subclass in order for the {{{MSRPStreamBase}}} class to take the correct decisions |
773 | 94 | Adrian Georgescu | |
774 | 1 | Adrian Georgescu | '''media_type''':: |
775 | 68 | Luci Stanescu | The media type as included in the SDP (eg. {{{"message"}}}, {{{"application"}}}). |
776 | 94 | Adrian Georgescu | |
777 | 1 | Adrian Georgescu | '''accept_types''':: |
778 | 68 | Luci Stanescu | A list of the MIME types which should be accepted by the stream (this is also sent within the SDP). |
779 | 94 | Adrian Georgescu | |
780 | 1 | Adrian Georgescu | '''accept_wrapped_types''':: |
781 | 68 | Luci Stanescu | A list of the MIME types which should be accepted by the stream while wrapped in a {{{message/cpim}}} envelope. |
782 | 94 | Adrian Georgescu | |
783 | 1 | Adrian Georgescu | '''use_msrp_session''':: |
784 | 69 | Luci Stanescu | A boolean indicating whether or not an {{{MSRPSession}}} should be used. |
785 | 1 | Adrian Georgescu | |
786 | 68 | Luci Stanescu | ==== notifications ==== |
787 | |||
788 | 1 | Adrian Georgescu | While not technically notifications of {{{MSRPStreamBase}}}, these notifications are sent from the middleware on behalf of the {{{MSRPTransport}}} used by a stream in the former case, and anonymously in the latter. |
789 | 68 | Luci Stanescu | |
790 | 94 | Adrian Georgescu | |
791 | 68 | Luci Stanescu | '''MSRPTransportTrace''':: |
792 | This notification is sent when an MSRP message is received for logging purposes. |
||
793 | [[BR]]timestamp:[[BR]] |
||
794 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
795 | [[BR]]direction:[[BR]] |
||
796 | The direction of the message, {{{"incoming"}}} or {{{"outgoing"}}}. |
||
797 | [[BR]]data:[[BR]] |
||
798 | The MSRP message as a string. |
||
799 | 94 | Adrian Georgescu | |
800 | 68 | Luci Stanescu | '''MSRPLibraryLog''':: |
801 | This notification is sent anonymously whenever the MSRP library needs to log any information. |
||
802 | [[BR]]timestamp:[[BR]] |
||
803 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
804 | [[BR]]message:[[BR]] |
||
805 | The log message as a string. |
||
806 | 1 | Adrian Georgescu | [[BR]]level:[[BR]] |
807 | 68 | Luci Stanescu | The log level at which the message was written. One of the levels {{{DEBUG}}}, {{{INFO}}}, {{{WARNING}}}, {{{ERROR}}}, {{{CRITICAL}}} from the {{{application.log.level}}} object which is part of the {{{python-application}}} library. |
808 | 1 | Adrian Georgescu | |
809 | === ChatStream === |
||
810 | |||
811 | 68 | Luci Stanescu | Implemented in [browser:sipsimple/streams/msrp.py] |
812 | 1 | Adrian Georgescu | |
813 | {{{sipsimple.streams.msrp.ChatStream}}} implements session-based Instant Messaging (IM) over MSRP. This class performs the following functions: |
||
814 | 68 | Luci Stanescu | |
815 | * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types |
||
816 | 1 | Adrian Georgescu | * unwraps incoming Message/CPIM messages; for each incoming message, the {{{ChatStreamGotMessage}}} notification is posted |
817 | 68 | Luci Stanescu | * composes iscomposing payloads and reacts to those received by sending the {{{ChatStreamGotComposingIndication}}} notification |
818 | 1 | Adrian Georgescu | |
819 | An example of an SDP created using this class follows: |
||
820 | |||
821 | {{{ |
||
822 | Content-Type: application/sdp |
||
823 | Content-Length: 283 |
||
824 | |||
825 | v=0 |
||
826 | o=- 3467525214 3467525214 IN IP4 192.168.1.6 |
||
827 | s=blink-0.10.7-beta |
||
828 | c=IN IP4 192.168.1.6 |
||
829 | t=0 0 |
||
830 | m=message 2855 TCP/TLS/MSRP * |
||
831 | a=path:msrps://192.168.1.6:2855/ca7940f12ddef14c3c32;tcp |
||
832 | a=accept-types:message/cpim text/* application/im-iscomposing+xml |
||
833 | a=accept-wrapped-types:* |
||
834 | 68 | Luci Stanescu | }}} |
835 | 1 | Adrian Georgescu | |
836 | 68 | Luci Stanescu | ==== methods ==== |
837 | |||
838 | 94 | Adrian Georgescu | |
839 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''account''', '''direction'''={{{'sendrecv'}}}):: |
840 | 68 | Luci Stanescu | Initializes the ChatStream instance. |
841 | |||
842 | 94 | Adrian Georgescu | |
843 | 68 | Luci Stanescu | '''send_message'''(''self'', '''content''', '''content_type'''={{{'text/plain'}}}, '''recipients'''={{{None}}}, '''courtesy_recipients'''={{{None}}}, '''subject'''={{{None}}}, ''timestamp''={{{None}}}, '''required'''={{{None}}}, '''additional_headers'''={{{None}}}):: |
844 | Sends an IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be |
||
845 | queued until the stream starts. |
||
846 | Returns the generated MSRP message ID. |
||
847 | [[BR]]content:[[BR]] |
||
848 | The content of the message. |
||
849 | [[BR]]content_type:[[BR]] |
||
850 | Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case); |
||
851 | otherwise, Content-Type of MSRP message. |
||
852 | [[BR]]recipients:[[BR]] |
||
853 | The list of {{{CPIMIdentity}}} objects which will be used for the {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity. |
||
854 | May only differ from the default one if the remote party supports private messages. If it does not, a {{{ChatStreamError}}} will be raised. |
||
855 | [[BR]]courtesy_recipients:[[BR]] |
||
856 | The list of {{{CPIMIdentity}}} objects which will be used for the {{{cc}}} header of the CPIM wrapper. |
||
857 | May only be specified if the remote party supports private messages and CPIM is supported. If it does not, a {{{ChatStreamError}}} will be raised. |
||
858 | [[BR]]subject:[[BR]] |
||
859 | A string or {{{MultilingualText}}} which specifies the subject and its translations to be added to the CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised. |
||
860 | [[BR]]required:[[BR]] |
||
861 | A list of strings describing the required capabilities that the other endpoint must support in order to understand this CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised. |
||
862 | [[BR]]additional_headers:[[BR]] |
||
863 | 1 | Adrian Georgescu | A list of MSRP header objects which will be added to this CPIM message. If CPIM is not supported, a {{{ChatStreamError}}} will be raised. |
864 | 68 | Luci Stanescu | [[BR]]timestamp:[[BR]] |
865 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message. |
866 | When set to {{{None}}}, a default one representing the current moment will be added. |
||
867 | |||
868 | These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses: |
||
869 | {{{ |
||
870 | Failure-Report: partial |
||
871 | Success-Report: yes |
||
872 | 68 | Luci Stanescu | }}} |
873 | |||
874 | 94 | Adrian Georgescu | |
875 | 68 | Luci Stanescu | '''send_composing_indication'''(''self'', ''state'', ''refresh'', ''last_active=None'', ''recipients=None''):: |
876 | Sends an is-composing message to the listed recipients. |
||
877 | [[BR]]state:[[BR]] |
||
878 | The state of the endpoint, {{{"active"}}} or {{{"idle"}}}. |
||
879 | [[BR]]refresh:[[BR]] |
||
880 | How often the local endpoint will send is-composing indications to keep the state from being reverted to {{{"idle"}}}. |
||
881 | [[BR]]last_active:[[BR]] |
||
882 | A {{{datatime.datetime}}} object representing the moment when the local endpoint was last active. |
||
883 | [[BR]]recipients:[[BR]] |
||
884 | 1 | Adrian Georgescu | The list of {{{CPIMIdentity}}} objects which will be used for the {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity. |
885 | 68 | Luci Stanescu | May only differ from the default one if the remote party supports private messages. If it does not, a {{{ChatStreamError}}} will be raised. |
886 | 1 | Adrian Georgescu | |
887 | ==== notifications ==== |
||
888 | 68 | Luci Stanescu | |
889 | 94 | Adrian Georgescu | |
890 | 68 | Luci Stanescu | '''ChatStreamGotMessage''':: |
891 | Sent whenever a new incoming message is received, |
||
892 | [[BR]]timestamp:[[BR]] |
||
893 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
894 | 1 | Adrian Georgescu | [[BR]]message:[[BR]] |
895 | 68 | Luci Stanescu | A {{{ChatMessage}}} or {{{CPIMMessage}}} instance, depending on whether a CPIM message was received or not. |
896 | 94 | Adrian Georgescu | |
897 | 68 | Luci Stanescu | '''ChatStreamDidDeliverMessage''':: |
898 | Sent when a successful report is received. |
||
899 | [[BR]]timestamp:[[BR]] |
||
900 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
901 | 68 | Luci Stanescu | [[BR]]message_id:[[BR]] |
902 | Text identifier of the message. |
||
903 | [[BR]]code:[[BR]] |
||
904 | The status code received. Will always be 200 for this notification. |
||
905 | [[BR]]reason:[[BR]] |
||
906 | 1 | Adrian Georgescu | The status reason received. |
907 | [[BR]]chunk:[[BR]] |
||
908 | 68 | Luci Stanescu | A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report. |
909 | 94 | Adrian Georgescu | |
910 | 68 | Luci Stanescu | '''ChatStreamDidNotDeliverMessage''':: |
911 | Sent when a failure report is received. |
||
912 | [[BR]]timestamp:[[BR]] |
||
913 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
914 | 68 | Luci Stanescu | [[BR]]message_id:[[BR]] |
915 | Text identifier of the message. |
||
916 | [[BR]]code:[[BR]] |
||
917 | The status code received. |
||
918 | [[BR]]reason:[[BR]] |
||
919 | 1 | Adrian Georgescu | The status reason received. |
920 | [[BR]]chunk:[[BR]] |
||
921 | 68 | Luci Stanescu | A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report. |
922 | 94 | Adrian Georgescu | |
923 | 68 | Luci Stanescu | '''ChatStreamDidSendMessage''':: |
924 | Sent when an outgoing message has been sent. |
||
925 | [[BR]]timestamp:[[BR]] |
||
926 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
927 | 1 | Adrian Georgescu | [[BR]]message:[[BR]] |
928 | 68 | Luci Stanescu | A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the sent message. |
929 | 94 | Adrian Georgescu | |
930 | 68 | Luci Stanescu | '''ChatStreamGotComposingIndication''':: |
931 | Sent when a is-composing payload is received. |
||
932 | [[BR]]timestamp:[[BR]] |
||
933 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
934 | [[BR]]state:[[BR]] |
||
935 | The state of the endpoint, {{{"active"}}} or {{{"idle"}}}. |
||
936 | [[BR]]refresh:[[BR]] |
||
937 | How often the remote endpoint will send is-composing indications to keep the state from being reverted to {{{"idle"}}}. May be {{{None}}}. |
||
938 | [[BR]]last_active:[[BR]] |
||
939 | A {{{datatime.datetime}}} object representing the moment when the remote endpoint was last active. May be {{{None}}}. |
||
940 | [[BR]]content_type:[[BR]] |
||
941 | The MIME type of message being composed. May be {{{None}}}. |
||
942 | 55 | Adrian Georgescu | [[BR]]sender:[[BR]] |
943 | 70 | Luci Stanescu | The {{{ChatIdentity}}} or {{{CPIMIdentity}}} instance which identifies the sender of the is-composing indication. |
944 | 137 | Adrian Georgescu | [[BR]]recipients:[[BR]] |
945 | The {{{ChatIdentity}}} or {{{CPIMIdentity}}} instances list which identifies the recipients of the is-composing indication. |
||
946 | 1 | Adrian Georgescu | |
947 | 70 | Luci Stanescu | === FileSelector === |
948 | |||
949 | The {{{FileSelector}}} is used to contain information about a file tranfer using the {{{FileTransferStream}}} documented below. |
||
950 | |||
951 | ==== methods ==== |
||
952 | |||
953 | 94 | Adrian Georgescu | |
954 | 70 | Luci Stanescu | '''!__init!__'''(''self'', '''name'''={{{None}}}, '''type'''={{{None}}}, '''size'''={{{None}}}, '''hash'''={{{None}}}, '''fd'''={{{None}}}):: |
955 | Instantiate a new {{{FileSelector}}}. All the arguments are also available as attributes. |
||
956 | [[BR]]name:[[BR]] |
||
957 | The filename (should be just the base name). |
||
958 | 1 | Adrian Georgescu | [[BR]]type:[[BR]] |
959 | The type of the file. |
||
960 | [[BR]]size:[[BR]] |
||
961 | The size of the file in bytes. |
||
962 | [[BR]]hash:[[BR]] |
||
963 | The hash of the file in the following format: {{{hash:sha-1:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX}}}, where {{{X}}} is a hexadecimal digit. Currently, only SHA1 hashes are supported according to the RFC. |
||
964 | [[BR]]fd:[[BR]] |
||
965 | A file descriptor if the application has already opened the file. |
||
966 | 94 | Adrian Georgescu | |
967 | 1 | Adrian Georgescu | '''parse'''(''cls'', '''string'''):: |
968 | Parses a file selector from the SDP {{{file-selector}}} a attribute and returns a {{{FileSelector}}} instance. |
||
969 | 94 | Adrian Georgescu | |
970 | 1 | Adrian Georgescu | '''for_file'''(''cls'', '''path''', '''content_type''', '''compute_hash'''={{{True}}}):: |
971 | Returns a {{{FileSelector}}} instance for the specified file. The file identified by the path must exist. Note that if {{{compute_hash}}} is {{{True}}} this method will block while the hash is computed, a potentially long operation for large files. |
||
972 | [[BR]]path:[[BR]] |
||
973 | The full path to the file. |
||
974 | [[BR]]content_type:[[BR]] |
||
975 | An optional MIME type which is to be included in the file-selector. |
||
976 | [[BR]]compute_hash:[[BR]] |
||
977 | Whether or not this method should compute the hash of the file. |
||
978 | |||
979 | 135 | Adrian Georgescu | '''compute_hash'''(''self''):: |
980 | Compute the hash for this file selector. This method will block while the hash is computed, a potentially long operation for large files. |
||
981 | |||
982 | 1 | Adrian Georgescu | ==== attributes ==== |
983 | |||
984 | 94 | Adrian Georgescu | |
985 | 1 | Adrian Georgescu | '''sdp_repr''':: |
986 | The SDP representation of the file-selector according to the RFC. This should be the value of the {{{file-selector}}} SDP attribute. |
||
987 | |||
988 | === FileTransferStream === |
||
989 | |||
990 | Implemented in [browser:sipsimple/streams/msrp.py] |
||
991 | |||
992 | The {{{FileTransferStream}}} supports file transfer over MSRP according to RFC5547. An example of SDP constructed using this stream follows: |
||
993 | |||
994 | {{{ |
||
995 | Content-Type: application/sdp |
||
996 | Content-Length: 383 |
||
997 | |||
998 | v=0 |
||
999 | o=- 3467525166 3467525166 IN IP4 192.168.1.6 |
||
1000 | s=blink-0.10.7-beta |
||
1001 | c=IN IP4 192.168.1.6 |
||
1002 | t=0 0 |
||
1003 | m=message 2855 TCP/TLS/MSRP * |
||
1004 | a=path:msrps://192.168.1.6:2855/e593357dc9abe90754bd;tcp |
||
1005 | a=sendonly |
||
1006 | a=accept-types:* |
||
1007 | a=accept-wrapped-types:* |
||
1008 | 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 |
||
1009 | }}} |
||
1010 | |||
1011 | ==== methods ==== |
||
1012 | |||
1013 | 94 | Adrian Georgescu | |
1014 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''account''', '''file_selector'''={{{None}}}):: |
1015 | Instantiate a new {{{FileTransferStream}}}. If this is constructed by the application for an outgoing file transfer, the {{{file_selector}}} argument must be present. |
||
1016 | [[BR]]account:[[BR]] |
||
1017 | The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} instance which will be associated with the stream. |
||
1018 | [[BR]]file_selector:[[BR]] |
||
1019 | The {{{FileSelector}}} instance which represents the file which is to be transferred. |
||
1020 | |||
1021 | ==== notifications ==== |
||
1022 | |||
1023 | 94 | Adrian Georgescu | |
1024 | 1 | Adrian Georgescu | '''FileTransferStreamDidDeliverChunk''':: |
1025 | This notification is sent for an outgoing file transfer when a success report is received about part of the file being transferred. |
||
1026 | [[BR]]timestamp:[[BR]] |
||
1027 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1028 | [[BR]]message_id:[[BR]] |
||
1029 | The MSRP message ID of the file transfer session. |
||
1030 | [[BR]]chunk:[[BR]] |
||
1031 | An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT. |
||
1032 | [[BR]]code:[[BR]] |
||
1033 | The status code received. Will always be 200 for this notification. |
||
1034 | [[BR]]reason:[[BR]] |
||
1035 | The status reason received. |
||
1036 | [[BR]]transferred_bytes:[[BR]] |
||
1037 | The number of bytes which have currently been successfully transferred. |
||
1038 | [[BR]]file_size:[[BR]] |
||
1039 | The size of the file being transferred. |
||
1040 | 94 | Adrian Georgescu | |
1041 | 1 | Adrian Georgescu | '''FileTransferStreamDidNotDeliverChunk''':: |
1042 | [[BR]]timestamp:[[BR]] |
||
1043 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1044 | This notification is sent for an outgoing file transfer when a failure report is received about part of the file being transferred. |
||
1045 | [[BR]]message_id:[[BR]] |
||
1046 | The MSRP message ID of the file transfer session. |
||
1047 | [[BR]]chunk:[[BR]] |
||
1048 | An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT. |
||
1049 | [[BR]]code:[[BR]] |
||
1050 | The status code received. |
||
1051 | [[BR]]reason:[[BR]] |
||
1052 | The status reason received. |
||
1053 | 94 | Adrian Georgescu | |
1054 | 1 | Adrian Georgescu | '''FileTransferStreamDidFinish''':: |
1055 | This notification is sent when the incoming or outgoing file transfer is finished. |
||
1056 | [[BR]]timestamp:[[BR]] |
||
1057 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1058 | 94 | Adrian Georgescu | |
1059 | 1 | Adrian Georgescu | '''FileTransferStreamGotChunk''':: |
1060 | This notificaiton is sent for an incoming file transfer when a chunk of file data is received. |
||
1061 | [[BR]]timestamp:[[BR]] |
||
1062 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1063 | [[BR]]content:[[BR]] |
||
1064 | The file part which was received, as a {{{str}}}. |
||
1065 | [[BR]]content_type:[[BR]] |
||
1066 | The MIME type of the file which is being transferred. |
||
1067 | [[BR]]transferred_bytes:[[BR]] |
||
1068 | The number of bytes which have currently been successfully transferred. |
||
1069 | [[BR]]file_size:[[BR]] |
||
1070 | The size of the file being transferred. |
||
1071 | |||
1072 | |||
1073 | === IDesktopSharingHandler === |
||
1074 | |||
1075 | This interface is used to describe the interface between a {{{IDesktopSharingHandler}}}, which is responsible for consuming and producing RFB data, and the {{{DesktopSharingStream}}} which is responsible for transporting the RFB data over MSRP. The middleware provides four implementations of this interface: |
||
1076 | * InternalVNCViewerHandler |
||
1077 | * InternalVNCServerHandler |
||
1078 | * ExternalVNCViewerHandler |
||
1079 | * ExternalVNCServerHandler |
||
1080 | |||
1081 | ==== methods ==== |
||
1082 | |||
1083 | 94 | Adrian Georgescu | |
1084 | 1 | Adrian Georgescu | '''initialize'''(''self'', '''stream'''):: |
1085 | This method will be called by the {{{DesktopSharingStream}}} when the stream has been started and RFB data can be transported. The stream has two attributes which are relevant to the {{{IDesktopSharingHandler}}}: incoming_queue and outgoing_queue. These attributes are {{{eventlet.coros.queue}}} instances which are used to transport RFB data between the stream and the handler. |
||
1086 | |||
1087 | ==== attributes ==== |
||
1088 | |||
1089 | 94 | Adrian Georgescu | |
1090 | 1 | Adrian Georgescu | '''type''':: |
1091 | {{{"active"}}} or {{{"passive"}}} depending on whether the handler represents a VNC viewer or server respectively. |
||
1092 | |||
1093 | ==== notifications ==== |
||
1094 | |||
1095 | 94 | Adrian Georgescu | |
1096 | 1 | Adrian Georgescu | '''DesktopSharingHandlerDidFail''':: |
1097 | This notification must be sent by the handler when an error occurs to notify the stream that it should fail. |
||
1098 | [[BR]]context:[[BR]] |
||
1099 | A string describing when the handler failed, such as {{{"reading"}}}, {{{"sending"}}} or {{{"connecting"}}}. |
||
1100 | [[BR]]failure:[[BR]] |
||
1101 | A {{{twisted.python.failure.Failure}}} instance describing the exception which led to the failure. |
||
1102 | [[BR]]reason:[[BR]] |
||
1103 | A string describing the failure reason. |
||
1104 | |||
1105 | === InternalVNCViewerHandler === |
||
1106 | |||
1107 | 99 | Luci Stanescu | This is a concrete implementation of the {{{IDesktopSharingHandler}}} interface which can be used for a VNC viewer implemented within the application. |
1108 | 1 | Adrian Georgescu | |
1109 | ==== methods ==== |
||
1110 | |||
1111 | 94 | Adrian Georgescu | |
1112 | 1 | Adrian Georgescu | '''send'''(''self'', '''data'''):: |
1113 | Sends the specified data to the stream in order for it to be transported over MSRP to the remote endpoint. |
||
1114 | [[BR]]data:[[BR]] |
||
1115 | The RFB data to be transported over MSRP, in the form of a {{{str}}}. |
||
1116 | |||
1117 | ==== notifications ==== |
||
1118 | |||
1119 | 94 | Adrian Georgescu | |
1120 | 1 | Adrian Georgescu | '''DesktopSharingStreamGotData''':: |
1121 | This notification is sent when data is received over MSRP. |
||
1122 | [[BR]]data:[[BR]] |
||
1123 | The RFB data from the remote endpoint, in the form of a {{{str}}}. |
||
1124 | |||
1125 | === InternalVNCServerHandler === |
||
1126 | |||
1127 | 99 | Luci Stanescu | This is a concrete implementation of the {{{IDesktopSharingHandler}}} interface which can be used for a VNC server implemented within the application. |
1128 | 1 | Adrian Georgescu | |
1129 | ==== methods ==== |
||
1130 | |||
1131 | 94 | Adrian Georgescu | |
1132 | 1 | Adrian Georgescu | '''send'''(''self'', '''data'''):: |
1133 | Sends the specified data to the stream in order for it to be transported over MSRP to the remote endpoint. |
||
1134 | [[BR]]data:[[BR]] |
||
1135 | The RFB data to be transported over MSRP, in the form of a {{{str}}}. |
||
1136 | |||
1137 | ==== notifications ==== |
||
1138 | |||
1139 | 94 | Adrian Georgescu | |
1140 | 1 | Adrian Georgescu | '''DesktopSharingStreamGotData''':: |
1141 | This notification is sent when data is received over MSRP. |
||
1142 | [[BR]]data:[[BR]] |
||
1143 | The RFB data from the remote endpoint, in the form of a {{{str}}}. |
||
1144 | |||
1145 | === ExternalVNCViewerHandler === |
||
1146 | |||
1147 | This implementation of {{{IDesktopSharingHandler}}} can be used for an external VNC viewer which connects to a VNC server using TCP. |
||
1148 | |||
1149 | ==== methods ==== |
||
1150 | |||
1151 | 94 | Adrian Georgescu | |
1152 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''address'''={{{("localhost", 0)}}}, '''connect_timeout'''={{{3}}}):: |
1153 | This instantiates a new {{{ExternalVNCViewerHandler}}} which is listening on the provided address, ready for the external VNC viewer to connect to it via TCP. After this method returns, the attribute {{{address}}} can be used to find out exactly on what address and port the handler is listening on. The handler will only accept one conenction on this address. |
||
1154 | [[BR]]address:[[BR]] |
||
1155 | A tuple containing an IP address/hostname and a port on which the handler should listen. Any data received on this socket will then be forwarded to the stream and any data received from the stream will be forwarded to this socket. |
||
1156 | |||
1157 | 109 | Adrian Georgescu | ==== attributes ==== |
1158 | 1 | Adrian Georgescu | |
1159 | 94 | Adrian Georgescu | |
1160 | 1 | Adrian Georgescu | '''address''':: |
1161 | A tuple containing an IP address and a port on which the handler is listening. |
||
1162 | |||
1163 | === ExternalVNCServerHandler === |
||
1164 | |||
1165 | This implementation of {{{IDesktopSharingHandler}}} can be used for an external VNC server to which handler will connect using TCP. |
||
1166 | |||
1167 | ==== methods ==== |
||
1168 | |||
1169 | 94 | Adrian Georgescu | |
1170 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''address''', '''connect_timeout'''={{{3}}}):: |
1171 | This instantiates a new {{{ExternalVNCServerHandler}}} which will connect to the provided address on which a VNC server must be listening before the stream using this handler starts. |
||
1172 | [[BR]]address:[[BR]] |
||
1173 | A tuple containing an IP address/hostname and a port on which the VNC server will be listening. Any data received on this socket will then be forwared to the stream and any data received form the stream will be forwarded to this socket. |
||
1174 | [[BR]]connect_timeout:[[BR]] |
||
1175 | How long to wait to connect to the VNC server before giving up. |
||
1176 | |||
1177 | |||
1178 | === DesktopSharingStream === |
||
1179 | |||
1180 | Implemented in [browser:sipsimple/streams/msrp.py] |
||
1181 | |||
1182 | This stream implements desktop sharing using MSRP as a transport protocol for RFB data. |
||
1183 | |||
1184 | 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: |
||
1185 | |||
1186 | {{{ |
||
1187 | m=application 2855 TCP/TLS/MSRP * |
||
1188 | a=path:msrps://10.0.1.19:2855/b599b22d1b1d6a3324c8;tcp |
||
1189 | a=accept-types:application/x-rfb |
||
1190 | 118 | Adrian Georgescu | a=rfbsetup:active |
1191 | 1 | Adrian Georgescu | }}} |
1192 | |||
1193 | |||
1194 | ==== methods ==== |
||
1195 | |||
1196 | 94 | Adrian Georgescu | |
1197 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''acount''', '''handler'''):: |
1198 | Instantiate a new {{{DesktopSharingStream}}}. |
||
1199 | [[BR]]account:[[BR]] |
||
1200 | The {{{sipsimple.account.Account}}} or {{{sipsimple.account.BonjourAccount}}} instance this stream is associated with. |
||
1201 | [[BR]]handler:[[BR]] |
||
1202 | An object implementing the {{{IDesktopSharingHandler}}} interface which will act as the handler for RFB data. |
||
1203 | |||
1204 | ==== attributes ==== |
||
1205 | |||
1206 | 94 | Adrian Georgescu | |
1207 | 1 | Adrian Georgescu | '''handler''':: |
1208 | This is a writable property which can be used to get or set the object implementing {{{IDesktopSharingHandler}}} which acts as the handler for RFB data. For incoming {{{DesktopSharingStreams}}}, this must be set by the application before the stream starts. |
||
1209 | 94 | Adrian Georgescu | |
1210 | 1 | Adrian Georgescu | '''incoming_queue''':: |
1211 | A {{{eventlet.coros.queue}}} instance on which incoming RFB data is written. The handler should wait for data on this queue. |
||
1212 | 94 | Adrian Georgescu | |
1213 | 1 | Adrian Georgescu | '''outgoing_queue''':: |
1214 | A {{{eventlet.coros.queue}}} instance on which outgoing RFB data is written. The handler should write data on this queue. |
||
1215 | 84 | Adrian Georgescu | |
1216 | 85 | Adrian Georgescu | == Address Resolution == |
1217 | 84 | Adrian Georgescu | |
1218 | 130 | Adrian Georgescu | The SIP SIMPLE middleware offers the {{{sipsimple.lookup}}} module which contains an implementation for doing DNS lookups for SIP proxies, MSRP relays, STUN servers and XCAP servers. The interface offers both an asynchronous and synchronous interface. The asynchronous interface is based on notifications, while the synchronous one on green threads. In order to call the methods in a asynchronous manner, you just need to call the method and wait for the notification which is sent on behalf of the DNSLookup instance. The notifications sent by the DNSLookup object are DNSLookupDidSucceed and DNSLookupDidFail. In order to call the methods in a synchronous manner, you need to call the wait method on the object returned by the methods of DNSLookup. This wait method needs to be called from a green thread and will either return the result of the lookup or raise an exception. |
1219 | 1 | Adrian Georgescu | |
1220 | 130 | Adrian Georgescu | The DNSLookup object uses DNSManager, an object that will use the system nameservers and it will fallback to Google's nameservers (8.8.8.8 and 8.8.4.4) in case of failure. |
1221 | |||
1222 | === DNS Manager === |
||
1223 | |||
1224 | This object provides {{{DNSLookup}}} with the nameserver list that will be used to perform DNS lookups. It will probe the system local nameservers and check if they are able to do proper lookups (by querying sip2sip.info domain). If the local nameservers are not able to do proper lookups Google nameservers will be used and another probing operation will be scheduled. Local nameservers are always preferred. |
||
1225 | |||
1226 | ==== methods ==== |
||
1227 | |||
1228 | '''!__init!__'''(''self''):: |
||
1229 | Instantiate the DNSManager object (it's a Singleton). |
||
1230 | |||
1231 | '''start'''(''self''):: |
||
1232 | Start the DNSManager. It will start the probing process to determine the suitable nameservers to use. |
||
1233 | |||
1234 | '''stop'''(''self''):: |
||
1235 | 131 | Adrian Georgescu | Stop the DNS resolution probing. |
1236 | 130 | Adrian Georgescu | |
1237 | |||
1238 | ==== notifications ==== |
||
1239 | |||
1240 | '''DNSResolverDidInitialize''':: |
||
1241 | This notification is sent when the nameservers to use for probing (and further DNS lookups) have been set for the first time. |
||
1242 | [[BR]]timestamp:[[BR]] |
||
1243 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1244 | [[BR]]nameservers:[[BR]] |
||
1245 | The list of nameservers that was set on the DNS Manager. |
||
1246 | |||
1247 | '''DNSNameserversDidChange''':: |
||
1248 | This notification is sent when the nameservers to use for probing (and further DNS lookups) have changed as a result of the probing process. |
||
1249 | [[BR]]timestamp:[[BR]] |
||
1250 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1251 | [[BR]]nameservers:[[BR]] |
||
1252 | The list of nameservers that was set on the DNS Manager. |
||
1253 | |||
1254 | |||
1255 | 84 | Adrian Georgescu | === DNS Lookup === |
1256 | |||
1257 | This object implements DNS lookup support for SIP proxies according to RFC3263 and MSRP relay and STUN server lookup using SRV records. The object initially does NS record queries in order to determine the authoritative nameservers for the domain requested; these authoritative nameservers will then be used for NAPTR, SRV and A record queries. If this fails, the locally configured nameservers are used. The reason for doing this is that some home routers have broken NAPTR and/or SRV query support. |
||
1258 | |||
1259 | ==== methods ==== |
||
1260 | |||
1261 | 94 | Adrian Georgescu | |
1262 | 84 | Adrian Georgescu | '''!__init!__'''(''self''):: |
1263 | Instantiate a new DNSLookup object. |
||
1264 | 94 | Adrian Georgescu | |
1265 | 84 | Adrian Georgescu | '''lookup_service'''(''self'', '''uri''', '''service''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: |
1266 | Perform an SRV lookup followed by A lookups for MSRP relays or STUN servers depending on the {{{service}}} parameter. If SRV queries on the {{{uri.host}}} domain fail, an A lookup is performed on it and the default port for the service is returned. Only the {{{uri.host}}} attribute is used. The return value is a list of (host, port) tuples. |
||
1267 | [[BR]]uri:[[BR]] |
||
1268 | A {{{(Frozen)SIPURI}}} from which the {{{host}}} attribute is used for the query domain. |
||
1269 | [[BR]]service:[[BR]] |
||
1270 | The service to lookup servers for, {{{"msrprelay"}}} or {{{"stun"}}}. |
||
1271 | [[BR]]timeout:[[BR]] |
||
1272 | How many seconds to wait for a response from a nameserver. |
||
1273 | [[BR]]lifetime:[[BR]] |
||
1274 | How many seconds to wait for a response from all nameservers in total. |
||
1275 | 94 | Adrian Georgescu | |
1276 | 84 | Adrian Georgescu | '''lookup_sip_proxy'''(''self'', '''uri''', '''supported_transports''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: |
1277 | Perform a RFC3263 compliant DNS lookup for a SIP proxy using the URI which is considered to point to a host if either the {{{host}}} attribute is an IP address, or the {{{port}}} is present. Otherwise, it is considered a domain for which NAPTR, SRV and A lookups are performed. If NAPTR or SRV queries fail, they fallback to using SRV and A queries. If the transport parameter is present in the URI, this will be used as far as it is part of the supported transports. If the URI has a {{{sips}}} schema, then only the TLS transport will be used as far as it doesn't conflict with the supported transports or the transport parameter. The return value is a list of {{{Route}}} objects containing the IP address, port and transport to use for routing in the order of preference given by the supported_transports argument. |
||
1278 | [[BR]]uri:[[BR]] |
||
1279 | A {{{(Frozen)SIPURI}}} from which the {{{host}}}, {{{port}}}, {{{parameters}}} and {{{secure}}} attributes are used. |
||
1280 | [[BR]]supported_transports:[[BR]] |
||
1281 | A sublist of {{{['udp', 'tcp', 'tls']}}} in the application's order of preference. |
||
1282 | [[BR]]timeout:[[BR]] |
||
1283 | How many seconds to wait for a response from a nameserver. |
||
1284 | [[BR]]lifetime:[[BR]] |
||
1285 | How many seconds to wait for a response from all nameservers in total. |
||
1286 | |||
1287 | 120 | Luci Stanescu | '''lookup_xcap_server'''(''self'', '''uri''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: |
1288 | Perform a TXT DNS query on xcap.<uri.host> and return all values of the TXT record which are URIs with a scheme of http or https. Only the {{{uri.host}}} attribute is used. The return value is a list of strings representing HTTP URIs. |
||
1289 | [[BR]]uri:[[BR]] |
||
1290 | A {{{(Frozen)SIPURI}}} from which the {{{host}}} attribute is used for the query domain. |
||
1291 | [[BR]]timeout:[[BR]] |
||
1292 | How many seconds to wait for a response from a nameserver. |
||
1293 | [[BR]]lifetime:[[BR]] |
||
1294 | How many seconds to wait for a response from all nameservers in total. |
||
1295 | |||
1296 | 84 | Adrian Georgescu | |
1297 | ==== notifications ==== |
||
1298 | 94 | Adrian Georgescu | |
1299 | 84 | Adrian Georgescu | |
1300 | '''DNSLookupDidSucceed''':: |
||
1301 | This notification is sent when one of the lookup methods succeeds in finding a result. |
||
1302 | [[BR]]timestamp:[[BR]] |
||
1303 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1304 | [[BR]]result:[[BR]] |
||
1305 | 94 | Adrian Georgescu | The result of the DNS lookup in the format described in each method. |
1306 | 84 | Adrian Georgescu | |
1307 | '''DNSLookupDidFail''':: |
||
1308 | This notification is sent when one of the lookup methods fails in finding a result. |
||
1309 | [[BR]]timestamp:[[BR]] |
||
1310 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1311 | [[BR]]error:[[BR]] |
||
1312 | 94 | Adrian Georgescu | A {{{str}}} object describing the error which resulted in the DNS lookup failure. |
1313 | 84 | Adrian Georgescu | |
1314 | '''DNSLookupTrace''':: |
||
1315 | This notification is sent several times during a lookup process for each individual DNS query. |
||
1316 | [[BR]]timestamp:[[BR]] |
||
1317 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1318 | [[BR]]query_type:[[BR]] |
||
1319 | The type of the query, {{{"NAPTR"}}}, {{{"SRV"}}}, {{{"A"}}}, {{{"NS"}}} etc. |
||
1320 | [[BR]]query_name:[[BR]] |
||
1321 | The name which was queried. |
||
1322 | [[BR]]answer:[[BR]] |
||
1323 | The answer returned by dnspython, or {{{None}}} if an error occurred. |
||
1324 | [[BR]]error:[[BR]] |
||
1325 | The exception which caused the query to fail, or {{{None}}} if no error occurred. |
||
1326 | [[BR]]context:[[BR]] |
||
1327 | The name of the method which was called on the {{{DNSLookup}}} object. |
||
1328 | [[BR]]service:[[BR]] |
||
1329 | 1 | Adrian Georgescu | The service which was queried for, only available when context is {{{"lookup_service"}}}. |
1330 | [[BR]]uri:[[BR]] |
||
1331 | 130 | Adrian Georgescu | The uri which was queried for. |
1332 | [[BR]]nameservers:[[BR]] |
||
1333 | The list of nameservers that was used to perform the lookup. |
||
1334 | |||
1335 | 84 | Adrian Georgescu | |
1336 | === Route === |
||
1337 | |||
1338 | This is a convinience object which contains sufficient information to identify a route to a SIP proxy. This object is returned by {{{DNSLookup.lookup_sip_proxy}}} and can be used with the {{{Session}}} or a {{{(Frozen)RouteHeader}}} can be easily constructed from it to pass to one of the objects in the SIP core handling SIP dialogs/transactions ({{{Invitation}}}, {{{Subscription}}}, {{{Request}}}, {{{Registration}}}, {{{Message}}}, {{{Publication}}}). This object has three attributes which can be set in the constructor or after it was instantiated. They will only be documented as arguments to the constructor. |
||
1339 | |||
1340 | ==== methods ==== |
||
1341 | |||
1342 | 94 | Adrian Georgescu | |
1343 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''address''', '''port'''=None, '''transport'''={{{'udp'}}}):: |
1344 | Creates the Route object with the specified parameters as attributes. |
||
1345 | Each of these attributes can be accessed on the object once instanced. |
||
1346 | [[BR]]''address'':[[BR]] |
||
1347 | The IPv4 address that the request in question should be sent to as a string. |
||
1348 | [[BR]]''port'':[[BR]] |
||
1349 | The port to send the requests to, represented as an int, or None if the default port is to be used. |
||
1350 | [[BR]]''transport'':[[BR]] |
||
1351 | The transport to use, this can be a string of either "udp", "tcp" or "tls" (case insensitive). |
||
1352 | 94 | Adrian Georgescu | |
1353 | 1 | Adrian Georgescu | '''get_uri'''(''self''):: |
1354 | Returns a {{{SIPURI}}} object which contains the adress, port and transport as parameter. This can be used to easily construct a {{{RouteHeader}}}: |
||
1355 | {{{ |
||
1356 | route = Route("1.2.3.4", port=1234, transport="tls") |
||
1357 | route_header = RouteHeader(route.get_uri()) |
||
1358 | }}} |
||
1359 | |||
1360 | |||
1361 | 92 | Adrian Georgescu | == SIP Accounts == |
1362 | 1 | Adrian Georgescu | |
1363 | Account Management is implemented in [browser:sipsimple/account.py] ({{{sipsimple.account}}} module) and offers support for SIP accounts registered at SIP providers and SIP bonjour accounts which are discovered using mDNS. |
||
1364 | |||
1365 | 91 | Adrian Georgescu | === AccountManager === |
1366 | |||
1367 | 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. |
||
1368 | |||
1369 | ==== methods ==== |
||
1370 | |||
1371 | 94 | Adrian Georgescu | |
1372 | 91 | Adrian Georgescu | '''!__init!__'''(''self''):: |
1373 | 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. |
||
1374 | 94 | Adrian Georgescu | |
1375 | 91 | Adrian Georgescu | '''start'''(''self''):: |
1376 | 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. This method is called automatically by the SIPApplication when it initializes all the components of the middleware. |
||
1377 | 94 | Adrian Georgescu | |
1378 | 91 | Adrian Georgescu | '''stop'''(''self''):: |
1379 | Calling this method will deactivate all accounts managed by the {{{AccountManager}}}. This method is called automatically by the SIPApplication when it stops. |
||
1380 | 94 | Adrian Georgescu | |
1381 | 91 | Adrian Georgescu | '''has_account'''(''self'', '''id'''):: |
1382 | This method returns {{{True}}} if an account which has the specifed SIP ID (must be a string) exists and {{{False}}} otherwise. |
||
1383 | 94 | Adrian Georgescu | |
1384 | 91 | Adrian Georgescu | '''get_account'''(''self'', '''id'''):: |
1385 | 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. |
||
1386 | 94 | Adrian Georgescu | |
1387 | 91 | Adrian Georgescu | '''get_accounts'''(''self''):: |
1388 | Returns a list containing all the managed accounts. |
||
1389 | 94 | Adrian Georgescu | |
1390 | 91 | Adrian Georgescu | '''iter_accounts'''(''self''):: |
1391 | Returns an iterator through all the managed accounts. |
||
1392 | 94 | Adrian Georgescu | |
1393 | 91 | Adrian Georgescu | '''find_account'''(''self'', '''contact_uri'''):: |
1394 | 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. |
||
1395 | |||
1396 | ==== notifications ==== |
||
1397 | |||
1398 | 94 | Adrian Georgescu | |
1399 | 91 | Adrian Georgescu | '''SIPAccountManagerDidAddAccount''':: |
1400 | 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. |
||
1401 | [[BR]]''timestamp'':[[BR]] |
||
1402 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1403 | [[BR]]''account'':[[BR]] |
||
1404 | The account object which was added. |
||
1405 | 94 | Adrian Georgescu | |
1406 | 91 | Adrian Georgescu | '''SIPAccountManagerDidRemoveAccount''':: |
1407 | This notification is sent when an account is deleted using the {{{delete}}} method. |
||
1408 | [[BR]]''timestamp'':[[BR]] |
||
1409 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1410 | [[BR]]''account'':[[BR]] |
||
1411 | The account object which was deleted. |
||
1412 | 94 | Adrian Georgescu | |
1413 | 91 | Adrian Georgescu | '''SIPAccountManagerDidChangeDefaultAccount''':: |
1414 | This notification is sent when the default account changes. |
||
1415 | [[BR]]''timestamp'':[[BR]] |
||
1416 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1417 | [[BR]]''old_account'':[[BR]] |
||
1418 | This is the account object which used to be the default account. |
||
1419 | [[BR]]''account'':[[BR]] |
||
1420 | This is the account object which is the new default account. |
||
1421 | |||
1422 | 72 | Luci Stanescu | === Account === |
1423 | |||
1424 | 64 | Luci Stanescu | The {{{sipsimple.account.Account}}} objects represent the SIP accounts which are registered at SIP providers. 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]. |
1425 | |||
1426 | 72 | 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}}}. |
1427 | 64 | Luci Stanescu | |
1428 | ==== states ==== |
||
1429 | |||
1430 | 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: |
||
1431 | {{{ |
||
1432 | account.enabled = True |
||
1433 | account.save() |
||
1434 | }}} |
||
1435 | |||
1436 | 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. |
||
1437 | |||
1438 | 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. |
||
1439 | |||
1440 | 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: |
||
1441 | |||
1442 | 94 | Adrian Georgescu | |
1443 | 64 | Luci Stanescu | '''Account.registration.enabled''':: |
1444 | This flag controls the automatic registration of the account. The notifications '''SIPAccountRegistrationDidSucceed''', '''SIPAccountRegistrationDidFail''' and '''SIPAccountRegistrationDidEnd''' are used to inform the status of this registration. |
||
1445 | 94 | Adrian Georgescu | |
1446 | 64 | Luci Stanescu | '''Account.presence.enabled''':: |
1447 | This flag controls the automatic subscription to buddies for the ''presence'' event and the publication of data in this event. (Not implemented yet) |
||
1448 | 94 | Adrian Georgescu | |
1449 | 1 | Adrian Georgescu | '''Account.dialog_event.enabled''':: |
1450 | 64 | 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) |
1451 | 94 | Adrian Georgescu | |
1452 | 64 | Luci Stanescu | '''Account.message_summary.enabled''':: |
1453 | This flag controls the automatic subscription to the ''message-summary'' event in order to find out about voicemail messages. (Not implemented yet) |
||
1454 | |||
1455 | 72 | 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]. |
1456 | 64 | Luci Stanescu | |
1457 | ==== attributes ==== |
||
1458 | |||
1459 | The following attributes can be used on an Account object and need to be considered read-only. |
||
1460 | |||
1461 | 94 | Adrian Georgescu | |
1462 | 64 | Luci Stanescu | '''id''':: |
1463 | 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}}}. |
||
1464 | {{{ |
||
1465 | account.id # 'alice@example.com' |
||
1466 | account.id.username # 'alice' |
||
1467 | account.id.domain # 'example.com' |
||
1468 | }}} |
||
1469 | 94 | Adrian Georgescu | |
1470 | 64 | Luci Stanescu | '''contact''':: |
1471 | 134 | Adrian Georgescu | 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.ContactURIFactory}}}. It can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}}, {{{'tls'}}}) or a {{{sipsimple.util.Route}}} object which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate IP, port and transport. The username part is a randomly generated 8 character string consisting of lowercase letters; but it can be chosen by passing it to __init__ when building the {{{ContactURIFactory}}} object. |
1472 | 1 | Adrian Georgescu | {{{ |
1473 | 134 | Adrian Georgescu | account.contact # 'ContactURIFactory(username=hnfkybrt)' |
1474 | 1 | Adrian Georgescu | account.contact.username # 'hnfkybrt' |
1475 | account.contact['udp'] # <SIPURI "sip:hnfkybrt@10.0.0.1:53024"> |
||
1476 | account.contact['tls'] # <SIPURI "sip:hnfkybrt@10.0.0.1:54478;transport=tls"> |
||
1477 | 72 | Luci Stanescu | }}} |
1478 | 94 | Adrian Georgescu | |
1479 | 1 | Adrian Georgescu | '''credentials''':: |
1480 | 72 | Luci Stanescu | This attribute is of type {{{sipsimple.core.Credentials}}} which is built from the {{{id.username}}} attribute and the {{{password}}} setting of the Account. Whenever this setting is changed, this attribute is updated. |
1481 | 64 | Luci Stanescu | {{{ |
1482 | 72 | Luci Stanescu | account.credentials # <Credentials for 'alice'> |
1483 | }}} |
||
1484 | 94 | Adrian Georgescu | |
1485 | 72 | Luci Stanescu | '''uri''':: |
1486 | This attribute is of type {{{sipsimple.core.SIPURI}}} which can be used to form a {{{FromHeader}}} associated with this account. It contains the SIP ID of the account. |
||
1487 | {{{ |
||
1488 | 1 | Adrian Georgescu | account.uri # <SIPURI "sip:alice@example.com"> |
1489 | 72 | Luci Stanescu | }}} |
1490 | 1 | Adrian Georgescu | |
1491 | ==== notifications ==== |
||
1492 | |||
1493 | 94 | Adrian Georgescu | |
1494 | 1 | Adrian Georgescu | '''CFGSettingsObjectDidChange''':: |
1495 | 72 | 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]. |
1496 | 94 | Adrian Georgescu | |
1497 | 125 | Adrian Georgescu | '''SIPAccountWillActivate''':: |
1498 | This notification is sent when the {{{Account}}} is about to be activated, but before actually performing any activation task. See {{{SIPAccountDidActivate}}} for more detail. |
||
1499 | [[BR]]''timestamp'':[[BR]] |
||
1500 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1501 | |||
1502 | 72 | Luci Stanescu | '''SIPAccountDidActivate''':: |
1503 | 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. |
||
1504 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1505 | 72 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1506 | 94 | Adrian Georgescu | |
1507 | 125 | Adrian Georgescu | '''SIPAccountWillDeactivate''':: |
1508 | This notification is sent when the {{{Account}}} is about to be deactivated, but before performing any deactivation task. See {{{SIPAccountDidDeactivate}}} for more detail. |
||
1509 | [[BR]]''timestamp'':[[BR]] |
||
1510 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1511 | |||
1512 | 72 | Luci Stanescu | '''SIPAccountDidDeactivate''':: |
1513 | 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}}}. |
||
1514 | [[BR]]''timestamp'':[[BR]] |
||
1515 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1516 | 94 | Adrian Georgescu | |
1517 | 117 | Adrian Georgescu | '''SIPAccountWillRegister''':: |
1518 | 72 | Luci Stanescu | This notification is sent when the account is about to register for the first time. |
1519 | [[BR]]''timestamp'':[[BR]] |
||
1520 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1521 | 94 | Adrian Georgescu | |
1522 | 117 | Adrian Georgescu | '''SIPAccountRegistrationWillRefresh''':: |
1523 | 72 | Luci Stanescu | This notification is sent when a registration is about to be refreshed. |
1524 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1525 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1526 | 94 | Adrian Georgescu | |
1527 | 72 | Luci Stanescu | '''SIPAccountRegistrationDidSucceed''':: |
1528 | 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: |
||
1529 | [[BR]]''timestamp'':[[BR]] |
||
1530 | 1 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1531 | [[BR]]''contact_header'':[[BR]] |
||
1532 | The Contact header which was registered. |
||
1533 | [[BR]]''contact_header_list'':[[BR]] |
||
1534 | A list containing all the contacts registered for this SIP account. |
||
1535 | [[BR]]''expires'':[[BR]] |
||
1536 | The amount in seconds in which this registration will expire. |
||
1537 | [[BR]]''registrar'':[[BR]] |
||
1538 | The {{{sipsimple.util.Route}}} object which was used. |
||
1539 | 94 | Adrian Georgescu | |
1540 | 1 | Adrian Georgescu | '''SIPAccountRegistrationDidFail''':: |
1541 | 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: |
||
1542 | [[BR]]''timestamp'':[[BR]] |
||
1543 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1544 | [[BR]]''error'':[[BR]] |
||
1545 | The reason for the failure of the REGISTER request. |
||
1546 | [[BR]]''timeout'':[[BR]] |
||
1547 | The amount in seconds as a {{{float}}} after which the registration will be tried again. |
||
1548 | 94 | Adrian Georgescu | |
1549 | 1 | Adrian Georgescu | '''SIPAccountRegistrationDidEnd''':: |
1550 | This notification is sent when a registration is ended (the account is unregistered). The data contained in this notification is: |
||
1551 | [[BR]]''timestamp'':[[BR]] |
||
1552 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1553 | [[BR]]''registration'':[[BR]] |
||
1554 | The {{{sipsimple.core.Registration}}} object which ended. |
||
1555 | 94 | Adrian Georgescu | |
1556 | 1 | Adrian Georgescu | '''SIPAccountRegistrationDidNotEnd''':: |
1557 | This notification is sent when a registration fails to end (the account is not unregistered). The data contained in this notification is: |
||
1558 | [[BR]]''timestamp'':[[BR]] |
||
1559 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1560 | [[BR]]''code'':[[BR]] |
||
1561 | The SIP status code received. |
||
1562 | [[BR]]''reason'':[[BR]] |
||
1563 | The SIP status reason received. |
||
1564 | [[BR]]''registration'':[[BR]] |
||
1565 | The {{{sipsimple.core.Registration}}} object which ended. |
||
1566 | 94 | Adrian Georgescu | |
1567 | 1 | Adrian Georgescu | '''SIPAccountRegistrationGotAnswer''':: |
1568 | This notification is sent whenever a response is received to a sent REGISTER request for this account. The data contained in this notification is: |
||
1569 | [[BR]]''timestamp'':[[BR]] |
||
1570 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1571 | [[BR]]''code'':[[BR]] |
||
1572 | The SIP status code received. |
||
1573 | [[BR]]''reason'':[[BR]] |
||
1574 | The SIP status reason received. |
||
1575 | [[BR]]''registration'':[[BR]] |
||
1576 | The {{{sipsimple.core.Registration}}} object which was used. |
||
1577 | [[BR]]''registrar'':[[BR]] |
||
1578 | The {{{sipsimple.util.Route}}} object which was used. |
||
1579 | |||
1580 | 122 | Adrian Georgescu | '''SIPAccountMWIDidGetSummary''':: |
1581 | 121 | Adrian Georgescu | This notification is sent when a NOTIFY is received with a message-summary payload. The data contained in this notification is: |
1582 | 122 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1583 | 121 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1584 | 122 | Adrian Georgescu | [[BR]]''message_summary'':[[BR]] |
1585 | 121 | Adrian Georgescu | A {{{sipsimple.payloads.messagesummary.MessageSummary}}} object with the parsed payload from the NOTIFY request. |
1586 | |||
1587 | 1 | Adrian Georgescu | === BonjourAccount === |
1588 | |||
1589 | 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. |
||
1590 | |||
1591 | ==== states ==== |
||
1592 | |||
1593 | 112 | Luci Stanescu | The {{{BonjourAccount}}} has an {{{enabled}}} flag 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 and discover its neighbours sending notifications as this happens. |
1594 | 1 | Adrian Georgescu | |
1595 | ==== attributes ==== |
||
1596 | |||
1597 | The following attributes can be used on a BonjourAccount object and need to be considered read-only. |
||
1598 | |||
1599 | 94 | Adrian Georgescu | |
1600 | 1 | Adrian Georgescu | '''id''':: |
1601 | 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}}}. |
||
1602 | {{{ |
||
1603 | bonjour_account.id # 'bonjour@local' |
||
1604 | bonjour_account.id.username # 'bonjour' |
||
1605 | bonjour_account.id.domain # 'local' |
||
1606 | }}} |
||
1607 | |||
1608 | '''contact''':: |
||
1609 | 134 | Adrian Georgescu | 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.ContactURIFactory}}}. It can be indexed by a string representing a transport ({{{'udp'}}}, {{{'tcp'}}}, {{{'tls'}}}) or a {{{sipsimple.util.Route}}} object which will return a {{{sipsimple.core.SIPURI}}} object with the appropriate IP, port and transport. The username part is a randomly generated 8 character string consisting of lowercase letters; but it can be chosen by passing it to __init__ when building the {{{ContactURIFactory}}} object. |
1610 | 1 | Adrian Georgescu | {{{ |
1611 | 134 | Adrian Georgescu | bonjour_account.contact # 'ContactURIFactory(username=lxzvgack)' |
1612 | 1 | Adrian Georgescu | bonjour_account.contact.username # 'lxzvgack' |
1613 | bonjour_account.contact['udp'] # <SIPURI "sip:lxzvgack@10.0.0.1:53024"> |
||
1614 | bonjour_account.contact['tls'] # <SIPURI "sip:lxzvgack@10.0.0.1:54478;transport=tls"> |
||
1615 | }}} |
||
1616 | 94 | Adrian Georgescu | |
1617 | 1 | Adrian Georgescu | '''credentials''':: |
1618 | This attribute is of type {{{sipsimple.core.Credentials}}} object which is built from the {{{contact.username}}} attribute; the password is set to the empty string. |
||
1619 | {{{ |
||
1620 | bonjour_account.credentials # <Credentials for 'alice'> |
||
1621 | }}} |
||
1622 | 94 | Adrian Georgescu | |
1623 | 1 | Adrian Georgescu | '''uri''':: |
1624 | 111 | Adrian Georgescu | This attribute is of type {{{sipsimple.core.SIPURI}}} which can be used to form a {{{FromHeader}}} associated with this account. It contains the contact address of the bonjour account: |
1625 | 1 | Adrian Georgescu | {{{ |
1626 | bonjour_account.uri # <SIPURI "sip:lxzvgack@10.0.0.1"> |
||
1627 | }}} |
||
1628 | |||
1629 | ==== notifications ==== |
||
1630 | |||
1631 | 127 | Adrian Georgescu | '''BonjourAccountDidAddNeighbour''':: |
1632 | This notification is sent when a new Bonjour neighbour is discovered. |
||
1633 | 129 | Adrian Georgescu | [[BR]]''service_description'':[[BR]] |
1634 | BonjourServiceDescription object uniquely identifying this neighbour in the mDNS library. |
||
1635 | 127 | Adrian Georgescu | [[BR]]''display_name'':[[BR]] |
1636 | The name of the neighbour as it is published. |
||
1637 | [[BR]]''host'':[[BR]] |
||
1638 | The hostname of the machine from which the Bonjour neighbour registered its contact address. |
||
1639 | [[BR]]''uri'':[[BR]] |
||
1640 | The contact URI of the Bonjour neighbour, as a {{{FrozenSIPURI}}} object. |
||
1641 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1642 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1643 | |||
1644 | 129 | Adrian Georgescu | '''BonjourAccountDidUpdateNeighbour''':: |
1645 | This notification is sent when an existing Bonjour neighbour has updates its published data. |
||
1646 | [[BR]]''service_description'':[[BR]] |
||
1647 | BonjourServiceDescription object uniquely identifying this neighbour in the mDNS library. |
||
1648 | [[BR]]''display_name'':[[BR]] |
||
1649 | The name of the neighbour as it is published. |
||
1650 | [[BR]]''host'':[[BR]] |
||
1651 | The hostname of the machine from which the Bonjour neighbour registered its contact address. |
||
1652 | 1 | Adrian Georgescu | [[BR]]''uri'':[[BR]] |
1653 | The contact URI of the Bonjour neighbour, as a {{{FrozenSIPURI}}} object. |
||
1654 | [[BR]]''timestamp'':[[BR]] |
||
1655 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1656 | |||
1657 | 129 | Adrian Georgescu | '''BonjourAccountDidRemoveNeighbour''':: |
1658 | This notification is sent when a Bonjour neighbour unregisters. |
||
1659 | [[BR]]''service_description'':[[BR]] |
||
1660 | The BonjourServiceDescription object, which uniquely identifies a neighbour, that got unregistered. |
||
1661 | |||
1662 | 1 | Adrian Georgescu | '''BonjourAccountDiscoveryDidFail''':: |
1663 | 129 | Adrian Georgescu | This notification is sent once per transport when the Bonjour account has failed to perform the discovery process for the indicated transport. |
1664 | [[BR]]''reason'':[[BR]] |
||
1665 | String defining the reason of the failure. |
||
1666 | [[BR]]''transport'':[[BR]] |
||
1667 | String specifying the transport for which the discovery failed. |
||
1668 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1669 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1670 | |||
1671 | '''BonjourAccountDiscoveryFailure''':: |
||
1672 | 129 | Adrian Georgescu | This notification is sent once per transport when the Bonjour account has encountered a problem while browsing the list of neighbours for the indicated transport. |
1673 | [[BR]]''error'':[[BR]] |
||
1674 | String defining the error of the failure. |
||
1675 | [[BR]]''transport'':[[BR]] |
||
1676 | String specifying the transport for which the neighbour resoution failed. |
||
1677 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1678 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1679 | 124 | Adrian Georgescu | |
1680 | 1 | Adrian Georgescu | '''BonjourAccountRegistrationDidEnd''':: |
1681 | 129 | Adrian Georgescu | This notification is sent once per transport when the Bonjour account unregisters its contact address for the indicated transport using mDNS. |
1682 | [[BR]]''transport'':[[BR]] |
||
1683 | String specifying the transport for which the registration ended. |
||
1684 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1685 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1686 | |||
1687 | 127 | Adrian Georgescu | '''BonjourAccountRegistrationDidFail''':: |
1688 | 129 | Adrian Georgescu | This notification is sent once per transport when the Bonjour account fails to register its contact address for the indicated transport using mDNS. |
1689 | 1 | Adrian Georgescu | [[BR]]''reason'':[[BR]] |
1690 | A human readable error message. |
||
1691 | 129 | Adrian Georgescu | [[BR]]''transport'':[[BR]] |
1692 | String specifying the transport for which the registration failed. |
||
1693 | [[BR]]''timestamp'':[[BR]] |
||
1694 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1695 | 1 | Adrian Georgescu | |
1696 | 129 | Adrian Georgescu | '''BonjourAccountRegistrationUpdateDidFail''':: |
1697 | This notification is sent once per transport when the Bonjour account fails to update its data for the indicated transport using mDNS. |
||
1698 | [[BR]]''reason'':[[BR]] |
||
1699 | A human readable error message. |
||
1700 | [[BR]]''transport'':[[BR]] |
||
1701 | String specifying the transport for which the registration update failed. |
||
1702 | [[BR]]''timestamp'':[[BR]] |
||
1703 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1704 | |||
1705 | 1 | Adrian Georgescu | '''BonjourAccountRegistrationDidSucceed''':: |
1706 | 129 | Adrian Georgescu | This notification is sent once per transport when the Bonjour account successfully registers its contact address for the indicated transport using mDNS. |
1707 | 1 | Adrian Georgescu | [[BR]]''name'':[[BR]] |
1708 | 127 | Adrian Georgescu | The contact address registered. |
1709 | 129 | Adrian Georgescu | [[BR]]''transport'':[[BR]] |
1710 | String specifying the transport for which the registration succeeded. |
||
1711 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1712 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1713 | |||
1714 | 112 | Luci Stanescu | '''BonjourAccountWillInitateDiscovery''':: |
1715 | 129 | Adrian Georgescu | This notification is sent when the Bonjour account is about to start the discovery process for the indicated transport. |
1716 | [[BR]]''transport'':[[BR]] |
||
1717 | String specifying the transport for which the discovery will be started. |
||
1718 | 127 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1719 | 112 | Luci Stanescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1720 | |||
1721 | '''BonjourAccountWillRegister''':: |
||
1722 | 129 | Adrian Georgescu | This notification is sent just before the Bonjour account starts the registering process for the indicated transport. |
1723 | [[BR]]''transport'':[[BR]] |
||
1724 | String specifying the transport for which the registration will be started. |
||
1725 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1726 | 127 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1727 | 112 | Luci Stanescu | |
1728 | '''CFGSettingsObjectDidChange''':: |
||
1729 | 94 | Adrian Georgescu | 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]. |
1730 | 125 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1731 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1732 | |||
1733 | '''SIPAccountWillActivate''':: |
||
1734 | This notification is sent when the {{{BonjourAccount}}} is about to be activated, but before actually performing any activation task. See {{{SIPAccountDidActivate}}} for more detail. |
||
1735 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1736 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1737 | 125 | Adrian Georgescu | |
1738 | '''SIPAccountDidActivate''':: |
||
1739 | 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. |
||
1740 | [[BR]]''timestamp'':[[BR]] |
||
1741 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1742 | 1 | Adrian Georgescu | |
1743 | '''SIPAccountWillDeactivate''':: |
||
1744 | 94 | Adrian Georgescu | This notification is sent when the {{{BonjourAccount}}} is about to be deactivated, but before performing any deactivation task. See {{{SIPAccountDidDeactivate}}} for more detail. |
1745 | 1 | Adrian Georgescu | [[BR]]''timestamp'':[[BR]] |
1746 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1747 | |||
1748 | '''SIPAccountDidDeactivate''':: |
||
1749 | 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}}}. |
||
1750 | [[BR]]''timestamp'':[[BR]] |
||
1751 | 87 | Adrian Georgescu | A {{{datetime.datetime}}} object indicating when the notification was sent. |
1752 | |||
1753 | |||
1754 | == Audio == |
||
1755 | |||
1756 | The high-level audio API hides the complexity of using the low-level PJMEDIA interface. This is implemented in the {{{sipsimple.audio}}} module and contains the following components: |
||
1757 | * IAudioPort: an interface describing an object capable of producing and/or consuming audio data. |
||
1758 | * AudioDevice: an object conforming to the IAudioPort interface which describes a physical audio device. |
||
1759 | * AudioBridge: a collection of objects conforming to IAudioPort which connects all of them in a full mesh. |
||
1760 | * WavePlayer: an object conforming to the IAudioPort interface which can playback the audio data from a {{{.wav}}} file. |
||
1761 | * WaveRecorder: an object conforming to the IAudioPort interface which can record audio data to a {{{.wav}}} file. |
||
1762 | |||
1763 | === IAudioPort === |
||
1764 | |||
1765 | The IAudioPort interface describes an object capable of producing and/or consuming audio data. This can be a dynamic object, which changes its role during its lifetime and notifies such changes using a notification, which is part of the interface. |
||
1766 | 94 | Adrian Georgescu | |
1767 | 87 | Adrian Georgescu | ==== attributes ==== |
1768 | |||
1769 | 94 | Adrian Georgescu | |
1770 | 87 | Adrian Georgescu | '''mixer''':: |
1771 | The {{{AudioMixer}}} this audio object is connected to. Only audio objects connected to the same mixer will be able to send audio data from one to another. |
||
1772 | 94 | Adrian Georgescu | |
1773 | 87 | Adrian Georgescu | '''consumer_slot''':: |
1774 | An integer representing the slot (see [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to consume audio data, or {{{None}}} if this object is not a consumer. |
||
1775 | |||
1776 | '''producer_slot''':: |
||
1777 | An integer representing the slot (see [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to produce audio data, or {{{None}}} if this object is not a producer. |
||
1778 | 94 | Adrian Georgescu | |
1779 | 87 | Adrian Georgescu | ==== notifications ==== |
1780 | |||
1781 | |||
1782 | '''AudioPortDidChangeSlots''':: |
||
1783 | This notification needs to be sent by implementations of this interface when the slots it has change, so as to let the {{{AudioBridges}}} it is part of know that reconnections need to be made. |
||
1784 | [[BR]]consumer_slot_changed:[[BR]] |
||
1785 | A bool indicating whether the consumer slot was changed. |
||
1786 | [[BR]]producer_slot_changed:[[BR]] |
||
1787 | A bool indicating whether the producer slot was changed. |
||
1788 | [[BR]]old_consumer_slot:[[BR]] |
||
1789 | The old slot for consuming audio data. Only required if consumer_slot_changed is {{{True}}}. |
||
1790 | [[BR]]new_consumer_slot:[[BR]] |
||
1791 | The new slot for consuming audio data. Only required if consumer_slot_changed is {{{True}}}. |
||
1792 | [[BR]]old_producer_slot:[[BR]] |
||
1793 | The old slot for producing audio data. Only required if producer_slot_changed is {{{True}}}. |
||
1794 | [[BR]]new_producer_slot:[[BR]] |
||
1795 | The new slot for producing audio data. Only required if producer_slot_changed is {{{True}}}. |
||
1796 | |||
1797 | === AudioDevice === |
||
1798 | |||
1799 | The AudioDevice represents the physical audio device which is part of a {{{AudioMixer}}}, implementing the {{{IAudioPort}}} interface. As such, it can be uniquely identified by the mixer it represents. |
||
1800 | 94 | Adrian Georgescu | |
1801 | 87 | Adrian Georgescu | ==== methods ==== |
1802 | |||
1803 | |||
1804 | '''!__init!__'''(''self'', '''mixer''', '''input_muted'''={{{False}}}, '''output_muted'''={{{False}}}): |
||
1805 | Instantiates a new AudioDevice which represents the physical device associated with the specified {{{AudioMixer}}}. |
||
1806 | [[BR]]mixer:[[BR]] |
||
1807 | The {{{AudioMixer}}} whose physical device this object represents. |
||
1808 | [[BR]]input_muted:[[BR]] |
||
1809 | A boolean which indicates whether this object should act as a producer of audio data. |
||
1810 | [[BR]]output_muted:[[BR]] |
||
1811 | A boolean which indicates whether this object should act as a consumer of audio data. |
||
1812 | 94 | Adrian Georgescu | |
1813 | 87 | Adrian Georgescu | ==== attributes ==== |
1814 | |||
1815 | 94 | Adrian Georgescu | |
1816 | 87 | Adrian Georgescu | '''input_muted''':: |
1817 | A writable property which controls whether this object should act as a producer of audio data. An {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within the {{{AudioBridges}}} this object is part of. |
||
1818 | |||
1819 | '''output_muted''':: |
||
1820 | A writable property which controls whether this object should act as a consumer of audio data. An {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within the {{{AudioBridges}}} this object is part of. |
||
1821 | |||
1822 | === AudioBridge === |
||
1823 | |||
1824 | The {{{AudioBridge}}} is the basic component which is able to connect {{{IAudioPort}}} implementations. It acts as a container which connects as the producers to all the consumers which are part of it. An object which is both a producer and a consumer of audio data will not be connected to itself. Being an implementation of {{{IAudioPort}}} itself, an {{{AudioBridge}}} can be part of another {{{AudioBridge}}}. The {{{AudioBridge}}} does not keep strong references to the ports it contains and once the port's reference count reaches 0, it is automatically removed from the {{{AudioBridge}}}. |
||
1825 | > Note: although this is not enforced, there should never be any cycles when connecting {{{AudioBridges}}}. |
||
1826 | 94 | Adrian Georgescu | |
1827 | 87 | Adrian Georgescu | ==== methods ==== |
1828 | |||
1829 | 94 | Adrian Georgescu | |
1830 | 87 | Adrian Georgescu | '''!__init!__'''(''self'', '''mixer'''):: |
1831 | Instantiate a new {{{AudioBridge}}} which uses the specified {{{AudioMixer}}} for mixing. |
||
1832 | 94 | Adrian Georgescu | |
1833 | 87 | Adrian Georgescu | '''add'''(''self'', '''port'''):: |
1834 | Add an implementation of {{{IAudioPort}}} to this AudioBridge. This will connect the new port to all the existing ports of the bridge. A port cannot be added more than once to an {{{AudioBridge}}}; thus, this object acts like a set. |
||
1835 | |||
1836 | '''remove'''(''self'', '''port'''):: |
||
1837 | Remove a port from this {{{AudioBridge}}}. The port must have previously been added to the {{{AudioBridge}}}, otherwise a {{{ValueError}}} is raised. |
||
1838 | |||
1839 | === WavePlayer === |
||
1840 | |||
1841 | A {{{WavePlayer}}} is an implementation of {{{IAudioPort}}} which is capable of producing audio data read from a {{{.wav}}} file. This object is completely reusable, as it can be started and stopped any number of times. |
||
1842 | 94 | Adrian Georgescu | |
1843 | 87 | Adrian Georgescu | ==== methods ==== |
1844 | |||
1845 | |||
1846 | '''!__init!__'''(''self'', '''mixer''', '''filename''', '''volume'''={{{100}}}, '''loop_count'''={{{1}}}, '''pause_time'''={{{0}}}, '''initial_play'''={{{True}}}):: |
||
1847 | Instantiate a new {{{WavePlayer}}} which is capable of playing a {{{.wav}}} file repeatedly. All the parameters are available as attributes of the object, but should not be changed once the object has been started. |
||
1848 | [[BR]]mixer:[[BR]] |
||
1849 | The {{{AudioMixer}}} this object is connected to. |
||
1850 | [[BR]]filename:[[BR]] |
||
1851 | The full path to the {{{.wav}}} file from which audio data is to be read. |
||
1852 | [[BR]]volume:[[BR]] |
||
1853 | The volume at which the file should be played. |
||
1854 | [[BR]]loop_count:[[BR]] |
||
1855 | The number of times the file should be played, or {{{0}}} for infinity. |
||
1856 | [[BR]]pause_time:[[BR]] |
||
1857 | 94 | Adrian Georgescu | How many seconds to wait between successive plays of the file. |
1858 | 87 | Adrian Georgescu | [[BR]]initial_play:[[BR]] |
1859 | Whether or not the file to play once the {{{WavePlayer}}} is started, or to wait {{{pause_time}}} seconds before the first play. |
||
1860 | 94 | Adrian Georgescu | |
1861 | 87 | Adrian Georgescu | '''start'''(''self''):: |
1862 | 110 | Adrian Georgescu | Start playing the {{{.wav}}} file. |
1863 | 87 | Adrian Georgescu | |
1864 | '''stop'''(''self''):: |
||
1865 | Stop playing the {{{.wav}}} file immediately. |
||
1866 | 94 | Adrian Georgescu | |
1867 | 133 | Adrian Georgescu | '''play'''(''self''):: |
1868 | Play the {{{.wav}}} file. This method is an alternative to the start/stop methods, it runs on a waitable green thread. One may call {{{play().wait()}}} in order to green-block waiting for the file playback to end. |
||
1869 | |||
1870 | 87 | Adrian Georgescu | ==== attributes ==== |
1871 | |||
1872 | |||
1873 | '''is_active''':: |
||
1874 | A boolean indicating whether or not this {{{WavePlayer}}} is currently playing. |
||
1875 | 94 | Adrian Georgescu | |
1876 | 87 | Adrian Georgescu | ==== notifications ==== |
1877 | |||
1878 | |||
1879 | '''WavePlayerDidStart''':: |
||
1880 | 94 | Adrian Georgescu | This notification is sent when the {{{WavePlayer}}} starts playing the file the first time after the {{{start()}}} method has been called. |
1881 | 87 | Adrian Georgescu | [[BR]]timestamp:[[BR]] |
1882 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1883 | |||
1884 | '''WavePlayerDidEnd''':: |
||
1885 | 94 | Adrian Georgescu | This notification is sent when the {{{WavePlayer}}} is done playing either as a result of playing the number of times it was told to, or because the {{{stop()}}} method has been called. |
1886 | 87 | Adrian Georgescu | [[BR]]timestamp:[[BR]] |
1887 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1888 | |||
1889 | '''WavePlayerDidFail''':: |
||
1890 | This notification is sent when the {{{WavePlayer}}} is not capable of playing the {{{.wav}}} file. |
||
1891 | [[BR]]timestamp:[[BR]] |
||
1892 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
1893 | [[BR]]error:[[BR]] |
||
1894 | The exception raised by the {{{WaveFile}}} which identifies the cause for not being able to play the {{{.wav}}} file. |
||
1895 | |||
1896 | === WaveRecorder === |
||
1897 | |||
1898 | A {{{WaveRecorder}}} is an implementation of {{{IAudioPort}}} is is capable of consuming audio data and writing it to a {{{.wav}}} file. Just like {{{WavePlayer}}}, this object is reusable: once stopped it can be started again, but if the filename attribute is not changed, the previously written file will be overwritten. |
||
1899 | 94 | Adrian Georgescu | |
1900 | 87 | Adrian Georgescu | ==== methods ==== |
1901 | |||
1902 | |||
1903 | '''!__init!__'''(''self'', '''mixer''', '''filename'''):: |
||
1904 | Instantiate a new {{{WaveRecorder}}}. |
||
1905 | [[BR]]mixer:[[BR]] |
||
1906 | 94 | Adrian Georgescu | The {{{AudioMixer}}} this {{{WaveRecorder}}} is connected to. |
1907 | 87 | Adrian Georgescu | [[BR]]filename:[[BR]] |
1908 | The full path to the {{{.wav}}} file where this object should write the audio data. The file must be writable. The directories up to the file will be created if possible when the {{{start()}}} method is called. |
||
1909 | 94 | Adrian Georgescu | |
1910 | 87 | Adrian Georgescu | '''start'''(''self''):: |
1911 | Start consuming audio data and writing it to the {{{.wav}}} file. If this object is not part of an {{{AudioBridge}}}, not audio data will be written. |
||
1912 | |||
1913 | '''stop'''(''self''):: |
||
1914 | Stop consuming audio data and close the {{{.wav}}} file. |
||
1915 | 94 | Adrian Georgescu | |
1916 | 87 | Adrian Georgescu | ==== attributes ==== |
1917 | |||
1918 | |||
1919 | 73 | Luci Stanescu | '''is_active''':: |
1920 | 86 | Adrian Georgescu | A boolean indicating whether or not this {{{WaveRecorder}}} is currently recording audio data. |
1921 | 73 | Luci Stanescu | |
1922 | |||
1923 | == Conference == |
||
1924 | |||
1925 | Conference support is implemented in the {{{sipsimple.conference}}} module. Currently, only audio conferencing is supported. |
||
1926 | |||
1927 | === AudioConference === |
||
1928 | |||
1929 | This class contains the basic implementation for audio conferencing. It acts as a container for {{{AudioStream}}} objects which it will connect in a full mesh, such that all participants can hear all other participants. |
||
1930 | 94 | Adrian Georgescu | |
1931 | 73 | Luci Stanescu | ==== methods ==== |
1932 | |||
1933 | 94 | Adrian Georgescu | |
1934 | 73 | Luci Stanescu | '''!__init!__'''(''self''):: |
1935 | Instantiates a new {{{AudioConference}}} which is ready to contain {{{AudioStream}}} objects. |
||
1936 | 94 | Adrian Georgescu | |
1937 | 73 | Luci Stanescu | '''add'''(''self'', '''stream'''):: |
1938 | Add the specified {{{AudioStream}}} object to the conference. |
||
1939 | 94 | Adrian Georgescu | |
1940 | 73 | Luci Stanescu | '''remove'''(''self'', '''stream'''):: |
1941 | Removes the specified {{{AudioStream}}} object from the conference. Raises a {{{ValueError}}} if the stream is not part of the conference. |
||
1942 | 94 | Adrian Georgescu | |
1943 | 73 | Luci Stanescu | '''hold'''(''self''):: |
1944 | Puts the conference "on hold". This means that the audio device will be disconnected from the conference: all the participants will be able to continue the conference, but the local party will no longer contribute any audio data and will not receive any audio data using the input and output devices respectively. This does not affect the hold state of the streams in any way. |
||
1945 | |||
1946 | '''unhold'''(''self''):: |
||
1947 | Removes the conference "from hold". This means that the audio device will be reconnected to the conference: all the participants will start to hear the local party and the local party will start to hear all the participants. This does not affect the hold state of the streams in any way. |
||
1948 | 94 | Adrian Georgescu | |
1949 | 73 | Luci Stanescu | ==== attributes ==== |
1950 | |||
1951 | 94 | Adrian Georgescu | |
1952 | 73 | Luci Stanescu | '''bridge''':: |
1953 | An {{{AudioBridge}}} which this conference uses to connect all audio streams. It can be used by the application to play a wav file using a {{{WavePlayer}}} to all the participants or record the whole conference using a {{{WaveRecorder}}}. |
||
1954 | 94 | Adrian Georgescu | |
1955 | 1 | Adrian Georgescu | '''on_hold''':: |
1956 | A boolean indicating whether or not the conference is "on hold". |
||
1957 | 119 | Luci Stanescu | |
1958 | '''streams''':: |
||
1959 | The list of streams which are part of this conference. The application must not manipulate this list in any way. |
||
1960 | |||
1961 | |||
1962 | == XCAP support == |
||
1963 | |||
1964 | The {{{sipsimple.xcap}}} module offers a high level API for managing XCAP resources to other parts of the middleware or to the applications built on top of the middleware. The XCAP resources |
||
1965 | which can be managed by means of this module are: |
||
1966 | * '''contact list''', by means of the {{{resource-lists}}} and {{{rls-services}}} XCAP applications |
||
1967 | * '''presence policies''', by means of the {{{org.openmobilealliance.pres-rules}}} or {{{pres-rules}}} XCAP applications |
||
1968 | * '''dialoginfo policies''', by means of the {{{org.openxcap.dialog-rules}}} XCAP application |
||
1969 | * '''status icon''', by means of the {{{org.openmobilealliance.pres-content}}} XCAP application |
||
1970 | * '''offline status''', by means of the {{{pidf-manipulation}}} XCAP application |
||
1971 | |||
1972 | The module can work with both OMA or IETF-compliant XCAP servers, preferring the OMA variants of the specification if the server supports them. Not all applications need to be available on the |
||
1973 | XCAP server, although it is obvious that only those that are will be managed. The central entity for XCAP resource management is the XCAPManager, whose API relies on a series of objects describing |
||
1974 | the resources stored on the XCAP server. |
||
1975 | |||
1976 | === Contact === |
||
1977 | |||
1978 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
1979 | |||
1980 | A {{{Contact}}} is a URI with additional information stored about it, central to the XCAP contact list management. Information about a contact is stored in the {{{resource-lists}}}, {{{rls-services}}}, |
||
1981 | {{{org.openmobilealliance.pres-rules}}} or {{{pres-rules}}}, and {{{org.openxcap.dialog-rules}}} applications. The URI associated with the contact is considered a unique identifier. Information |
||
1982 | found in various places about the same URI is aggregated into a single {{{Contact}}} instance. More information about the contact is described within the attributes section. |
||
1983 | |||
1984 | ==== attributes ==== |
||
1985 | |||
1986 | '''name''':: |
||
1987 | A human-readable name which can be associated with the contact. This is stored using the {{{display-name}}} standard {{{resource-lists}}} element. |
||
1988 | |||
1989 | '''uri''':: |
||
1990 | The uniquely identifying URI. |
||
1991 | |||
1992 | '''group''':: |
||
1993 | A human-readable group name which can be used to group contacts together. If this is not {{{None}}}, the contact will be reachable from the {{{oma_buddylist}}} list within the {{{resource-lists}}} |
||
1994 | document, as defined by OMA. The group of a contact is the first {{{display-name}}} of an ancestor list which contains the contact information. |
||
1995 | |||
1996 | '''subscribe_to_presence''':: |
||
1997 | A boolean flag which indicates whether a subscription to the {{{presence}}} event is desired. If this is {{{True}}}, the contact's URI is referenced from a {{{rls-services}}} service which defines |
||
1998 | {{{presence}}} as one of the packages. Thus, a contact with this flag set is guaranteed to be referenced by an RLS service. |
||
1999 | |||
2000 | '''subscribe_to_dialoginfo''':: |
||
2001 | A boolean flag which indicates whether a subscription to the {{{dialog}}} event is desired. If this is {{{True}}}, the contact's URI is referenced from a {{{rls-services}}} service which defines |
||
2002 | {{{dialog}}} as one of the packages. Thus, a contact with this flag set is guaranteed to be refereneced by an RLS service. |
||
2003 | |||
2004 | '''presence_policies''':: |
||
2005 | Either {{{None}}} or a list of {{{PresencePolicy}}} objects which represent {{{org.openmobilealliance.pres-rules}}} or {{{pres-rules}}} rules which reference this contact's URI either directly |
||
2006 | (through an identity condition) or indirectly through resource lists (using the OMA external-list common policy extension). |
||
2007 | |||
2008 | '''dialoginfo_policies''':: |
||
2009 | Either {{{None}}} or a list of {{{DialoginfoPolicy}}} objects which represent {{{org.openxcap.dialog-rules}}} rules which reference this contact's URI through an identity condition. |
||
2010 | |||
2011 | '''attributes''':: |
||
2012 | A dictionary containing additional name, value pairs which the middleware or the application can use to store any information regarding this contact. This is stored through a proprietary AG-Projects |
||
2013 | extension to resource-lists. |
||
2014 | |||
2015 | ==== methods ==== |
||
2016 | |||
2017 | '''!__init!__'''(''self'', '''name''', '''uri''', '''group''', '''**attributes'''):: |
||
2018 | Initializes a new {{{Contact}}} instance. The policies are by default set to {{{None}}} and the {{{subscribe_to_presence}}} and {{{subscribe_to_dialoginfo}}} flags to {{{True}}}. |
||
2019 | |||
2020 | |||
2021 | === Service === |
||
2022 | |||
2023 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2024 | |||
2025 | A {{{Service}}} represents a URI managed by a Resource List Server (RLS). Subscriptions to this URI will be handled by the RLS. |
||
2026 | |||
2027 | ==== attributes ==== |
||
2028 | |||
2029 | '''uri''':: |
||
2030 | The URI which can be used to access a service provided by the RLS. |
||
2031 | |||
2032 | '''packages''':: |
||
2033 | A list of strings containing the SIP events which can be subscribed for to the URI. |
||
2034 | |||
2035 | '''entries''':: |
||
2036 | A list of URIs which represent the expanded list of URIs referenced by the service. A subscription to the service's URI for one of packages will result in the RLS subscribing to these URIs. |
||
2037 | |||
2038 | ==== methods ==== |
||
2039 | |||
2040 | '''!__init!__'''(''self'', '''uri''', '''packages''', '''entries'''={{{None}}}):: |
||
2041 | Initializes a new {{{Service}}} instance. |
||
2042 | |||
2043 | |||
2044 | === Policy === |
||
2045 | |||
2046 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2047 | |||
2048 | {{{Policy}}} is the base class for {{{PresencePolicy}}} and {{{DialoginfoPolicy}}}. It describes the attributes common to both. |
||
2049 | |||
2050 | ==== attributes ==== |
||
2051 | |||
2052 | '''id''':: |
||
2053 | A string containing the unique identifier of this specific policy. While it should not be considered human readable, OMA does assign specific meanings to some IDs. |
||
2054 | |||
2055 | '''action''':: |
||
2056 | A string having one of the values {{{"allow"}}}, {{{"confirm"}}}, {{{"polite-block"}}} or {{{"block"}}}. |
||
2057 | |||
2058 | '''validity''':: |
||
2059 | Either {{{None}}}, or a list of {{{datetime}}} instance 2-tuples representing the intervals when this policy applies. Example valid validity list which represents two intervals, each of two hours: |
||
2060 | {{{ |
||
2061 | from datetime import datetime, timedelta |
||
2062 | now = datetime.now() |
||
2063 | one_hour = timedelta(seconds=3600) |
||
2064 | one_day = timedelta(days=1) |
||
2065 | validity = [(now-one_hour, now+one_hour), (now+one_day-one_hour, now+one_day+one_hour)] |
||
2066 | }}} |
||
2067 | |||
2068 | '''sphere''':: |
||
2069 | Either {{{None}}} or a string representing the sphere of presentity when this policy applies. |
||
2070 | |||
2071 | '''multi_identity_conditions''':: |
||
2072 | Either {{{None}}} or a list of {{{CatchAllCondition}}} or {{{DomainCondition}}} objects as defined below. This is used to apply this policy to multiple users. |
||
2073 | |||
2074 | ==== methods ==== |
||
2075 | |||
2076 | '''!__init!__'''(''self'', '''id''', '''action''', '''name'''={{{None}}}, '''validity'''={{{None}}}, '''sphere'''={{{None}}}, '''multi_identity_conditions'''={{{None}}}):: |
||
2077 | Initializes a new {{{Policy}}} instance. |
||
2078 | |||
2079 | '''check_validity'''(''self'', '''timestamp''', '''sphere'''={{{Any}}}):: |
||
2080 | Returns a boolean indicating whether this policy applies at the specific moment given by timestamp (which must be a {{{datetime}}} instance) in the context of the specific sphere. |
||
2081 | |||
2082 | |||
2083 | === CatchAllCondition === |
||
2084 | |||
2085 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2086 | |||
2087 | {{{CatchAllCondition}}} represents a condition which matches any user, but which can have some exceptions. |
||
2088 | |||
2089 | ==== attributes ==== |
||
2090 | |||
2091 | '''exceptions''':: |
||
2092 | A list containing {{{DomainException}}} or {{{UserException}}} objects to define when this condition does not apply. |
||
2093 | |||
2094 | ==== methods ==== |
||
2095 | |||
2096 | '''!__init!__'''(''self'', '''exceptions'''={{{None}}}):: |
||
2097 | Initializes a new {{{CatchAllCondition}}} instance. |
||
2098 | |||
2099 | |||
2100 | === DomainCondition === |
||
2101 | |||
2102 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2103 | |||
2104 | {{{DomainCondition}}} represents a condition which matches any user within a specified domain, but which can have some exceptions. |
||
2105 | |||
2106 | ==== attributes ==== |
||
2107 | |||
2108 | '''domain''':: |
||
2109 | A string containing the domain for which this condition applies. |
||
2110 | |||
2111 | '''exceptions''':: |
||
2112 | A list containing {{{UserEception}}} objects to define when this condition does not apply. |
||
2113 | |||
2114 | |||
2115 | ==== methods ==== |
||
2116 | |||
2117 | '''!__init!__'''(''self'', '''domain''', '''exceptions'''={{{None}}}):: |
||
2118 | Initializes a new {{{DomainCondition}}} instance. |
||
2119 | |||
2120 | |||
2121 | === DomainException === |
||
2122 | |||
2123 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2124 | |||
2125 | {{{DomainException}}} is used as an exception for a {{{CatchAllCondition}}} which excludes all users within a specified domain. |
||
2126 | |||
2127 | ==== attributes ==== |
||
2128 | |||
2129 | '''domain''':: |
||
2130 | A string containing the domain which is to be excluded from the {{{CatchAllCondition}}} containing this object as an exception. |
||
2131 | |||
2132 | |||
2133 | ==== methods ==== |
||
2134 | |||
2135 | '''!__init!__'''(''self'', '''domain'''):: |
||
2136 | Initializes a new {{{DomainException}}} instance. |
||
2137 | |||
2138 | |||
2139 | === UserException === |
||
2140 | |||
2141 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2142 | |||
2143 | {{{UserException}}} is used as an exception for either a {{{CatchAllCondition}}} or a {{{DomainCondition}}} and excludes a user identified by an URI. |
||
2144 | |||
2145 | ==== attributes ==== |
||
2146 | |||
2147 | '''uri''':: |
||
2148 | A string containing the URI which is to be excluded from the {{{CatchAllCondition}}} or {{{DomainCondition}}} containing this object as an exception. |
||
2149 | |||
2150 | |||
2151 | ==== methods ==== |
||
2152 | |||
2153 | '''!__init!__'''(''self'', '''uri'''):: |
||
2154 | Initializes a new {{{UserException}}} instance. |
||
2155 | |||
2156 | |||
2157 | === PresencePolicy === |
||
2158 | |||
2159 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2160 | |||
2161 | A {{{PresencePolicy}}} represents either a {{{org.openmobilealliance.pres-rules}}} or {{{pres-rules}}} rule. It subclasses {{{Policy}}} and inherits its attributes, but defines additional |
||
2162 | attributes corresponding to the transformations which can be specified in a rule. |
||
2163 | |||
2164 | ==== attributes ==== |
||
2165 | |||
2166 | All of the following attributes only make sense for a policy having a {{{"allow"}}} action. |
||
2167 | |||
2168 | '''provide_devices''':: |
||
2169 | Either {{{sipsimple.util.All}}}, or a list of {{{Class}}}, {{{OccurenceID}}} or {{{DeviceID}}} objects as defined below. |
||
2170 | |||
2171 | '''provide_persons''':: |
||
2172 | Either {{{sipsimple.util.All}}}, or a list of {{{Class}}} or {{{OccurenceID}}} objects as defined below. |
||
2173 | |||
2174 | '''provide_services''':: |
||
2175 | Either {{{sipsimple.util.All}}}, or a list of {{{Class}}}, {{{OccurenceID}}}, {{{ServiceURI}}} or {{{ServiceURIScheme}}} objects as defined below. |
||
2176 | |||
2177 | '''provide_activities''':: |
||
2178 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2179 | |||
2180 | '''provide_class''':: |
||
2181 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2182 | |||
2183 | '''provide_device_id''':: |
||
2184 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2185 | |||
2186 | '''provide_mood''':: |
||
2187 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2188 | |||
2189 | '''provide_place_is''':: |
||
2190 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2191 | |||
2192 | '''provide_place_type''':: |
||
2193 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2194 | |||
2195 | '''provide_privacy''':: |
||
2196 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2197 | |||
2198 | '''provide_relationship''':: |
||
2199 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2200 | |||
2201 | '''provide_status_icon''':: |
||
2202 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2203 | |||
2204 | '''provide_sphere''':: |
||
2205 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2206 | |||
2207 | '''provide_time_offset''':: |
||
2208 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2209 | |||
2210 | '''provide_user_input''':: |
||
2211 | Either {{{None}}} (if the transformation is not be specified) or one of the strings {{{"false"}}}, {{{"bare"}}}, {{{"thresholds"}}}, {{{"full"}}}. |
||
2212 | |||
2213 | '''provide_unknown_attributes''':: |
||
2214 | Either {{{None}}} (if the transformation is not be specified) or a boolean. The name of the attribute is not a typo, although it maps to the transformation named {{{provide-unknown-attribute}}} (singular form). |
||
2215 | |||
2216 | '''provide_all_attributes''':: |
||
2217 | Either {{{None}}} (if the transformation is not be specified) or a boolean. |
||
2218 | |||
2219 | ==== methods ==== |
||
2220 | |||
2221 | '''!__init!__'''(''self'', '''id''', '''action''', '''name'''={{{None}}}, '''validity'''={{{None}}}, '''sphere'''={{{None}}}, '''multi_identity_conditions'''={{{None}}}):: |
||
2222 | Initializes a new {{{PresencePolicy}}} instance. The {{{provide_devices}}}, {{{provide_persons}}} and {{{provide_services}}} are initialized to {{{sipsimple.util.All}}}, {{{provide_all_attributes}}} to {{{True}}} and the rest to {{{None}}}. |
||
2223 | |||
2224 | |||
2225 | === DialoginfoPolicy === |
||
2226 | |||
2227 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2228 | |||
2229 | A {{{DialoginfoPolicy}}} represents a {{{org.openxcap.dialog-rules}}} rule. It subclasses {{{Policy}}} and inherits all of its attributes. It does not add any other attributes or methods and thus |
||
2230 | has an identical API. |
||
2231 | |||
2232 | |||
2233 | === Icon === |
||
2234 | |||
2235 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2236 | |||
2237 | An {{{Icon}}} instance represents a status icon stored using the {{{org.openmobilealliance.pres-content}}} application. |
||
2238 | |||
2239 | ==== attributes ==== |
||
2240 | |||
2241 | '''data''':: |
||
2242 | The binary data of the image, as a string. |
||
2243 | |||
2244 | '''mime_type''':: |
||
2245 | The MIME type of the image, one of {{{image/jpeg}}}, {{{image/gif}}} or {{{image/png}}}. |
||
2246 | |||
2247 | '''description''':: |
||
2248 | An optional description of the icon. |
||
2249 | |||
2250 | '''location''':: |
||
2251 | An HTTP(S) URI which can be used by other users to download the status icon of the local user. If the XCAP server returns the proprietary X-AGP-Alternative-Location header in its GET and PUT |
||
2252 | responses, that is used otherwise the XCAP URI of the icon is used. |
||
2253 | |||
2254 | ==== methods ==== |
||
2255 | |||
2256 | '''!__init!__'''(''self'', '''data''', '''mime_type''', '''description'''={{{None}}}, '''location'''={{{None}}}):: |
||
2257 | Initializes a new {{{Icon}}} instance. |
||
2258 | |||
2259 | |||
2260 | === OfflineStatus === |
||
2261 | |||
2262 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2263 | |||
2264 | An {{{OfflineStatus}}} instance represents data stored using the {{{pidf-manipulation}}} application. |
||
2265 | |||
2266 | ==== attributes ==== |
||
2267 | |||
2268 | '''activity''':: |
||
2269 | A string representing an activity within a {{{person}}} element. |
||
2270 | |||
2271 | '''note''':: |
||
2272 | A string stored as a note within a {{{person}}} element. |
||
2273 | |||
2274 | ==== methods ==== |
||
2275 | |||
2276 | '''!__init!__'''(''self'', '''activity'''={{{None}}}, '''note'''={{{Note}}}):: |
||
2277 | Initializes a new {{{OfflineStatus}}} instance. |
||
2278 | |||
2279 | |||
2280 | === XCAPManager === |
||
2281 | |||
2282 | Implemented in [browser:sipsimple/xcap/__init__.py] |
||
2283 | |||
2284 | The XCAPManager is the central entity used to manage resource via the XCAP protocol. It is a {{{Singleton}}} per account and has state machine as described in the following diagram: |
||
2285 | |||
2286 | [[Image(xcap-manager-state.png, align=center)]] |
||
2287 | |||
2288 | The XCAPManager associated with an account can be obtained by instantiating it with the account passed as an argument. The {{{load}}} method needs to be called just once in order to specify the |
||
2289 | directory which is used by manager to store its cache and other internal data. Once this is done, the {{{start}}} and {{{stop}}} methods can be called as needed. Initially in the {{{stopped}}} state, |
||
2290 | the start method will result in a transition to the {{{initializing}}} state. While in the {{{initializing}}} state, the XCAP manager will try to connect to the XCAP server and retrieve the |
||
2291 | capabilities ({{{xcap-caps}}} application). It will then initiate a SUBSCRIBE for the {{{xcap-diff}}} event (if configured) and transition to the {{{fetching}}} state. In the {{{fetching}}} state, it |
||
2292 | will try retrieve all the documents from the XCAP server, also specifying the ETag of the last known version. If none of the documents changed and this is not the first fetch, it transitions to the |
||
2293 | {{{insync}}} state. Otherwise, it inserts a {{{normalize}}} operation at the beginning of the journal (described below) and transitions to the {{{updating}}} state. In the {{{updating}}} state, it |
||
2294 | applies the operations from the journal which were not applied yet on the currently known documents and tries to push the documents, specifying the Etag of the last known version. If an operation |
||
2295 | fails due to a document having been modified, it marks all the operations in the journal as not being applied and transitions to the {{{fetching}}} state; if any other error occurs, the update is |
||
2296 | retried periodically. If the update succeeds, data is extracted from the documents and the {{{XCAPManagerDidReloadData}}} notification is sent. The XCAPManager then transitions to the {{{insync}}} |
||
2297 | state. A call to the {{{stop}}} method will result in a transition to the {{{stopping}}} state, termination of any existing SUBSCRIBE dialog and a transition to the {{{stopped}}} state. |
||
2298 | |||
2299 | Modifications to the settings which control the XCAPManager can result in either a transition to the {{{initializing}}} state or the termination of any previous SUBSCRIBE dialog and creation of a new |
||
2300 | 126 | Adrian Georgescu | one. |
2301 | 119 | Luci Stanescu | |
2302 | The subscription to the {{{xcap-diff}}} event allows the XCAPManager to be notified when the documents it manages are modified remotely. If the subscription fails, a fetch of all the documents is |
||
2303 | tried and the subscription is retried in some time. This allows the XCAPManager to reload the documents when they are modified remotely even if {{{xcap-diff}}} event is not supported by the provider. If subscription for {{{xcap-diff}}} event fails, a fetch of all the documents will be tried every 2 minutes. |
||
2304 | |||
2305 | The XCAPManager keeps the documents as they are stored on the XCAP server along with their ETags in an on-disk cache. All operations are made using the conditional {{{If-Match}}} and |
||
2306 | {{{If-None-Match}}} headers such that remote modifications the XCAPManager does not know about are not overwritten and bandwidth and processing power are not wasted by GET operations when a document |
||
2307 | is not modified. |
||
2308 | |||
2309 | Operations which the XCAPManager can be asked to apply to modify the documents are kept in a journal. This journal is saved to disk, such that operations which cannot be applied when requested due |
||
2310 | to server problems or lack of connectivity are retried even after application restarts. In addition, the high-level defined operations and the journal allow the modifications to be applied even if the |
||
2311 | document stored on the XCAP server are modified. Put differently, operations do depend on a specific version of the documents and the XCAPManager will try to apply them irrespective of the format |
||
2312 | of the document. |
||
2313 | |||
2314 | 126 | Adrian Georgescu | ==== configuration ==== |
2315 | 119 | Luci Stanescu | |
2316 | '''Account.id''', '''Account.auth.username''', '''Account.auth.password''':: |
||
2317 | These are used both for the {{{xcap-diff}}} subscription and the XCAP server connection. |
||
2318 | |||
2319 | '''Account.sip.subscribe_interval''':: |
||
2320 | This controls the Expires header used for the subscription, although a 423 response from the server can result in a larger Expires value being used. |
||
2321 | |||
2322 | '''Account.xcap.xcap_root''':: |
||
2323 | This specifies the XCAP root used for contacting the XCAP server and managing the resources. If this setting is {{{None}}}, a TXT DNS query is made for the {{{xcap}}} subdomain of the SIP account's |
||
2324 | domain. The result is interpreted as being an XCAP root. Example record for account alice@example.org: |
||
2325 | {{{ |
||
2326 | xcap.example.org. IN TXT "https://xcap.example.org/xcap-root" |
||
2327 | }}} |
||
2328 | |||
2329 | '''SIPSimpleSettings.sip.transport_list''':: |
||
2330 | This controls the transports which can be used for the subscription. |
||
2331 | |||
2332 | ==== methods ==== |
||
2333 | |||
2334 | '''!__init!__'''(''self'', '''account'''):: |
||
2335 | Initializes an XCAPManager for the specified account. Since XCAPManager is a {{{Singleton}}}, a single reference will be returned when "instantiating" it multiple times for the same account. |
||
2336 | |||
2337 | '''load'''(''self'', '''cache_directory'''):: |
||
2338 | Allows the XCAPManager to the load its internal data from cache. The directory passed will be used as the root for xcap data: a subdirectory for each account ID will be created within it. Thus, |
||
2339 | the account ID should not be part of the directory passed as an argument. |
||
2340 | |||
2341 | '''start'''(''self''):: |
||
2342 | Starts the XCAPManager. This will result in the subscription being started, the XCAP server being contacted and any operations in the journal being applied. This method must be called in a green |
||
2343 | thread. |
||
2344 | |||
2345 | '''stop'''(''self''):: |
||
2346 | Stops the XCAPManager from performing any tasks. Waits until the {{{xcap-diff}}} subscription, if any, is terminated. This method must be called in a green thread. |
||
2347 | |||
2348 | '''start_transaction'''(''self''):: |
||
2349 | This allows multiple operations to be queued and not applied immediately. All operations queued after a call to this method will not be applied until the {{{commit_transaction}}} method is called. |
||
2350 | This does not have the same meaning as a relational database transaction, since there is no {{{rollback}}} operation. |
||
2351 | |||
2352 | '''commit_transaction'''(''self''):: |
||
2353 | Applies the modifications queued after a call to {{{start_transaction}}}. This method needs to be called the exact same number of times the {{{start_transaction}}} method was called. Does not have |
||
2354 | any effect if {{{start_transaction}}} was not previously called. |
||
2355 | |||
2356 | The following methods results in XCAP operations being queued on the journal: |
||
2357 | |||
2358 | '''add_group'''(''self'', '''group'''):: |
||
2359 | Add a contact group with the specified name. |
||
2360 | |||
2361 | '''rename_group'''(''self'', '''old_name''', '''new_name'''):: |
||
2362 | Change the name of the contact group {{{old_name}}} to {{{new_name}}}. If such a contact group does not exist, the operation does not do anything. |
||
2363 | |||
2364 | '''remove_group'''(''self'', '''group'''):: |
||
2365 | Remove the contact group (and any contacts contained in it) with the specified name. If such a contact group does not exist, the operation does not do anything. |
||
2366 | |||
2367 | '''add_contact'''(''self'', '''contact'''):: |
||
2368 | Adds a new contact, described by a {{{Contact}}} object. If the contact with the same URI and a not-{{{None}}} group already exists, the operation does not do anything. Otherwise, the contact |
||
2369 | is added and any reference to the contact's URI is overwritten. Requests to add a contact to some OMA reserved presence policies ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, |
||
2370 | {{{wp_prs_block_anonymous}}}, {{{wp_prs_allow_own}}}) is ignored. |
||
2371 | |||
2372 | '''update_contact'''(''self'', '''contact''', '''**attributes'''):: |
||
2373 | Modifies a contact's properties. The keywords can be any of the {{{Contact}}} attributes, with the same meaning. The URI of the contact to be modified is taken from the first argument. If such |
||
2374 | a URI does not exist, it is added. Requests to add a contact to some OMA reserved presence policies ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, {{{wp_prs_block_anonymous}}}, |
||
2375 | {{{wp_prs_allow_own}}}) is ignored. The URI of a contact can be changed by specified the keyword argument {{{uri}}} with the new value. |
||
2376 | |||
2377 | '''remove_contact'''(''self'', '''contact'''):: |
||
2378 | Removes any reference to the contact's URI from all documents. This also means that the operation will make sure there are no policies which match the contact's URI. |
||
2379 | |||
2380 | '''add_presence_policy'''(''self'', '''policy'''):: |
||
2381 | Adds a new presence policy, described by a {{{PresencePolicy}}} object. If the id is specified and a policy with the same id exists, the operation does not do anything. Otherwise, if the id is not |
||
2382 | specified, one will be automatically generated (recommended). If the id is specified, but it is incompatible with the description of the policy (for example if an OMA defined id is used and there |
||
2383 | are some multi_identity_conditions), a new one will be automatically generated. |
||
2384 | |||
2385 | '''update_presence_policy'''(''self'', '''policy''', '''**attributes'''):: |
||
2386 | Modifies a presence policy's properties. The keywords can be any of the {{{PresencePolicy}}} attributes, with the same meaning. The id of the policy to be modified is taken from the first argument. |
||
2387 | If such a policy does not exist and there is sufficient information about the policy, it is added. If the policy to be modified uses the OMA extension to reference resource-lists and |
||
2388 | multi_identity_conditions are specified in the keywords, a new policy whose properties are the combination of the existing policy and the keywords is created. |
||
2389 | |||
2390 | '''remove_presence_policy'''(''self'', '''policy'''):: |
||
2391 | Removes the presence policy identified by the id attribute of the {{{PresencePolicy}}} object specified. If the id is {{{None}}} or does not exist in the document, the operation does not do |
||
2392 | anything. Some standard OMA policies ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, {{{wp_prs_block_anonymous}}}, {{{wp_prs_allow_own}}}, {{{wp_prs_grantedcontacts}}}, |
||
2393 | {{{wp_prs_blockedcontacts}}}) cannot be removed. |
||
2394 | |||
2395 | '''add_dialoginfo_policy'''(''self'', '''policy'''):: |
||
2396 | Adds a new dialoginfo policy, described by a {{{DialoginfoPolicy}}} object. If the id is specified and a policy with the same id exists, the operation does not do anything. Otherwise, if the id is |
||
2397 | not specified, one will be automatically generated (recommended). |
||
2398 | |||
2399 | '''update_dialoginfo_policy'''(''self'', '''policy''', '''**attributes'''):: |
||
2400 | Modifies a dialoginfo policy's properties. The keywords can be any of the {{{DialoginfoPolicy}}} attributes, with the same meanining. The id of the policy to be modified is taken from the first |
||
2401 | argument. If such a policy does not exist and there is sufficient information about the policy, it is added. |
||
2402 | |||
2403 | '''remove_dialoginfo_policy'''(''self'', '''policy'''):: |
||
2404 | Removes the dialoginfo policy identified by the id attribute of the {{{DialoginfoPolicy}}} object specified. If the id is {{{None}}} or does not exist in the document, the operation does not do |
||
2405 | anything. |
||
2406 | |||
2407 | '''set_status_icon'''(''self'', '''icon'''):: |
||
2408 | Sets the status icon using the information from the {{{Icon}}} object specified. The {{{location}}} attribute is ignored. The MIME type must be one of {{{image/gif}}}, {{{image/png}}} or |
||
2409 | {{{image/jpeg}}}. If the argument is {{{None}}}, the status icon is deleted. |
||
2410 | |||
2411 | '''set_offline_status'''(''self'', '''status'''):: |
||
2412 | Sets the offline status using the information from the {{{OfflineStatus}}} object specified. If the argument is {{{None}}}, the offline status document is deleted. |
||
2413 | |||
2414 | ==== notifications ==== |
||
2415 | |||
2416 | '''XCAPManagerWillStart''':: |
||
2417 | This notification is sent just after calling the {{{start}}} method. |
||
2418 | [[BR]]timestamp:[[BR]] |
||
2419 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2420 | |||
2421 | '''XCAPManagerDidStart''':: |
||
2422 | This notification is sent after the XCAPManager has started doing its tasks (contacting the XCAP server, subscribing to {{{xcap-diff}}} event). This notification does not mean that |
||
2423 | any of these operations were successful, as the XCAPManager will retry them continuously should they fail. |
||
2424 | [[BR]]timestamp:[[BR]] |
||
2425 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2426 | |||
2427 | '''XCAPManagerWillEnd''':: |
||
2428 | This notification is sent just after calling the {{{stop}}} method. |
||
2429 | [[BR]]timestamp:[[BR]] |
||
2430 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2431 | |||
2432 | '''XCAPManagerDidEnd''':: |
||
2433 | This notification is sent when the XCAPManager has stopped performing any tasks. This also means that any active {{{xcap-diff}}} subscription has been terminated. |
||
2434 | [[BR]]timestamp:[[BR]] |
||
2435 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2436 | |||
2437 | '''XCAPManagerDidDiscoverServerCapabilities''':: |
||
2438 | This notification is sent when the XCAPManager contacts an XCAP server for the first time or after the connection is reset due to configuration changes. The data of the notification contains |
||
2439 | information about the server's capabilities (obtained using the {{{xcap-caps}}} application). |
||
2440 | [[BR]]contactlist_supported:[[BR]] |
||
2441 | A boolean indicating the support of documents needed for contact management ({{{resource-lists}}} and {{{rls-services}}}). |
||
2442 | [[BR]]presence_policies_supported:[[BR]] |
||
2443 | A boolean indicating the support of documents needed for presence policy management ({{{org.openmobilealliance.pres-rules}}} or {{{pres-rules}}}). |
||
2444 | [[BR]]dialoginfo_policies_supported:[[BR]] |
||
2445 | A boolean indicating the support of documents needed for dialoginfo policy management ({{{org.openxcap.dialog-rules}}}). |
||
2446 | [[BR]]status_icon_supported:[[BR]] |
||
2447 | A boolean indicating the support of documents needed for status icon management ({{{org.openmobilealliance.pres-content}}}). |
||
2448 | [[BR]]offline_status_supported:[[BR]] |
||
2449 | A boolean indicating the support of documents needed for offline status management ({{{pidf-manipulation}}}). |
||
2450 | [[BR]]timestamp:[[BR]] |
||
2451 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2452 | |||
2453 | '''XCAPManagerDidReloadData''':: |
||
2454 | This notification is sent when the XCAPManager synchronizes with the XCAP server. The data of the notification contains objects representing the data as it is stored on the XCAP server. |
||
2455 | [[BR]]contacts:[[BR]] |
||
2456 | A list of {{{Contact}}} objects. |
||
2457 | [[BR]]groups:[[BR]] |
||
2458 | A list of strings. |
||
2459 | [[BR]]services:[[BR]] |
||
2460 | A list of {{{Service}}} objects. |
||
2461 | [[BR]]presence_policies:[[BR]] |
||
2462 | A list of {{{PresencePolicy}}} objects. |
||
2463 | [[BR]]dialoginfo_policies:[[BR]] |
||
2464 | A list of {{{DialoginfoPolicy}}} objects. |
||
2465 | [[BR]]status_icon:[[BR]] |
||
2466 | A {{{StatusIcon}}} object if one is stored, {{{None}}} otherwise. |
||
2467 | [[BR]]offline_status:[[BR]] |
||
2468 | A {{{OfflineStatus}}} object if offline status information is stored, {{{None}}} otherwise. |
||
2469 | [[BR]]timestamp:[[BR]] |
||
2470 | A {{{datetime.datetime}}} object indicating when the notification was sent. |
||
2471 | |||
2472 | '''XCAPManagerDidChangeState''':: |
||
2473 | This notification is sent when the XCAPManager transitions from one state to another. |
||
2474 | [[BR]]prev_state:[[BR]] |
||
2475 | The old state of the XCAPManager, a string. |
||
2476 | [[BR]]state:[[BR]] |
||
2477 | 1 | Adrian Georgescu | The new state of the XCAPManager, a string. |
2478 | [[BR]]timestamp:[[BR]] |
||
2479 | A {{{datetime.datetime}}} object indicating when the notification was sent. |