Project

General

Profile

SipMiddlewareApi » History » Revision 147

Revision 146 (Adrian Georgescu, 04/03/2012 02:13 PM) → Revision 147/238 (Adrian Georgescu, 04/03/2012 02:13 PM)

 
 h1. = Middleware API 




 = 

 [[TOC(SipMiddlewareApi, SipConfigurationAPI, SipCoreApiDocumentation, SipMSRPApi, ThreadingApi, depth=3)]] 

 This chapter describes the _Middleware API_ ''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_ ''non-blocking'' API    that communicates with the user interface asynchronously by using _Notifications_. ''Notifications''. For its configuration, the Middleware uses the [[SipConfigurationAPI|Configuration API]]. [wiki:SipConfigurationAPI Configuration API]. 

 !{ [[Image(sipsimple-middleware.png, align=center, width:700px}sipsimple-middleware.png! 


 h2. width=700)]] 

 == SIPApplication 


 == 

 Implemented in [browser:sipsimple/application.py] 

 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: 
 
  * the twisted thread 
 
  * the configuration system, via the [[SipConfigurationAPI#ConfigurationManager|ConfigurationManager]] 
 [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] 
  * the core [[SipCoreApiDocumentation#Engine|Engine]] [wiki:SipCoreApiDocumentation#Engine Engine] using the settings in the configuration 
 
  * the [[SipMiddlewareApi#AccountManager|AccountManager]], [wiki:SipMiddlewareApi#AccountManager AccountManager], using the accounts in the configuration 
 
  * the [[SipMiddlewareApi#SessionManager|SessionManager]], [wiki:SipMiddlewareApi#SessionManager SessionManager], in order to handle incoming sessions 
 
  * two [[SipMiddlewareApi#AudioBridge|AudioBridges]], [wiki:SipMiddlewareApi#AudioBridge AudioBridges], using the settings in the configuration 

 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. 


 h4. 

 ==== methods  



 *<notextile>__init__</notextile>*(_self_) 
 >Instantiates    ==== 


  '''!__init!__'''(''self''):: 
   Instantiates a new SIPApplication. 

 *start*(_self_, *storage*) 
 >Starts 

  '''start'''(''self'', '''storage'''):: 
   Starts the @SIPApplication@ {{{SIPApplication}}} which initializes all the components in the correct order. The @storage@ {{{storage}}} is saved as an attribute which other entities like the @Configuration Manager@ {{{Configuration Manager}}} will use to take the appropriate backend. If any error occurs with loading the configuration, the exception raised by the @ConfigurationManager@ {{{ConfigurationManager}}} is propagated by this method and @SIPApplication@ {{{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@ {{{SIPApplicationDidStart}}} notification in order to know that the application started. 

 *stop*(_self_) 
 >Stop 

  '''stop'''(''self''):: 
   Stop all the components started by the SIPApplication. This method returns immediately, but a @SIPApplicationDidEnd@ {{{SIPApplicationDidEnd}}} notification is sent when all the components have been stopped. 


 h4. 

 ==== attributes 



 *running* ==== 


  '''running''':: 
   @True@ {{{True}}} if the SIPApplication is running (it has been started and it has not been told to stop), @False@ {{{False}}} otherwise. 

 *storage* 
 >Holds 

  '''storage''':: 
   Holds an object which implements the @ISIPSimpleStorage@ {{{ISIPSimpleStorage}}} interface which will be used to provide a storage facility to other middleware components. 

 *local_nat_type* 
 >String 

  '''local_nat_type''':: 
   String containing the detected local NAT type. 

 *alert_audio_mixer* 
 >The @AudioMixer@ 

  '''alert_audio_mixer''':: 
   The {{{AudioMixer}}} object created on the alert audio device as defined by the configuration (by SIPSimpleSettings.audio.alert_device). 

 *alert_audio_bridge* 
 >An @AudioBridge@ 

  '''alert_audio_bridge''':: 
   An {{{AudioBridge}}} where @IAudioPort@ {{{IAudioPort}}} objects can be added to playback sound to the alert device. 

 *alert_audio_device* 
 >An @AudioDevice@ 

  '''alert_audio_device''':: 
   An {{{AudioDevice}}} which corresponds to the alert device as defined by the configuration. This will always be part of the alert_audio_bridge. 

 *voice_audio_mixer* 
 >The @AudioMixer@ 

  '''voice_audio_mixer''':: 
   The {{{AudioMixer}}} object created on the voice audio device as defined by the configuration (by SIPSimpleSettings.audio.input_device and SIPSimpleSettings.audio.output_device). 

 *voice_audio_bridge* 
 >An @AudioBridge@ 

  '''voice_audio_bridge''':: 
   An {{{AudioBridge}}} where @IAudioPort@ {{{IAudioPort}}} objects can be added to playback sound to the output device or record sound from the input device. 

 *voice_audio_device* 
 >An @AudioDevice@ 

  '''voice_audio_device''':: 
   An {{{AudioDevice}}} which corresponds to the voice device as defined by the configuration. This will always be part of the voice_audio_bridge. 


 h4. 

 ==== notifications  



 *SIPApplicationWillStart* 
 >This    ==== 


  '''SIPApplicationWillStart''':: 
   This notification is sent just after the configuration has been loaded and the twisted thread started, but before any other components have been initialized. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPApplicationDidStart* 
 >This 

  '''SIPApplicationDidStart''':: 
   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. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPApplicationWillEnd* 
 >This 

  '''SIPApplicationWillEnd''':: 
   This notification is sent as soon as the @stop()@ {{{stop()}}} method has been called. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPApplicationDidEnd* 
 >This 

  '''SIPApplicationDidEnd''':: 
   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). 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPApplicationFailedToStartTLS* 
 >This 

  '''SIPApplicationFailedToStartTLS''':: 
   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. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 error: 

 >The 
   [[BR]]error:[[BR]] 
   The exception raised by the Engine which identifies the cause for not being able to start the TLS transport. 



 h2. 


 == Storage API 


 == 

 Different middleware components may need to store data, i.e. configuration files or XCAP documents. The @Storage API@ {{{Storage API}}} defines a collection of backends which other components will use to store their data. 


 h3. 

 === API Definition 


 === 

 The @Storage API@ {{{Storage API}}} currently requires the following attributes to be defined as per the @ISIPSimpleStorage@ {{{ISIPSimpleStorage}}} interface: 

 *configuration_backend* 
 >The 

  '''configuration_backend''':: 
   The backend used for storing the configuration. 

 *xcap_storage_factory* 
 >Factory 

  '''xcap_storage_factory''':: 
   Factory used to create XCAP storage backends for each account. 


 h3. 

 === Provided implementations 


 === 

 Two storage implementations are provided: *FileStorage* '''FileStorage''' and *MemoryStorage* '''MemoryStorage''' both located in the *sipsimple.storage* '''sipsimple.storage''' module. 


 h2. 

 == SIP Sessions 


 == 

 SIP sessions are supported by the @sipsimple.session.Session@ {{{sipsimple.session.Session}}} class and independent stream classes, which need to implement the @sipsimple.streams.IMediaStream@ {{{sipsimple.streams.IMediaStream}}} interface. The @Session@ {{{Session}}} class takes care of the signalling, while the streams offer the actual media support which is negotiated by the @Session@. {{{Session}}}. The streams which are implemented in the SIP SIMPLE middleware are provided in modules within the @sipsimple.streams@ {{{sipsimple.streams}}} package, but they are accessible for import directly from @sipsimple.streams@. {{{sipsimple.streams}}}. Currently, the middleware implements two types of streams, one for RTP data, with a concrete implementation in the @AudioStream@ {{{AudioStream}}} class, and one for MSRP sessions, with concrete implementations in the @ChatStream@, @FileTransferStream@ {{{ChatStream}}}, {{{FileTransferStream}}} and @DesktopSharingStream@ {{{DesktopSharingStream}}} classes. However, the application can provide its own stream implementation, provided they respect the @IMediaStream@ {{{IMediaStream}}} interface. 

 The @sipsimple.streams@ {{{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 [[SipMiddlewareApi#MediaStreamRegistry|MediaStreamRegistry]]. 



 h3. [wiki:SipMiddlewareApi#MediaStreamRegistry MediaStreamRegistry]. 


 === SessionManager 


 === 

 Implemented in [browser:sipsimple/session.py] 

 The @sipsimple.session.SessionManager@ {{{sipsimple.session.SessionManager}}} class is a singleton, which acts as the central aggregation point for sessions within the middleware. 
 Although it is mainly used internally, the application can use it to query information about all active sessions. 
 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. 


 h4. 

 ==== attributes 



 *sessions* 
 >A ==== 


  '''sessions''':: 
   A property providing a copy of the list of all active @Sesssion@ {{{Sesssion}}} objects within the application, meaning any @Session@ {{{Session}}} object that exists globally within the application and is not in the @NULL@ {{{NULL}}} or @TERMINATED@ {{{TERMINATED}}} state. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_) 
 >Instantiate ==== 


  '''!__init!__'''(''self''):: 
   Instantiate a new @SessionManager@ {{{SessionManager}}} object. 


 *start*(_self_) 
 >Start 


  '''start'''(''self''):: 
   Start the @SessionManager@ {{{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. 

 *stop*(_self_) 
 >End 

  '''stop'''(''self''):: 
   End all connected sessions. This method is called automatically when SIPApplication is stopped. The application should not call this method directly. 


 h3. 

 === Session 


 === 

 Implemented in [browser:sipsimple/session.py] 

 A @sipsimple.session.Session@ {{{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. 

 A @Session@ {{{Session}}} instance is a stateful object, meaning that it has a @state@ {{{state}}} attribute and that the lifetime of the session traverses different states, from session creation to termination. 
 State changes are triggered by methods called on the object by the application or by received network events. 
 These states and their transitions are represented in the following diagram: 

 !{}/raw-attachment/wiki/SipCoreApiDocumentation/sipsimple-core-invite-state-machine.png! [[Image(/raw-attachment/wiki/SipCoreApiDocumentation/sipsimple-core-invite-state-machine.png)]] 

 Although these states are crucial to the correct operation of the @Session@ {{{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. 

 The @Session@ {{{Session}}} is completely independent of the streams it contains, which need to be implementations of the @sipsimple.streams.IMediaStream@ {{{sipsimple.streams.IMediaStream}}} interface. This interface provides the API by which the @Session@ {{{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. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *account*) 
 >Creates ==== 


  '''!__init!__'''(''self'', '''account'''):: 
   Creates a new @Session@ {{{Session}}} object in the @None@ {{{None}}} state. 
  
 >+_account_+: 

 >The 
   [[BR]]''account'':[[BR]] 
   The local account to be associated with this @Session@. 

 *connect*(_self_, *to_header*, *routes*, *streams*, *is_focus*=@False@, *subject*=@None@) 
 >Will {{{Session}}}. 

  '''connect'''(''self'', '''to_header''', '''routes''', '''streams''', '''is_focus'''={{{False}}}, '''subject'''={{{None}}}):: 
   Will set up the @Session@ {{{Session}}} as outbound and propose the new session to the specified remote party and move the state machine to the @outgoing@ {{{outgoing}}} state. 
 >Before 
   Before contacting the remote party, a @SIPSessionNewOutgoing@ {{{SIPSessionNewOutgoing}}} notification will be emitted. 
 >If 
   If there is a failure or the remote party rejected the offer, a @SIPSessionDidFail@ {{{SIPSessionDidFail}}} notification will be sent. 
 >Any 
   Any time a ringing indication is received from the remote party, a @SIPSessionGotRingIndication@ {{{SIPSessionGotRingIndication}}} notification is sent. 
 >If 
   If the remote party accepted the session, a @SIPSessionWillStart@ {{{SIPSessionWillStart}}} notification will be sent, followed by a @SIPSessionDidStart@ {{{SIPSessionDidStart}}} notification when the session is actually established. 
 >This 
   This method may only be called while in the @None@ {{{None}}} state. 
  
 >+_to_header_+: 

 >A @sipsimple.core.ToHeader@ 
   [[BR]]''to_header'':[[BR]] 
   A {{{sipsimple.core.ToHeader}}} object representing the remote identity to initiate the session to. 
  
 >+_routes_+: 

 >An 
   [[BR]]''routes'':[[BR]] 
   An iterable of @sipsimple.util.Route@ {{{sipsimple.util.Route}}} objects, specifying the IP, port and transport to the outbound proxy. 
 >These 
   These routes will be tried in order, until one of them succeeds. 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   A list of stream objects which will be offered to the remote endpoint. 
  
 >+_is_focus_+: 

 >Boolean 
   [[BR]]''is_focus'':[[BR]] 
   Boolean flag indicating if the @isfocus@ {{{isfocus}}} parameter should be added to the @Contact@ {{{Contact}}} header according to RFC 4579. 
  
 >+_subject_+: 

 >Session 
   [[BR]]''subject'':[[BR]] 
   Session subject. If not None a @Subject@ {{{Subject}}} header will be added with the specified value. 

 *send_ring_indication*(_self_) 
 >Sends 

  '''send_ring_indication'''(''self''):: 
   Sends a 180 provisional response in the case of an incoming session. 

 *accept*(_self_, *streams*) 
 >Calling 

  '''accept'''(''self'', '''streams'''):: 
   Calling this methods will accept an incoming session and move the state machine to the @accepting@ {{{accepting}}} state. 
 >When 
   When there is a new incoming session, a @SIPSessionNewIncoming@ {{{SIPSessionNewIncoming}}} notification is sent, after which the application can call this method on the sender of the notification. 
 >After 
   After this method is called, @SIPSessionWillStart@ {{{SIPSessionWillStart}}} followed by @SIPSessionDidStart@ {{{SIPSessionDidStart}}} will be emitted, or @SIPSessionDidFail@ {{{SIPSessionDidFail}}} on an error. 
 >This 
   This method may only be called while in the @incoming@ {{{incoming}}} state. 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   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. 

 *reject*(_self_, *code*=@603@, *reason*=@None@) 
 >Reject 

  '''reject'''(''self'', '''code'''={{{603}}}, '''reason'''={{{None}}}):: 
   Reject an incoming session and move it to the @terminating@ {{{terminating}}} state, which eventually leads to the @terminated@ {{{terminated}}} state. 
 >Calling 
   Calling this method will cause the @Session@ {{{Session}}} object to emit a @SIPSessionDidFail@ {{{SIPSessionDidFail}}} notification once the session has been rejected. 
 >This 
   This method may only be called while in the @incoming@ {{{incoming}}} state. 
  
 >+_code_+: 

 >An 
   [[BR]]''code'':[[BR]] 
   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). 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   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. 

 *accept_proposal*(_self_, *streams*) 
 >When 

  '''accept_proposal'''(''self'', '''streams'''):: 
   When the remote party proposes to add some new streams, signaled by the @SIPSessionGotProposal@ {{{SIPSessionGotProposal}}} notification, the application can use this method to accept the stream(s) being proposed. 
 >After 
   After calling this method a @SIPSessionGotAcceptProposal@ {{{SIPSessionGotAcceptProposal}}} notification is sent, unless an error occurs while setting up the new stream, in which case a @SIPSessionHadProposalFailure@ {{{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@ {{{SIPSessionDidRenegotiateStreams}}} notification is also sent. 
 >This 
   This method may only be called while in the @received_proposal@ {{{received_proposal}}} state. 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   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. 

 *reject_proposal*(_self_, *code*=@488@, *reason*=@None@) 
 >When 

  '''reject_proposal'''(''self'', '''code'''={{{488}}}, '''reason'''={{{None}}}):: 
   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@ {{{SIPSessionGotRejectProposal}}} or @SIPSessionHadProposalFailure@ {{{SIPSessionHadProposalFailure}}} notification is sent. 
 >This 
   This method may only be called while in the @received_proposal@ {{{received_proposal}}} state. 
  
 >+_code_+: 

 >An 
   [[BR]]''code'':[[BR]] 
   An integer which represents the SIP status code in the response which is to be sent. Usually, this is 488 (Not Acceptable Here). 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   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. 

 *add_stream*(_self_, *stream*) 
 >Proposes 

  '''add_stream'''(''self'', '''stream'''):: 
   Proposes a new stream to the remote party. 
 >Calling 
   Calling this method will cause a @SIPSessionGotProposal@ {{{SIPSessionGotProposal}}} notification to be emitted. 
 >After 
   After this, the state machine will move into the @sending_proposal@ {{{sending_proposal}}} state until either a @SIPSessionGotAcceptProposal@, @SIPSessionGotRejectProposal@ {{{SIPSessionGotAcceptProposal}}}, {{{SIPSessionGotRejectProposal}}} or @SIPSessionHadProposalFailure@ {{{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@ {{{SIPSessionDidRenegotiateStreams}}} notification is also sent. 
 >This 
   This method may only be called while in the @connected@ {{{connected}}} state. 

 *remove_stream*(_self_, *stream*) 
 >Stop 

  '''remove_stream'''(''self'', '''stream'''):: 
   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). 
 >This 
   This method may only be called while in the @connected@ {{{connected}}} state. 

 *cancel_proposal*(_self_) 
 >This 

  '''cancel_proposal'''(''self''):: 
   This method cancels a proposal of adding a stream to the session by sending a CANCEL request. A @SIPSessionGotRejectProposal@ {{{SIPSessionGotRejectProposal}}} notification will be sent with code 487. 

 *hold*(_self_) 
 >Put 

  '''hold'''(''self''):: 
   Put the streams of the session which support the notion of hold on hold. 
 >This 
   This will cause a @SIPSessionDidChangeHoldState@ {{{SIPSessionDidChangeHoldState}}} notification to be sent. 
 >This 
   This method may be called in any state and will send the re-INVITE as soon as it is possible. 

 *unhold*(_self_) 
 >Take 

  '''unhold'''(''self''):: 
   Take the streams of the session which support the notion of hold out of hold. 
 >This 
   This will cause a @SIPSessionDidChangeHoldState@ {{{SIPSessionDidChangeHoldState}}} notification to be sent. 
 >This 
   This method may be called in any state and will send teh re-INVITE as soon as it is possible. 

 *end*(_self_) 
 >This 

  '''end'''(''self''):: 
   This method may be called any time after the @Session@ {{{Session}}} has started in order to terminate the session by sending a BYE request. 
 >Right 
   Right before termination a @SIPSessionWillEnd@ {{{SIPSessionWillEnd}}} notification is sent, after termination @SIPSessionDidEnd@ {{{SIPSessionDidEnd}}} is sent. 

 *transfer*(_self_, *target_uri*, 

  '''transfer'''(''self'', '''target_uri''',    *replaced_session*=@None@) 
 >Proposes '''replaced_session'''={{{None}}}):: 
   Proposes a blind call transfer to a new target URI or assisted transfer to an URI belonging to an already established session.  

 *accept_transfer*(_self_) 
 >Accepts  

  '''accept_transfer'''(''self''):: 
   Accepts an incoming call transfer request. 

 *reject_transfer*(_self_, *code*=@486@, *reason_=@None@) 
 >Rejects 

  '''reject_transfer'''(''self'', '''code'''={{{486}}}, '''reason''={{{None}}}):: 
   Rejects an incoming call transfer request. 



 h4. 


 ==== attributes 



 *state* 
 >The ==== 


  '''state''':: 
   The state the object is currently in, being one of the states from the diagram above. 

 *account* 
 >The @sipsimple.account.Account@ 

  '''account''':: 
   The {{{sipsimple.account.Account}}} or @sipsimple.account.BonjourAccount@ {{{sipsimple.account.BonjourAccount}}} object that the @Session@ {{{Session}}} is associated with. 
 >On 
   On an outbound session, this is the account the application specified on object instantiation. 

 *direction* 
 >A 

  '''direction''':: 
   A string indicating the direction of the initial negotiation of the session. 
 >This 
   This can be either @None@, {{{None}}}, "incoming" or "outgoing". 

 *transport* 
 >A 

  '''transport''':: 
   A string representing the transport this @Session@ {{{Session}}} is using: @"udp"@, @"tcp"@ {{{"udp"}}}, {{{"tcp"}}} or @"tls"@. 

 *start_time* 
 >The {{{"tls"}}}. 

  '''start_time''':: 
   The time the session started as a @datetime.datetime@ {{{datetime.datetime}}} object, or @None@ {{{None}}} if the session was not yet started. 

 *stop_time* 
 >The 

  '''stop_time''':: 
   The time the session stopped as a @datetime.datetime@ {{{datetime.datetime}}} object, or @None@ {{{None}}} if the session has not yet terminated. 

 *on_hold* 
 >Boolean 

  '''on_hold''':: 
   Boolean indicating whether the session was put on hold, either by the local or the remote party. 

 *remote_user_agent* 
 >A 

  '''remote_user_agent''':: 
   A string indicating the remote user agent, if it provided one. 
 >Initially 
   Initially this will be @None@, {{{None}}}, it will be set as soon as this information is received from the remote party (which may be never). 

 *local_identity* 
 >The @sipsimple.core.FrozenFromHeader@ 

  '''local_identity''':: 
   The {{{sipsimple.core.FrozenFromHeader}}} or @sipsimple.core.FrozenToHeader@ {{{sipsimple.core.FrozenToHeader}}} identifying the local party, if the session is active, @None@ {{{None}}} otherwise. 

 *remote_identity* 
 >The @sipsimple.core.FrozenFromHeader@ 

  '''remote_identity''':: 
   The {{{sipsimple.core.FrozenFromHeader}}} or @sipsimple.core.FrozenToHeader@ {{{sipsimple.core.FrozenToHeader}}} identifying the remote party, if the session is active, @None@ {{{None}}} otherwise. 

 *streams* 
 >A 

  '''streams''':: 
   A list of the currently active streams in the @Session@. 

 *proposed_streams* 
 >A {{{Session}}}. 

  '''proposed_streams''':: 
   A list of the currently proposed streams in the @Session@, {{{Session}}}, or @None@ {{{None}}} if there is no proposal in progress. 

 *conference* 
 >A @ConferenceHandler@ 

  '''conference''':: 
   A {{{ConferenceHandler}}} object instance (or Null). It can be later used to add/remove participants from a remote conference. 

 *subject* 
 >The 

  '''subject''':: 
   The session subject as a unicode object. 

 *replaced_session* 
 >A @Session@ 

  '''replaced_session''':: 
   A {{{Session}}} object instance (or Null). It can be used for assisted call transfer. 

 *transfer_handler* 
 >A @TransferHandler@ 

  '''transfer_handler''':: 
   A {{{TransferHandler}}} object instance (or Null). It is used for managing the call transfer process. 

 *transfer_info* 
 >A @TransferInfo@ 

  '''transfer_info''':: 
   A {{{TransferInfo}}} object instance (or Null). It is used for describing the details of a call transfer operation. 


 h4. 

 ==== notifications 



 *SIPSessionNewIncoming* 
 >Will ==== 


  '''SIPSessionNewIncoming''':: 
   Will be sent when a new incoming @Session@ {{{Session}}} is received. 
 >The 
   The application should listen for this notification to get informed of incoming sessions. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   A list of streams that were proposed by the remote party. 

 *SIPSessionNewOutgoing* 
 >Will 

  '''SIPSessionNewOutgoing''':: 
   Will be sent when the application requests a new outgoing @Session@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{Session}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   A list of streams that were proposed to the remote party. 

 *SIPSessionGotRingIndication* 
 >Will 

  '''SIPSessionGotRingIndication''':: 
   Will be sent when an outgoing @Session@ {{{Session}}} receives an indication that a remote device is ringing. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPSessionGotProvisionalResponse* 
 >Will 

  '''SIPSessionGotProvisionalResponse''':: 
   Will be sent whenever the @Session@ {{{Session}}} receives a provisional response as a result of sending a (re-)INVITE. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP status code received. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The SIP status reason received. 

 *SIPSessionWillStart* 
 >Will 

  '''SIPSessionWillStart''':: 
   Will be sent just before a @Session@ {{{Session}}} completes negotiation. 
 >In 
   In terms of SIP, this is sent after the final response to the @INVITE@, {{{INVITE}}}, but before the @ACK@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{ACK}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPSessionDidStart* 
 >Will 

  '''SIPSessionDidStart''':: 
   Will be sent when a @Session@ {{{Session}}} completes negotiation and all the streams have started. 
 >In 
   In terms of SIP this is sent after the @ACK@ {{{ACK}}} was sent or received. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_streams_+: 

 >The 
   [[BR]]''streams'':[[BR]] 
   The list of streams which now form the active streams of the @Session@. 

 *SIPSessionDidFail* 
 >This {{{Session}}}. 

  '''SIPSessionDidFail''':: 
   This notification is sent whenever the session fails before it starts. 
 >The 
   The failure reason is included in the data attributes. 
 >This 
   This notification is never followed by @SIPSessionDidEnd@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{SIPSessionDidEnd}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >A 
   [[BR]]''originator'':[[BR]] 
   A string indicating the originator of the @Session@. {{{Session}}}. This will either be "local" or "remote". 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP error code of the failure. 
  
 >+_reason_+: 

 >A 
   [[BR]]''reason'':[[BR]] 
   A SIP status reason. 
  
 >+_failure_reason_+: 

 >A 
   [[BR]]''failure_reason'':[[BR]] 
   A string which represents the reason for the failure, such as @"user_request"@, @"missing ACK"@, @"SIP {{{"user_request"}}}, {{{"missing ACK"}}}, {{{"SIP core error..."@. 

 *SIPSessionWillEnd* 
 >Will error..."}}}. 

  '''SIPSessionWillEnd''':: 
   Will be sent just before terminating a @Session@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{Session}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPSessionDidEnd* 
 >Will 

  '''SIPSessionDidEnd''':: 
   Will be sent always when a @Session@ {{{Session}}} ends as a result of remote or local session termination. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >A 
   [[BR]]''originator'':[[BR]] 
   A string indicating who originated the termination. This will either be "local" or "remote". 
  
 >+_end_reason_+: 

 >A 
   [[BR]]''end_reason'':[[BR]] 
   A string representing the termination reason, such as @"user_request"@, @"SIP {{{"user_request"}}}, {{{"SIP core error..."@. 

 *SIPSessionDidChangeHoldState* 
 >Will error..."}}}. 

  '''SIPSessionDidChangeHoldState''':: 
   Will be sent when the session got put on hold or removed from hold, either by the local or the remote party. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >A 
   [[BR]]''originator'':[[BR]] 
   A string indicating who originated the hold request, and consequently in which direction the session got put on hold. 
  
 >+_on_hold_+: 

   @True@ 
   [[BR]]''on_hold'':[[BR]] 
   {{{True}}} if there is at least one stream which is on hold and @False@ {{{False}}} otherwise. 
  
 >+_partial_+: 

   @True@ 
   [[BR]]''partial'':[[BR]] 
   {{{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@ {{{False}}} otherwise. 

 *SIPSessionGotProposal* 
 >Will 

  '''SIPSessionGotProposal''':: 
   Will be sent when either the local or the remote party proposes to add streams to the session. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >The 
   [[BR]]''originator'':[[BR]] 
   The party that initiated the stream proposal, can be either "local" or "remote". 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   A list of streams that were proposed. 

 *SIPSessionGotRejectProposal* 
 >Will 

  '''SIPSessionGotRejectProposal''':: 
   Will be sent when either the local or the remote party rejects a proposal to have streams added to the session. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >The 
   [[BR]]''originator'':[[BR]] 
   The party that initiated the stream proposal, can be either "local" or "remote". 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The code with which the proposal was rejected. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The reason for rejecting the stream proposal. 
  
 >+_streams_+: 

 >The 
   [[BR]]''streams'':[[BR]] 
   The list of streams which were rejected. 

 *SIPSessionGotAcceptProposal* 
 >Will 

  '''SIPSessionGotAcceptProposal''':: 
   Will be sent when either the local or the remote party accepts a proposal to have stream( added to the session. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >The 
   [[BR]]''originator'':[[BR]] 
   The party that initiated the stream proposal, can be either "local" or "remote". 
  
 >+_streams_+: 

 >The 
   [[BR]]''streams'':[[BR]] 
   The list of streams which were accepted. 
  
 >+_proposed_streams_+: 

 >The 
   [[BR]]''proposed_streams'':[[BR]] 
   The list of streams which were originally proposed. 

 *SIPSessionHadProposalFailure* 
 >Will 

  '''SIPSessionHadProposalFailure''':: 
   Will be sent when a re-INVITE fails because of an internal reason (such as a stream not being able to start). 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_failure_reason_+: 

 >The 
   [[BR]]''failure_reason'':[[BR]] 
   The error which caused the proposal to fail. 
  
 >+_streams_+: 

 >The 
   [[BR]]''streams'':[[BR]] 
   The streams which were part of this proposal. 

 *SIPSessionDidRenegotiateStreams* 
 >Will 

  '''SIPSessionDidRenegotiateStreams''':: 
   Will be sent when a media stream is either activated or deactivated. 
 >An 
   An application should listen to this notification in order to know when a media stream can be used. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_action_+: 

 >A 
   [[BR]]''action'':[[BR]] 
   A string which is either @"add"@ {{{"add"}}} or @"remove"@ {{{"remove"}}} which specifies what happened to the streams the notificaton referes to 
  
 >+_streams_+: 

 >A 
   [[BR]]''streams'':[[BR]] 
   A list with the streams which were added or removed. 

 *SIPSessionDidProcessTransaction* 
 >Will 

  '''SIPSessionDidProcessTransaction''':: 
   Will be sent whenever a SIP transaction is complete in order to provide low-level details of the progress of the INVITE dialog. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_originator_+: 

 >The 
   [[BR]]''originator'':[[BR]] 
   The initiator of the transaction, @"local"@ {{{"local"}}} or @"remote"@. 
  
 >+_method_+: 

 >The {{{"remote"}}}. 
   [[BR]]''method'':[[BR]] 
   The method of the request. 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP status code of the response. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The SIP status reason of the response. 
  
 >+_ack_received_+: 

 >This 
   [[BR]]''ack_received'':[[BR]] 
   This attribute is only present for INVITE transactions and has one of the values @True@, @False@ {{{True}}}, {{{False}}} or @"unknown"@. {{{"unknown"}}}. The last value may occur then PJSIP does not let us know whether the ACK was received or not. 

 *SIPSessionTransferNewOutgoing* 
 >Will 

  '''SIPSessionTransferNewOutgoing''':: 
   Will be sent whenever a SIP session initiates an outgoing call transfer request. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_transfer_destination_+: 

 >The 
   [[BR]]''transfer_destination'':[[BR]] 
   The destination SIP URI of the call transfer request. 
  
 >+_transfer_source_+: 

 >The 
   [[BR]]''transfer_source'':[[BR]] 
   The source SIP URI of the call transfer request. 

 *SIPSessionTransferDidStart* 
 >Will 

  '''SIPSessionTransferDidStart''':: 
   Will be sent whenever a call transfer has been started. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPSessionTransferDidFail* 
 >Will 

  '''SIPSessionTransferDidFail''':: 
   Will be sent whenever a call transfer request has failed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP failure code reported by the SIP stack. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The reason of the failure as a string. 


 As an example for how to use the @Session@ {{{Session}}} object, the following provides a basic Python program that initiates an outgoing SIP session request see [[SipSessionExample|Minimalist [wiki:SipSessionExample Minimalist Session Example code]]. 


 h3. code]. 

 === IMediaStream 


 === 

 Implemented in [browser:sipsimple/streams/+init+.py] [browser:sipsimple/streams/__init__.py] 

 This interface describes the API which the @Session@ {{{Session}}} uses to communicate with the streams. All streams used by the @Session@ +must+ {{{Session}}} __must__ respect this interface. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, _account_) 
 >Initializes ==== 


  '''!__init!__'''(''self'', ''account''):: 
   Initializes the generic stream instance. 

 *new_from_sdp*(_cls_, _account_, _remote_sdp_, _stream_index_) 
 >A 

  '''new_from_sdp'''(''cls'', ''account'', ''remote_sdp'', ''stream_index''):: 
   A classmethod which returns an instance of this stream implementation if the sdp is accepted by the stream or None otherwise. 
  
 account: 

 >The @sipsimple.account.Account@ 
   [[BR]]account:[[BR]] 
   The {{{sipsimple.account.Account}}} or @sipsimple.account.BonjourAccount@ {{{sipsimple.account.BonjourAccount}}} object the session which this stream would be part of is associated with. 
  
 remote_sdp: 

 >The @FrozenSDPSession@ 
   [[BR]]remote_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which was received by the remote offer. 
  
 stream_index: 

 >An 
   [[BR]]stream_index:[[BR]] 
   An integer representing the index within the list of media streams within the whole SDP which this stream would be instantiated for.  

 *get_local_media*(_self_, _for_offer_) 
 >Return  

  '''get_local_media'''(''self'', ''for_offer''):: 
   Return an @SDPMediaStream@ {{{SDPMediaStream}}} which represents an offer for using this stream if @for_offer@ {{{for_offer}}} is @True@ {{{True}}} and a response to an SDP proposal otherwise. 
  
 for_offer: 

   @True@ 
   [[BR]]for_offer:[[BR]] 
   {{{True}}} if the @SDPMediaStream@ {{{SDPMediaStream}}} will be used for an SDP proposal and @False@ {{{False}}} if for a response. 

 *initialize*(_self_, _session_, _direction_) 
 >Initializes 

  '''initialize'''(''self'', ''session'', ''direction''):: 
   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@. {{{Session}}}. If initialization goes fine, the stream must send a @MediaStreamDidInitialize@ {{{MediaStreamDidInitialize}}} notification or a @MediaStreamDidFail@ {{{MediaStreamDidFail}}} notification otherwise. 
  
 session: 

 >The @Session@ 
   [[BR]]session:[[BR]] 
   The {{{Session}}} object this stream will be part of. 
  
 direction: 

   @"incoming"@ 
   [[BR]]direction:[[BR]] 
   {{{"incoming"}}} if the stream was created because of a received proposal and @"outgoing"@ {{{"outgoing"}}} if a proposal was sent. Note that this need not be the same as the initial direction of the @Session@ {{{Session}}} since streams can be proposed in either way using re-INVITEs. 

 *start*(_self_, _local_sdp_, _remote_sdp_, _stream_index_) 
 >Starts 

  '''start'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index''):: 
   Starts the stream. This method will be called as soon is known to be used in the @Session@ {{{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@ {{{MediaStreamDidStart}}} notification or a @MediaStreamDidFail@ {{{MediaStreamDidFail}}} notification otherwise. 
  
 local_sdp: 

 >The @FrozenSDPSession@ 
   [[BR]]local_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which is used by the local endpoint. 
  
 remote_sdp: 

 >The @FrozenSDPSession@ 
   [[BR]]remote_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which is used by the remote endpoint. 
  
 stream_index: 

 >An 
   [[BR]]stream_index:[[BR]] 
   An integer representing the index within the list of media streams within the whole SDP which this stream is represented by.  

 *validate_update*(_self_, _remote_sdp_, _stream_index_) 
 >This  

  '''validate_update'''(''self'', ''remote_sdp'', ''stream_index''):: 
   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@ {{{True}}} if the changes are acceptable or @False@ {{{False}}} otherwise. If any changed streams return @False@ {{{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@.  
  
 remote_sdp: 

 >The @FrozenSDPSession@ {{{True}}}.  
   [[BR]]remote_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which is used by the remote endpoint. 
  
 stream_index: 

 >An 
   [[BR]]stream_index:[[BR]] 
   An integer representing the index within the list of media streams within the whole SDP which this stream is represented by.  

 *update*(_self_, _local_sdp_, _remote_sdp_, _stream_index_) 
 >This  

  '''update'''(''self'', ''local_sdp'', ''remote_sdp'', ''stream_index''):: 
   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. 
  
 local_sdp: 

 >The @FrozenSDPSession@ 
   [[BR]]local_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which is used by the local endpoint. 
  
 remote_sdp: 

 >The @FrozenSDPSession@ 
   [[BR]]remote_sdp:[[BR]] 
   The {{{FrozenSDPSession}}} which is used by the remote endpoint. 
  
 stream_index: 

 >An 
   [[BR]]stream_index:[[BR]] 
   An integer representing the index within the list of media streams within the whole SDP which this stream is represented by.  

 *hold*(_self_) 
 >Puts  

  '''hold'''(''self''):: 
   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()@ {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state. 

 *unhold*(_self_) 
 >Takes 

  '''unhold'''(''self''):: 
   Takes the stream off hold. Typically used by audio and video streams. Calls to @get_local_media()@ {{{get_local_media()}}} following calls to this method must return an SDP which reflects the new hold state. 

 *deactivate*(_self_) 
 >This 

  '''deactivate'''(''self''):: 
   This method is called on a stream just before the stream will be removed from the @Session@ {{{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. 

 *end*(_self_) 
 >Ends 

  '''end'''(''self''):: 
   Ends the stream. This must close the underlying transport connection. The stream must send a @MediaStreamWillEnd@ {{{MediaStreamWillEnd}}} just after this method is called and a @MediaStreamDidEnd@ {{{MediaStreamDidEnd}}} as soon as the operation is complete. This method is always be called by the @Session@ {{{Session}}} on the stream if at least the @initialize()@ {{{initialize()}}} method has been called. This means that once a stream sends the @MediaStreamDidFail@ {{{MediaStreamDidFail}}} notification, the @Session@ {{{Session}}} will still call this method. 


 h4. 

 ==== attributes 



 *type* ==== 


  '''type''' (class attribute) 
 >A attribute):: 
   A string identifying the stream type (eg: @"audio"@, @"video"@). 

 *priority* {{{"audio"}}}, {{{"video"}}}). 

  '''priority''' (class attribute) 
 >An attribute):: 
   An integer value indicating the stream priority relative to the other streams types (higher numbers have higher priority). 

 *hold_supported* 
 >True 

  '''hold_supported''':: 
   True if the stream supports hold 

 *on_hold_by_local* 
 >True 

  '''on_hold_by_local''':: 
   True if the stream is on hold by the local party 

 *on_hold_by_remote* 
 >True 

  '''on_hold_by_remote''':: 
   True if the stream is on hold by the remote 

 *on_hold* 
 >True 

  '''on_hold''':: 
   True if either on_hold_by_local or on_hold_by_remote is true 


 h4. 

 ==== notifications 


 ==== 

 These notifications must be generated by all streams in order for the @Session@ {{{Session}}} to know the state of the stream. 


 *MediaStreamDidInitialize* 
 >Sent 


  '''MediaStreamDidInitialize''':: 
   Sent when the stream has been successfully initialized. 

 *MediaStreamDidStart* 
 >Sent 

  '''MediaStreamDidStart''':: 
   Sent when the stream has been successfully started. 

 *MediaStreamDidFail* 
 >Sent 

  '''MediaStreamDidFail''':: 
   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). 

 *MediaStreamWillEnd* 
 >Sent 

  '''MediaStreamWillEnd''':: 
   Sent immediately after the @end()@ {{{end()}}} method is called. 

 *MediaStreamDidEnd* 
 >Sent 

  '''MediaStreamDidEnd''':: 
   Sent when the @end()@ {{{end()}}} method finished closing the stream. 


 h3. 

 === MediaStreamRegistry 


 === 

 The MediaStream registry is a collection of classes which implement @IMediaStream@. {{{IMediaStream}}}. This collection is used by the @Session@ {{{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@. {{{Session}}}. This object is a Singleton so references to the same object can be obtained by a simple instantiation. 

 There are several pre-built streams based on the @IMediaStream@ {{{IMediaStream}}} API: 
 
  * @sipsimple.streams.rtp.AudioStream@ {{{sipsimple.streams.rtp.AudioStream}}} - Audio stream based on RTP 
 
  * @sipsimple.streams.msrp.ChatStream@ {{{sipsimple.streams.msrp.ChatStream}}} - Chat stream based on MSRP  
  
  * @sipsimple.streams.msrp.FileTransferStream@ {{{sipsimple.streams.msrp.FileTransferStream}}} - File Transfer stream based on MSRP  
  
  * @sipsimple.streams.msrp.DesktopSharingStream@ {{{sipsimple.streams.msrp.DesktopSharingStream}}} -    Desktop Sharing stream based on VNC over MSRP 

 Other streams which are created by the application must be registered in this registry. For a simple way of doing this, see [[SipMiddlewareApi#MediaStreamRegistrar|MediaStreamRegistrar]]. 


 h4. [wiki:SipMiddlewareApi#MediaStreamRegistrar MediaStreamRegistrar]. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_) 
 >Instantiate ==== 


  '''!__init!__'''(''self''):: 
   Instantiate the MediaStreamRegistry. This will be called just once when first (and only) instance is created. 

 *<notextile>__iter__</notextile>*(_self_) 
 >This 

  '''!__iter!__'''(''self''):: 
   This method allows the registry to be iterated through and will return classes which were registered to it. 

 *add*(_self_, *cls*) 
 >Add @cls@ 

  '''add'''(''self'', '''cls'''):: 
   Add {{{cls}}} to the registry of streams. The class must implement the @IMediaStream@ {{{IMediaStream}}} interface. 


 h3. 

 === MediaStreamRegistrar 


 === 

 This is a convenience metaclass which automatically registers a defined class with the @MediaStreamRegistry@. {{{MediaStreamRegistry}}}. In order to use this class, one simply needs to use it as the metaclass of the new stream. 

 <pre> 
 {{{ 
 from zope.interface import implements 

 from sipsimple.streams import IMediaStream, MediaStreamRegistrar 


 class MyStream(object): 
   __metaclass__ = MediaStreamRegistrar 

   implements(IMediaStream) 
  
 [...]  
 </pre> 


 h3. }}} 

 === AudioStream 


 === 

 Implemented in [browser:sipsimple/streams/rtp.py] 

 The @AudioStream@ {{{AudioStream}}} is an implementation of @IMediaStream@ {{{IMediaStream}}} which supports audio data using the @AudioTransport@ {{{AudioTransport}}} and @RTPTransport@ {{{RTPTransport}}} of the SIP core. As such, it provides all features of these objects, including ICE negotiation. An example SDP created using the @AudioStream@ {{{AudioStream}}} is provided below: 

 <pre> 
 {{{ 
 Content-Type: application/sdp 
 Content-Length:    1093 

 v=0 
 o=- 3467525278 3467525278 IN IP4 192.168.1.6 
 s=blink-0.10.7-beta 
 c=IN IP4 80.101.96.20 
 t=0 0 
 m=audio 55328 RTP/AVP 104 103 102 3 9 0 8 101 
 a=rtcp:55329 IN IP4 80.101.96.20 
 a=rtpmap:104 speex/32000 
 a=rtpmap:103 speex/16000 
 a=rtpmap:102 speex/8000 
 a=rtpmap:3 GSM/8000 
 a=rtpmap:9 G722/8000 
 a=rtpmap:0 PCMU/8000 
 a=rtpmap:8 PCMA/8000 
 a=rtpmap:101 telephone-event/8000 
 a=fmtp:101 0-15 
 a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:esI6DbLY1+Aceu0JNswN9Z10DcFx5cZwqJcu91jb 
 a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:SHuEMm1BYJqOF4udKl73EaCwnsI57pO86bYKsg70 
 a=ice-ufrag:2701ed80 
 a=ice-pwd:6f8f8281 
 a=candidate:S 1 UDP 31 80.101.96.20 55328 typ srflx raddr 192.168.1.6 rport 55328 
 a=candidate:H 1 UDP 23 192.168.1.6 55328 typ host 
 a=candidate:H 1 UDP 23 10.211.55.2 55328 typ host 
 a=candidate:H 1 UDP 23 10.37.129.2 55328 typ host 
 a=candidate:S 2 UDP 30 80.101.96.20 55329 typ srflx raddr 192.168.1.6 rport 55329 
 a=candidate:H 2 UDP 22 192.168.1.6 55329 typ host 
 a=candidate:H 2 UDP 22 10.211.55.2 55329 typ host 
 a=candidate:H 2 UDP 22 10.37.129.2 55329 typ host 
 a=sendrecv 
 </pre> }}} 

 As an implementation of @IAudioPort@, {{{IAudioPort}}}, an @AudioStream@ {{{AudioStream}}} can be added to an @AudioBridge@ {{{AudioBridge}}} to send or to read audio data to/from other audio objects. It is connected to the voice @AudioMixer@ (@SIPApplication.voice_audio_mixer@) {{{AudioMixer}}} ({{{SIPApplication.voice_audio_mixer}}}) so it can only be added to bridges using the same @AudioMixer@. {{{AudioMixer}}}. It also contains an @AudioBridge@ {{{AudioBridge}}} on the @bridge@ {{{bridge}}} attribute which always contains an @AudioDevice@ {{{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@ {{{WaveRecorder}}} which records audio data. 


 h4. 

 ==== methods 



 *start_recording*(_self_, *filename*=@None@) 
 >If ==== 


  '''start_recording'''(''self'', '''filename'''={{{None}}}):: 
   If an audio stream is present within this session, calling this method will record the audio to a @.wav@ {{{.wav}}} file. 
 >Note 
   Note that when the session is on hold, nothing will be recorded to the file. 
 >Right 
   Right before starting the recording a @SIPSessionWillStartRecordingAudio@ {{{SIPSessionWillStartRecordingAudio}}} notification will be emitted, followed by a @SIPSessionDidStartRecordingAudio@. 
 >This {{{SIPSessionDidStartRecordingAudio}}}. 
   This method may only be called while the stream is started. 
  
 >+_filename_+: 

 >The 
   [[BR]]''filename'':[[BR]] 
   The name of the @.wav@ {{{.wav}}} file to record to. 
 >If 
   If this is set to @None@, {{{None}}}, a default file name including the session participants and the timestamp will be generated using the directory defined in the configuration. 

 *stop_recording*(_self_) 
 >This 

  '''stop_recording'''(''self''):: 
   This will stop a previously started recording. 
 >Before 
   Before stopping, a @SIPSessionWillStopRecordingAudio@ {{{SIPSessionWillStopRecordingAudio}}} notification will be sent, followed by a @SIPSessionDidStopRecordingAudio@. 

 *send_dtmf*(_self_, *digit*) 
 >If {{{SIPSessionDidStopRecordingAudio}}}. 

  '''send_dtmf'''(''self'', '''digit'''):: 
   If the audio stream is started, sends a DTMF digit to the remote party. 
  
 >+_digit_+: 

 >This 
   [[BR]]''digit'':[[BR]] 
   This should a string of length 1, containing a valid DTMF digit value (0-9, A-D, * or #). 


 h4. 

 ==== attributes 



 *sample_rate* 
 >If ==== 


  '''sample_rate''':: 
   If the audio stream was started, this attribute contains the sample rate of the audio negotiated. 

 *codec* 
 >If 

  '''codec''':: 
   If the audio stream was started, this attribute contains the name of the audio codec that was negotiated. 

 *srtp_active* 
 >If 

  '''srtp_active''':: 
   If the audio stream was started, this boolean attribute indicates if SRTP is currently being used on the stream. 

 *ice_active* 

  '''ice_active''':: 
   @True@ {{{True}}} if the ICE candidates negotiated are being used, @False@ {{{False}}} otherwise. 

 *local_rtp_address* 
 >If 

  '''local_rtp_address''':: 
   If an audio stream is present within the session, this attribute contains the local IP address used for the audio stream. 

 *local_rtp_port* 
 >If 

  '''local_rtp_port''':: 
   If an audio stream is present within the session, this attribute contains the local UDP port used for the audio stream. 

 *remote_rtp_address_sdp* 
 >If 

  '''remote_rtp_address_sdp''':: 
   If the audio stream was started, this attribute contains the IP address that the remote party gave to send audio to. 

 *remote_rtp_port_sdp* 
 >If 

  '''remote_rtp_port_sdp''':: 
   If the audio stream was started, this attribute contains the UDP port that the remote party gave to send audio to. 

 *remote_rtp_address_received* 
 >If 

  '''remote_rtp_address_received''':: 
   If the audio stream was started, this attribute contains the remote IP address from which the audio stream is being received. 

 *remote_rtp_port_received* 
 >If 

  '''remote_rtp_port_received''':: 
   If the audio stream was started, this attribute contains the remote UDP port from which the audio stream is being received. 

 *local_rtp_candidate_type* 
 >The 

  '''local_rtp_candidate_type''':: 
   The local ICE candidate type which was selected by the ICE negotiation if it succeeded and @None@ {{{None}}} otherwise. 

 *remote_rtp_candidate_type* 
 >The 

  '''remote_rtp_candidate_type''':: 
   The remote ICE candidate type which was selected by the ICE negotiation if it succeeded and @None@ {{{None}}} otherwise. 

 *recording_filename* 
 >If 

  '''recording_filename''':: 
   If the audio stream is currently being recorded to disk, this property contains the name of the @.wav@ {{{.wav}}} file being recorded to. 


 h4. 

 ==== notifications 



 *AudioStreamDidChangeHoldState* 
 >Will ==== 


  '''AudioStreamDidChangeHoldState''':: 
   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()@ {{{hold()/unhold()}}} methods on the @Session@ {{{Session}}} this stream is part of. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 originator: 

 >A 
   [[BR]]originator:[[BR]] 
   A string representing the party which requested the hold change, @"local"@ {{{"local"}}} or @"remote"@ 
  
 on_hold: 

 >A {{{"remote"}}} 
   [[BR]]on_hold:[[BR]] 
   A boolean indicating the new hold state from the point of view of the originator. 

 *AudioStreamWillStartRecordingAudio_ 
 >Will 

  '''AudioStreamWillStartRecordingAudio'':: 
   Will be sent when the application requested that the audio stream be recorded to a @.wav@ {{{.wav}}} file, just before recording starts. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_filename_+: 

 >The 
   [[BR]]''filename'':[[BR]] 
   The full path to the @.wav@ {{{.wav}}} file being recorded to. 

 *AudioStreamDidStartRecordingAudio* 
 >Will 

  '''AudioStreamDidStartRecordingAudio''':: 
   Will be sent when the application requested that the audio stream be recorded to a @.wav@ {{{.wav}}} file, just after recording started. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_filename_+: 

 >The 
   [[BR]]''filename'':[[BR]] 
   The full path to the @.wav@ {{{.wav}}} file being recorded to. 

 *AudioStreamWillStopRecordingAudio* 
 >Will 

  '''AudioStreamWillStopRecordingAudio''':: 
   Will be sent when the application requested ending the recording to a @.wav@ {{{.wav}}} file, just before recording stops. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_filename_+: 

 >The 
   [[BR]]''filename'':[[BR]] 
   The full path to the @.wav@ {{{.wav}}} file being recorded to. 

 *AudioStreamDidStopRecordingAudio* 
 >Will 

  '''AudioStreamDidStopRecordingAudio''':: 
   Will be sent when the application requested ending the recording to a @.wav@ {{{.wav}}} file, just after recording stoped. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_filename_+: 

 >The 
   [[BR]]''filename'':[[BR]] 
   The full path to the @.wav@ {{{.wav}}} file being recorded to. 

 *AudioStreamDidChangeRTPParameters* 
 >This 

  '''AudioStreamDidChangeRTPParameters''':: 
   This notification is sent when the RTP parameters are changed, such as codec, sample rate, RTP port etc. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *AudioStreamGotDTMF* 
 >Will 

  '''AudioStreamGotDTMF''':: 
   Will be send if there is a DMTF digit received from the remote party on the audio stream.  
  
 >+_timestamp_+: 

 >A @datetime.datetime@  
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_digit_+: 

 >The 
   [[BR]]''digit'':[[BR]] 
   The DTMF digit that was received, in the form of a string of length 1. 

 *AudioStreamICENegotiationStateDidChange* 
 >This 

  '''AudioStreamICENegotiationStateDidChange''':: 
   This notification is proxied from the @RTPTransport@ {{{RTPTransport}}} and as such has the same data as the @RTPTransportICENegotiationStateDidChange@. 

 *AudioStreamICENegotiationDidSucceed* 
 >This {{{RTPTransportICENegotiationStateDidChange}}}. 

  '''AudioStreamICENegotiationDidSucceed''':: 
   This notification is proxied from the @RTPTransport@ {{{RTPTransport}}} and as such has the same data as the @RTPTransportICENegotiationDidSucceed@. 

 *AudioStreamICENegotiationDidFail* 
 >This {{{RTPTransportICENegotiationDidSucceed}}}. 

  '''AudioStreamICENegotiationDidFail''':: 
   This notification is proxied from the @RTPTransport@ {{{RTPTransport}}} and as such has the same data as the @RTPTransportICENegotiationDidFail@. 

 *AudioStreamDidTimeout* 
 >This {{{RTPTransportICENegotiationDidFail}}}. 

  '''AudioStreamDidTimeout''':: 
   This notification is proxied from the @RTPTransport@. {{{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@). 


 h3. {{{Account}}}). 

 === MSRPStreamBase 


 === 

 Implemented in [browser:sipsimple/streams/msrp.py] 

 The @MSRPStreamBase@ {{{MSRPStreamBase}}} is used as a base class for streams using the MSRP protocol. Within the SIP SIMPLE middleware, this hold for the @ChatStream@, @FileTransferStream@ {{{ChatStream}}}, {{{FileTransferStream}}} and @DesktopSharingStream@ {{{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. 


 h4. 

 ==== methods 

 
 ==== 
 
 Of the methods defined by the @IMediaStream@ {{{IMediaStream}}} interface, only the @new_from_sdp@ {{{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@, {{{_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 {{{_NH_<notification name>(self, notification)@ notification)}}} as used throughout the middleware in order to do various things at the different points within the life-cycle of the stream. 


 h4. 

 ==== attributes 


 ==== 

 The attributes defined in the @IMediaStream@ {{{IMediaStream}}} interface which are not provided by this class are: 
 
  * type 
 
  * priority 

 In addition, the following attributes need to be defined in the subclass in order for the @MSRPStreamBase@ {{{MSRPStreamBase}}} class to take the correct decisions 

 *media_type* 
 >The 

  '''media_type''':: 
   The media type as included in the SDP (eg. @"message"@, @"application"@). 

 *accept_types* 
 >A {{{"message"}}}, {{{"application"}}}). 

  '''accept_types''':: 
   A list of the MIME types which should be accepted by the stream (this is also sent within the SDP). 

 *accept_wrapped_types* 
 >A 

  '''accept_wrapped_types''':: 
   A list of the MIME types which should be accepted by the stream while wrapped in a @message/cpim@ {{{message/cpim}}} envelope. 

 *use_msrp_session* 
 >A 

  '''use_msrp_session''':: 
   A boolean indicating whether or not an @MSRPSession@ {{{MSRPSession}}} should be used. 


 h4. 

 ==== notifications 


 ==== 

 While not technically notifications of @MSRPStreamBase@, {{{MSRPStreamBase}}}, these notifications are sent from the middleware on behalf of the @MSRPTransport@ {{{MSRPTransport}}} used by a stream in the former case, and anonymously in the latter. 


 *MSRPTransportTrace* 
 >This 


  '''MSRPTransportTrace''':: 
   This notification is sent when an MSRP message is received for logging purposes. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 direction: 

 >The 
   [[BR]]direction:[[BR]] 
   The direction of the message, @"incoming"@ {{{"incoming"}}} or @"outgoing"@. 
  
 data: 

 >The {{{"outgoing"}}}. 
   [[BR]]data:[[BR]] 
   The MSRP message as a string. 

 *MSRPLibraryLog* 
 >This 

  '''MSRPLibraryLog''':: 
   This notification is sent anonymously whenever the MSRP library needs to log any information. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message: 

 >The 
   [[BR]]message:[[BR]] 
   The log message as a string. 
  
 level: 

 >The 
   [[BR]]level:[[BR]] 
   The log level at which the message was written. One of the levels @DEBUG@, @INFO@, @WARNING@, @ERROR@, @CRITICAL@ {{{DEBUG}}}, {{{INFO}}}, {{{WARNING}}}, {{{ERROR}}}, {{{CRITICAL}}} from the @application.log.level@ {{{application.log.level}}} object which is part of the @python-application@ {{{python-application}}} library. 


 h3. 

 === ChatStream 


 === 

 Implemented in [browser:sipsimple/streams/msrp.py] 

 @sipsimple.streams.msrp.ChatStream@ {{{sipsimple.streams.msrp.ChatStream}}} implements session-based Instant Messaging (IM) over MSRP. This class performs the following functions: 

 

  * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types 
 
  * unwraps incoming Message/CPIM messages; for each incoming message, the @ChatStreamGotMessage@ {{{ChatStreamGotMessage}}} notification is posted 
 
  * composes iscomposing payloads and reacts to those received by sending the @ChatStreamGotComposingIndication@ {{{ChatStreamGotComposingIndication}}} notification 

 An example of an SDP created using this class follows: 

 <pre> 
 {{{ 
 Content-Type: application/sdp 
 Content-Length:     283 

 v=0 
 o=- 3467525214 3467525214 IN IP4 192.168.1.6 
 s=blink-0.10.7-beta 
 c=IN IP4 192.168.1.6 
 t=0 0 
 m=message 2855 TCP/TLS/MSRP * 
 a=path:msrps://192.168.1.6:2855/ca7940f12ddef14c3c32;tcp 
 a=accept-types:message/cpim text/* application/im-iscomposing+xml 
 a=accept-wrapped-types:* 
 </pre> 


 h4. }}} 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *account*, *direction*=@'sendrecv'@) 
 >Initializes ==== 


  '''!__init!__'''(''self'', '''account''', '''direction'''={{{'sendrecv'}}}):: 
   Initializes the ChatStream instance. 


 *send_message*(_self_, *content*, *content_type*=@'text/plain'@, *recipients*=@None@, *courtesy_recipients*=@None@, *subject*=@None@, _timestamp_=@None@, *required*=@None@, *additional_headers*=@None@) 
 >Sends 


  '''send_message'''(''self'', '''content''', '''content_type'''={{{'text/plain'}}}, '''recipients'''={{{None}}}, '''courtesy_recipients'''={{{None}}}, '''subject'''={{{None}}}, ''timestamp''={{{None}}}, '''required'''={{{None}}}, '''additional_headers'''={{{None}}}):: 
   Sends an IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be 
 >queued 
   queued until the stream starts. 
 >Returns 
   Returns the generated MSRP message ID. 
  
 content: 

 >The 
   [[BR]]content:[[BR]] 
   The content of the message. 
  
 content_type: 

 >Content-Type 
   [[BR]]content_type:[[BR]] 
   Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case); 
 >otherwise, 
   otherwise, Content-Type of MSRP message. 
  
 recipients: 

 >The 
   [[BR]]recipients:[[BR]] 
   The list of @CPIMIdentity@ {{{CPIMIdentity}}} objects which will be used for the @To@ {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity. 
 >May 
   May only differ from the default one if the remote party supports private messages. If it does not, a @ChatStreamError@ {{{ChatStreamError}}} will be raised. 
  
 courtesy_recipients: 

 >The 
   [[BR]]courtesy_recipients:[[BR]] 
   The list of @CPIMIdentity@ {{{CPIMIdentity}}} objects which will be used for the @cc@ {{{cc}}} header of the CPIM wrapper. 
 >May 
   May only be specified if the remote party supports private messages and CPIM is supported. If it does not, a @ChatStreamError@ {{{ChatStreamError}}} will be raised. 
  
 subject: 

 >A 
   [[BR]]subject:[[BR]] 
   A string or @MultilingualText@ {{{MultilingualText}}} which specifies the subject and its translations to be added to the CPIM message. If CPIM is not supported, a @ChatStreamError@ {{{ChatStreamError}}} will be raised. 
  
 required: 

 >A 
   [[BR]]required:[[BR]] 
   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@ {{{ChatStreamError}}} will be raised. 
  
 additional_headers: 

 >A 
   [[BR]]additional_headers:[[BR]] 
   A list of MSRP header objects which will be added to this CPIM message. If CPIM is not supported, a @ChatStreamError@ {{{ChatStreamError}}} will be raised. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object representing the timestamp to put on the CPIM wrapper of the message. 
 >When 
   When set to @None@, {{{None}}}, a default one representing the current moment will be added. 

  These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses: 
 <pre> 
 {{{ 
 Failure-Report: partial 
 Success-Report: yes 
 </pre> 


 *send_composing_indication*(_self_, _state_, _refresh_, _last_active=None_, _recipients=None_) 
 >Sends }}} 


  '''send_composing_indication'''(''self'', ''state'', ''refresh'', ''last_active=None'', ''recipients=None''):: 
   Sends an is-composing message to the listed recipients. 
  
 state: 

 >The 
   [[BR]]state:[[BR]] 
   The state of the endpoint, @"active"@ {{{"active"}}} or @"idle"@. 
  
 refresh: 

 >How {{{"idle"}}}. 
   [[BR]]refresh:[[BR]] 
   How often the local endpoint will send is-composing indications to keep the state from being reverted to @"idle"@. 
  
 last_active: 

 >A @datatime.datetime@ {{{"idle"}}}. 
   [[BR]]last_active:[[BR]] 
   A {{{datatime.datetime}}} object representing the moment when the local endpoint was last active. 
  
 recipients: 

 >The 
   [[BR]]recipients:[[BR]] 
   The list of @CPIMIdentity@ {{{CPIMIdentity}}} objects which will be used for the @To@ {{{To}}} header of the CPIM wrapper. Used to override the default which depends on the remote identity. 
 >May 
   May only differ from the default one if the remote party supports private messages. If it does not, a @ChatStreamError@ {{{ChatStreamError}}} will be raised. 


 h4. 

 ==== notifications 



 *ChatStreamGotMessage* 
 >Sent ==== 


  '''ChatStreamGotMessage''':: 
   Sent whenever a new incoming message is received, 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message: 

 >A @ChatMessage@ 
   [[BR]]message:[[BR]] 
   A {{{ChatMessage}}} or @CPIMMessage@ {{{CPIMMessage}}} instance, depending on whether a CPIM message was received or not. 

 *ChatStreamDidDeliverMessage* 
 >Sent 

  '''ChatStreamDidDeliverMessage''':: 
   Sent when a successful report is received. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message_id: 

 >Text 
   [[BR]]message_id:[[BR]] 
   Text identifier of the message. 
  
 code: 

 >The 
   [[BR]]code:[[BR]] 
   The status code received. Will always be 200 for this notification. 
  
 reason: 

 >The 
   [[BR]]reason:[[BR]] 
   The status reason received. 
  
 chunk: 

 >A @msrplib.protocol.MSRPData@ 
   [[BR]]chunk:[[BR]] 
   A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report. 

 *ChatStreamDidNotDeliverMessage* 
 >Sent 

  '''ChatStreamDidNotDeliverMessage''':: 
   Sent when a failure report is received. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message_id: 

 >Text 
   [[BR]]message_id:[[BR]] 
   Text identifier of the message. 
  
 code: 

 >The 
   [[BR]]code:[[BR]] 
   The status code received. 
  
 reason: 

 >The 
   [[BR]]reason:[[BR]] 
   The status reason received. 
  
 chunk: 

 >A @msrplib.protocol.MSRPData@ 
   [[BR]]chunk:[[BR]] 
   A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the report. 

 *ChatStreamDidSendMessage* 
 >Sent 

  '''ChatStreamDidSendMessage''':: 
   Sent when an outgoing message has been sent. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message: 

 >A @msrplib.protocol.MSRPData@ 
   [[BR]]message:[[BR]] 
   A {{{msrplib.protocol.MSRPData}}} instance providing all the MSRP information about the sent message. 

 *ChatStreamGotComposingIndication* 
 >Sent 

  '''ChatStreamGotComposingIndication''':: 
   Sent when a is-composing payload is received. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 state: 

 >The 
   [[BR]]state:[[BR]] 
   The state of the endpoint, @"active"@ {{{"active"}}} or @"idle"@. 
  
 refresh: 

 >How {{{"idle"}}}. 
   [[BR]]refresh:[[BR]] 
   How often the remote endpoint will send is-composing indications to keep the state from being reverted to @"idle"@. {{{"idle"}}}. May be @None@. 
  
 last_active: 

 >A @datatime.datetime@ {{{None}}}. 
   [[BR]]last_active:[[BR]] 
   A {{{datatime.datetime}}} object representing the moment when the remote endpoint was last active. May be @None@. 
  
 content_type: 

 >The {{{None}}}. 
   [[BR]]content_type:[[BR]] 
   The MIME type of message being composed. May be @None@. 
  
 sender: 

 >The @ChatIdentity@ {{{None}}}. 
   [[BR]]sender:[[BR]] 
   The {{{ChatIdentity}}} or @CPIMIdentity@ {{{CPIMIdentity}}} instance which identifies the sender of the is-composing indication. 
  
 recipients: 

 >The @ChatIdentity@ 
   [[BR]]recipients:[[BR]] 
   The {{{ChatIdentity}}} or @CPIMIdentity@ {{{CPIMIdentity}}} instances list which identifies the recipients of the is-composing indication. 


 h3. 

 === FileSelector 


 === 

 The @FileSelector@ {{{FileSelector}}} is used to contain information about a file tranfer using the @FileTransferStream@ {{{FileTransferStream}}} documented below. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *name*=@None@, *type*=@None@, *size*=@None@, *hash*=@None@, *fd*=@None@) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''name'''={{{None}}}, '''type'''={{{None}}}, '''size'''={{{None}}}, '''hash'''={{{None}}}, '''fd'''={{{None}}}):: 
   Instantiate a new @FileSelector@. {{{FileSelector}}}. All the arguments are also available as attributes. 
  
 name: 

 >The 
   [[BR]]name:[[BR]] 
   The filename (should be just the base name). 
  
 type: 

 >The 
   [[BR]]type:[[BR]] 
   The type of the file. 
  
 size: 

 >The 
   [[BR]]size:[[BR]] 
   The size of the file in bytes. 
  
 hash: 

 >The 
   [[BR]]hash:[[BR]] 
   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@, {{{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@ {{{X}}} is a hexadecimal digit. Currently, only SHA1 hashes are supported according to the RFC. 
  
 fd: 

 >A 
   [[BR]]fd:[[BR]] 
   A file descriptor if the application has already opened the file. 

 *parse*(_cls_, *string*) 
 >Parses 

  '''parse'''(''cls'', '''string'''):: 
   Parses a file selector from the SDP @file-selector@ {{{file-selector}}} a attribute and returns a @FileSelector@ {{{FileSelector}}} instance. 

 *for_file*(_cls_, *path*, *content_type*, *compute_hash*=@True@) 
 >Returns 

  '''for_file'''(''cls'', '''path''', '''content_type''', '''compute_hash'''={{{True}}}):: 
   Returns a @FileSelector@ {{{FileSelector}}} instance for the specified file. The file identified by the path must exist. Note that if @compute_hash@ {{{compute_hash}}} is @True@ {{{True}}} this method will block while the hash is computed, a potentially long operation for large files. 
  
 path: 

 >The 
   [[BR]]path:[[BR]] 
   The full path to the file. 
  
 content_type: 

 >An 
   [[BR]]content_type:[[BR]] 
   An optional MIME type which is to be included in the file-selector. 
  
 compute_hash: 

 >Whether 
   [[BR]]compute_hash:[[BR]] 
   Whether or not this method should compute the hash of the file. 

 *compute_hash*(_self_) 
 >Compute 

  '''compute_hash'''(''self''):: 
   Compute the hash for this file selector. This method will block while the hash is computed, a potentially long operation for large files.  


 h4.  

 ==== attributes 



 *sdp_repr* 
 >The ==== 


  '''sdp_repr''':: 
   The SDP representation of the file-selector according to the RFC. This should be the value of the @file-selector@ {{{file-selector}}} SDP attribute. 


 h3. 

 === FileTransferStream 


 === 

 Implemented in [browser:sipsimple/streams/msrp.py] 

 The @FileTransferStream@ {{{FileTransferStream}}} supports file transfer over MSRP according to RFC5547. An example of SDP constructed using this stream follows: 

 <pre> 
 {{{ 
 Content-Type: application/sdp 
 Content-Length:     383 

 v=0 
 o=- 3467525166 3467525166 IN IP4 192.168.1.6 
 s=blink-0.10.7-beta 
 c=IN IP4 192.168.1.6 
 t=0 0 
 m=message 2855 TCP/TLS/MSRP * 
 a=path:msrps://192.168.1.6:2855/e593357dc9abe90754bd;tcp 
 a=sendonly 
 a=accept-types:* 
 a=accept-wrapped-types:* 
 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 
 </pre> 


 h4. }}} 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *account*, *file_selector*=@None@) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''account''', '''file_selector'''={{{None}}}):: 
   Instantiate a new @FileTransferStream@. {{{FileTransferStream}}}. If this is constructed by the application for an outgoing file transfer, the @file_selector@ {{{file_selector}}} argument must be present. 
  
 account: 

 >The @sipsimple.account.Account@ 
   [[BR]]account:[[BR]] 
   The {{{sipsimple.account.Account}}} or @sipsimple.account.BonjourAccount@ {{{sipsimple.account.BonjourAccount}}} instance which will be associated with the stream. 
  
 file_selector: 

 >The @FileSelector@ 
   [[BR]]file_selector:[[BR]] 
   The {{{FileSelector}}} instance which represents the file which is to be transferred. 


 h4. 

 ==== notifications 



 *FileTransferStreamDidDeliverChunk* 
 >This ==== 


  '''FileTransferStreamDidDeliverChunk''':: 
   This notification is sent for an outgoing file transfer when a success report is received about part of the file being transferred. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 message_id: 

 >The 
   [[BR]]message_id:[[BR]] 
   The MSRP message ID of the file transfer session. 
  
 chunk: 

 >An @msrplib.protocol.MSRPData@ 
   [[BR]]chunk:[[BR]] 
   An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT. 
  
 code: 

 >The 
   [[BR]]code:[[BR]] 
   The status code received. Will always be 200 for this notification. 
  
 reason: 

 >The 
   [[BR]]reason:[[BR]] 
   The status reason received. 
  
 transferred_bytes: 

 >The 
   [[BR]]transferred_bytes:[[BR]] 
   The number of bytes which have currently been successfully transferred. 
  
 file_size: 

 >The 
   [[BR]]file_size:[[BR]] 
   The size of the file being transferred. 

 *FileTransferStreamDidNotDeliverChunk* 
  
 timestamp: 

 >A @datetime.datetime@ 

  '''FileTransferStreamDidNotDeliverChunk''':: 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
 >This 
   This notification is sent for an outgoing file transfer when a failure report is received about part of the file being transferred. 
  
 message_id: 

 >The 
   [[BR]]message_id:[[BR]] 
   The MSRP message ID of the file transfer session. 
  
 chunk: 

 >An @msrplib.protocol.MSRPData@ 
   [[BR]]chunk:[[BR]] 
   An {{{msrplib.protocol.MSRPData}}} instance represented the received REPORT. 
  
 code: 

 >The 
   [[BR]]code:[[BR]] 
   The status code received. 
  
 reason: 

 >The 
   [[BR]]reason:[[BR]] 
   The status reason received. 

 *FileTransferStreamDidFinish* 
 >This 

  '''FileTransferStreamDidFinish''':: 
   This notification is sent when the incoming or outgoing file transfer is finished. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *FileTransferStreamGotChunk* 
 >This 

  '''FileTransferStreamGotChunk''':: 
   This notificaiton is sent for an incoming file transfer when a chunk of file data is received. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 content: 

 >The 
   [[BR]]content:[[BR]] 
   The file part which was received, as a @str@. 
  
 content_type: 

 >The {{{str}}}. 
   [[BR]]content_type:[[BR]] 
   The MIME type of the file which is being transferred. 
  
 transferred_bytes: 

 >The 
   [[BR]]transferred_bytes:[[BR]] 
   The number of bytes which have currently been successfully transferred. 
  
 file_size: 

 >The 
   [[BR]]file_size:[[BR]] 
   The size of the file being transferred. 



 h3. 


 === IDesktopSharingHandler 


 === 

 This interface is used to describe the interface between a @IDesktopSharingHandler@, {{{IDesktopSharingHandler}}}, which is responsible for consuming and producing RFB data, and the @DesktopSharingStream@ {{{DesktopSharingStream}}} which is responsible for transporting the RFB data over MSRP. The middleware provides four implementations of this interface: 
 
  * InternalVNCViewerHandler 
 
  * InternalVNCServerHandler 
 
  * ExternalVNCViewerHandler 
 
  * ExternalVNCServerHandler 


 h4. 

 ==== methods 

 

 *initialize*(_self_, *stream*) 
 >This ==== 
 

  '''initialize'''(''self'', '''stream'''):: 
   This method will be called by the @DesktopSharingStream@ {{{DesktopSharingStream}}} when the stream has been started and RFB data can be transported. The stream has two attributes which are relevant to the @IDesktopSharingHandler@: {{{IDesktopSharingHandler}}}: incoming_queue and outgoing_queue. These attributes are @eventlet.coros.queue@ {{{eventlet.coros.queue}}} instances which are used to transport RFB data between the stream and the handler. 


 h4. 

 ==== attributes 



 *type* ==== 


  '''type''':: 
   @"active"@ {{{"active"}}} or @"passive"@ {{{"passive"}}} depending on whether the handler represents a VNC viewer or server respectively. 


 h4. 

 ==== notifications 



 *DesktopSharingHandlerDidFail* 
 >This ==== 


  '''DesktopSharingHandlerDidFail''':: 
   This notification must be sent by the handler when an error occurs to notify the stream that it should fail. 
  
 context: 

 >A 
   [[BR]]context:[[BR]] 
   A string describing when the handler failed, such as @"reading"@, @"sending"@ {{{"reading"}}}, {{{"sending"}}} or @"connecting"@. 
  
 failure: 

 >A @twisted.python.failure.Failure@ {{{"connecting"}}}. 
   [[BR]]failure:[[BR]] 
   A {{{twisted.python.failure.Failure}}} instance describing the exception which led to the failure. 
  
 reason: 

 >A 
   [[BR]]reason:[[BR]] 
   A string describing the failure reason. 


 h3. 

 === InternalVNCViewerHandler 


 === 

 This is a concrete implementation of the @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} interface which can be used for a VNC viewer implemented within the application. 


 h4. 

 ==== methods 



 *send*(_self_, *data*) 
 >Sends ==== 


  '''send'''(''self'', '''data'''):: 
   Sends the specified data to the stream in order for it to be transported over MSRP to the remote endpoint. 
  
 data: 

 >The 
   [[BR]]data:[[BR]] 
   The RFB data to be transported over MSRP, in the form of a @str@. 


 h4. {{{str}}}. 

 ==== notifications 



 *DesktopSharingStreamGotData* 
 >This ==== 


  '''DesktopSharingStreamGotData''':: 
   This notification is sent when data is received over MSRP. 
  
 data: 

 >The 
   [[BR]]data:[[BR]] 
   The RFB data from the remote endpoint, in the form of a @str@. 


 h3. {{{str}}}. 

 === InternalVNCServerHandler 


 === 

 This is a concrete implementation of the @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} interface which can be used for a VNC server implemented within the application. 


 h4. 

 ==== methods 



 *send*(_self_, *data*) 
 >Sends ==== 


  '''send'''(''self'', '''data'''):: 
   Sends the specified data to the stream in order for it to be transported over MSRP to the remote endpoint. 
  
 data: 

 >The 
   [[BR]]data:[[BR]] 
   The RFB data to be transported over MSRP, in the form of a @str@. 


 h4. {{{str}}}. 

 ==== notifications 



 *DesktopSharingStreamGotData* 
 >This ==== 


  '''DesktopSharingStreamGotData''':: 
   This notification is sent when data is received over MSRP. 
  
 data: 

 >The 
   [[BR]]data:[[BR]] 
   The RFB data from the remote endpoint, in the form of a @str@. 


 h3. {{{str}}}. 

 === ExternalVNCViewerHandler 


 === 

 This implementation of @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} can be used for an external VNC viewer which connects to a VNC server using TCP. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *address*=@("localhost", 0)@, *connect_timeout*=@3@) 
 >This ==== 


  '''!__init!__'''(''self'', '''address'''={{{("localhost", 0)}}}, '''connect_timeout'''={{{3}}}):: 
   This instantiates a new @ExternalVNCViewerHandler@ {{{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@ {{{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. 
  
 address: 

 >A 
   [[BR]]address:[[BR]] 
   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. 


 h4. 

 ==== attributes 



 *address* 
 >A ==== 


  '''address''':: 
   A tuple containing an IP address and a port on which the handler is listening. 


 h3. 

 === ExternalVNCServerHandler 


 === 

 This implementation of @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} can be used for an external VNC server to which handler will connect using TCP. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *address*, *connect_timeout*=@3@) 
 >This ==== 


  '''!__init!__'''(''self'', '''address''', '''connect_timeout'''={{{3}}}):: 
   This instantiates a new @ExternalVNCServerHandler@ {{{ExternalVNCServerHandler}}} which will connect to the provided address on which a VNC server must be listening before the stream using this handler starts. 
  
 address: 

 >A 
   [[BR]]address:[[BR]] 
   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. 
  
 connect_timeout: 

 >How 
   [[BR]]connect_timeout:[[BR]] 
   How long to wait to connect to the VNC server before giving up. 



 h3. 


 === DesktopSharingStream 


 === 

 Implemented in [browser:sipsimple/streams/msrp.py] 

 This stream implements desktop sharing using MSRP as a transport protocol for RFB data. 

 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 "MSRP relay":http://msrprelay.org [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: 

 <pre> 
 {{{ 
 m=application 2855 TCP/TLS/MSRP * 
 a=path:msrps://10.0.1.19:2855/b599b22d1b1d6a3324c8;tcp 
 a=accept-types:application/x-rfb 
 a=rfbsetup:active 
 </pre> 



 h4. }}} 


 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *acount*, *handler*) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''acount''', '''handler'''):: 
   Instantiate a new @DesktopSharingStream@. 
  
 account: 

 >The @sipsimple.account.Account@ {{{DesktopSharingStream}}}. 
   [[BR]]account:[[BR]] 
   The {{{sipsimple.account.Account}}} or @sipsimple.account.BonjourAccount@ {{{sipsimple.account.BonjourAccount}}} instance this stream is associated with. 
  
 handler: 

 >An 
   [[BR]]handler:[[BR]] 
   An object implementing the @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} interface which will act as the handler for RFB data. 


 h4. 

 ==== attributes 



 *handler* 
 >This ==== 


  '''handler''':: 
   This is a writable property which can be used to get or set the object implementing @IDesktopSharingHandler@ {{{IDesktopSharingHandler}}} which acts as the handler for RFB data. For incoming @DesktopSharingStreams@, {{{DesktopSharingStreams}}}, this must be set by the application before the stream starts. 

 *incoming_queue* 
 >A @eventlet.coros.queue@ 

  '''incoming_queue''':: 
   A {{{eventlet.coros.queue}}} instance on which incoming RFB data is written. The handler should wait for data on this queue. 

 *outgoing_queue* 
 >A @eventlet.coros.queue@ 

  '''outgoing_queue''':: 
   A {{{eventlet.coros.queue}}} instance on which outgoing RFB data is written. The handler should write data on this queue. 


 h3. 

 === ConferenceHandler 


 === 

 This class is internal to the @Session@ {{{Session}}} and provied the user with the ability to invite participants to a conference hosted by the remote endpoint. 

 Adding and removing participants is performed using a @REFER@ {{{REFER}}} request as explained in RFC 4579, section 5.5. 

 In addition, the @ConferenceHandler@ {{{ConferenceHandler}}} will subscribe to the @conference@ {{{conference}}} event in order to get information about participants in the conference. 


 h4. 

 ==== methods 


 *add_participant*(_self_, *participant_uri*) 
 >Send ==== 

  '''add_participant'''(''self'', '''participant_uri'''):: 
   Send a @REFER@ {{{REFER}}} request telling the server to invite the participant specified in @participant_uri@ {{{participant_uri}}} to join the ongoing conference. 

 *remove_participant*(_self_, *participant_uri*) 
 >Send 

  '''remove_participant'''(''self'', '''participant_uri'''):: 
   Send a @REFER@ {{{REFER}}} request telling the server to remove the participant specified in @participant_uri@ {{{participant_uri}}} from the ongoing conference. 


 h4. 

 ==== notifications 


  ==== 

  All notifications are sent with the @Session@ {{{Session}}} object as the sender. 

 *SIPSessionGotConferenceInfo* 
 >This 

  '''SIPSessionGotConferenceInfo''':: 
   This notification is sent when a @NOTIFY@ {{{NOTIFY}}} is received with a valid conferene payload. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 conference_info: 

 >The @Conference@ 
   [[BR]]conference_info:[[BR]] 
   The {{{Conference}}} payload object. 

 *SIPConferenceDidAddParticipant* 
 >This 

  '''SIPConferenceDidAddParticipant''':: 
   This notification is sent when a participant was successfully added to the conference. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant added to the conference. 

 *SIPConferenceDidNotAddParticipant* 
 >This 

  '''SIPConferenceDidNotAddParticipant''':: 
   This notification is sent when a participant could not be added to the conference. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant added to the conference. 
  
 code: 

 >SIP 
   [[BR]]code:[[BR]] 
   SIP response code for the failure. 
  
 reason: 

 >Reason 
   [[BR]]reason:[[BR]] 
   Reason for the failure. 

 *SIPConferenceDidRemoveParticipant* 
 >This 

  '''SIPConferenceDidRemoveParticipant''':: 
   This notification is sent when a participant was successfully removed from the conference. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant removed from the conference. 

 *SIPConferenceDidNotRemoveParticipant* 
 >This 

  '''SIPConferenceDidNotRemoveParticipant''':: 
   This notification is sent when a participant could not be removed from the conference. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant removed from the conference. 
  
 code: 

 >SIP 
   [[BR]]code:[[BR]] 
   SIP response code for the failure. 
  
 reason: 

 >Reason 
   [[BR]]reason:[[BR]] 
   Reason for the failure. 

 *SIPConferenceGotAddParticipantProgress* 
 >This 

  '''SIPConferenceGotAddParticipantProgress''':: 
   This notification is sent when a @NOTIFY@ {{{NOTIFY}}} is received indicating the status of the add participant operation. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant whose operation is in progress. 
  
 code: 

 >SIP 
   [[BR]]code:[[BR]] 
   SIP response code for progress. 
  
 reason: 

 >Reason 
   [[BR]]reason:[[BR]] 
   Reason associated with the response code. 

 *SIPConferenceGotRemoveParticipantProgress* 
 >This 

  '''SIPConferenceGotRemoveParticipantProgress''':: 
   This notification is sent when a @NOTIFY@ {{{NOTIFY}}} is received indicating the status of the remove participant operation. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 participant: 

 >URI 
   [[BR]]participant:[[BR]] 
   URI of the participant whose operation is in progress. 
  
 code: 

 >SIP 
   [[BR]]code:[[BR]] 
   SIP response code for progress. 
  
 reason: 

 >Reason 
   [[BR]]reason:[[BR]] 
   Reason associated with the response code. 


 h2. 

 == Address Resolution 


 == 

 The SIP SIMPLE middleware offers the @sipsimple.lookup@ {{{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. 

 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.  


 h3.  

 === DNS Manager 


 === 

 This object provides @DNSLookup@ {{{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. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_) 
 >Instantiate ==== 

  '''!__init!__'''(''self''):: 
   Instantiate the DNSManager object (it's a Singleton). 

 *start*(_self_) 
 >Start 

  '''start'''(''self''):: 
   Start the DNSManager. It will start the probing process to determine the suitable nameservers to use. 

 *stop*(_self_) 
 >Stop 

  '''stop'''(''self''):: 
   Stop the DNS resolution probing. 



 h4. 


 ==== notifications 


 *DNSResolverDidInitialize* 
 >This ==== 

  '''DNSResolverDidInitialize''':: 
   This notification is sent when the nameservers to use for probing (and further DNS lookups) have been set for the first time. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 nameservers: 

 >The 
   [[BR]]nameservers:[[BR]] 
   The list of nameservers that was set on the DNS Manager. 

 *DNSNameserversDidChange* 
 >This 

  '''DNSNameserversDidChange''':: 
   This notification is sent when the nameservers to use for probing (and further DNS lookups) have changed as a result of the probing process. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 nameservers: 

 >The 
   [[BR]]nameservers:[[BR]] 
   The list of nameservers that was set on the DNS Manager. 



 h3. 


 === DNS Lookup 


 === 

 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. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_) 
 >Instantiate ==== 


  '''!__init!__'''(''self''):: 
   Instantiate a new DNSLookup object. 

 *lookup_service*(_self_, *uri*, *service*, *timeout*=@3.0@, *lifetime*=@15.0@) 
 >Perform 

  '''lookup_service'''(''self'', '''uri''', '''service''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: 
   Perform an SRV lookup followed by A lookups for MSRP relays or STUN servers depending on the @service@ {{{service}}} parameter. If SRV queries on the @uri.host@ {{{uri.host}}} domain fail, an A lookup is performed on it and the default port for the service is returned. Only the @uri.host@ {{{uri.host}}} attribute is used. The return value is a list of (host, port) tuples. 
  
 uri: 

 >A @(Frozen)SIPURI@ 
   [[BR]]uri:[[BR]] 
   A {{{(Frozen)SIPURI}}} from which the @host@ {{{host}}} attribute is used for the query domain. 
  
 service: 

 >The 
   [[BR]]service:[[BR]] 
   The service to lookup servers for, @"msrprelay"@ {{{"msrprelay"}}} or @"stun"@. 
  
 timeout: 

 >How {{{"stun"}}}. 
   [[BR]]timeout:[[BR]] 
   How many seconds to wait for a response from a nameserver. 
  
 lifetime: 

 >How 
   [[BR]]lifetime:[[BR]] 
   How many seconds to wait for a response from all nameservers in total. 

 *lookup_sip_proxy*(_self_, *uri*, *supported_transports*, *timeout*=@3.0@, *lifetime*=@15.0@) 
 >Perform 

  '''lookup_sip_proxy'''(''self'', '''uri''', '''supported_transports''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: 
   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@ {{{host}}} attribute is an IP address, or the @port@ {{{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@ {{{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@ {{{Route}}} objects containing the IP address, port and transport to use for routing in the order of preference given by the supported_transports argument. 
  
 uri: 

 >A @(Frozen)SIPURI@ 
   [[BR]]uri:[[BR]] 
   A {{{(Frozen)SIPURI}}} from which the @host@, @port@, @parameters@ {{{host}}}, {{{port}}}, {{{parameters}}} and @secure@ {{{secure}}} attributes are used. 
  
 supported_transports: 

 >A 
   [[BR]]supported_transports:[[BR]] 
   A sublist of @['udp', {{{['udp', 'tcp', 'tls']@ 'tls']}}} in the application's order of preference. 
  
 timeout: 

 >How 
   [[BR]]timeout:[[BR]] 
   How many seconds to wait for a response from a nameserver. 
  
 lifetime: 

 >How 
   [[BR]]lifetime:[[BR]] 
   How many seconds to wait for a response from all nameservers in total. 

 *lookup_xcap_server*(_self_, *uri*, *timeout*=@3.0@, *lifetime*=@15.0@) 
 >Perform 

  '''lookup_xcap_server'''(''self'', '''uri''', '''timeout'''={{{3.0}}}, '''lifetime'''={{{15.0}}}):: 
   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@ {{{uri.host}}} attribute is used. The return value is a list of strings representing HTTP URIs. 
  
 uri: 

 >A @(Frozen)SIPURI@ 
   [[BR]]uri:[[BR]] 
   A {{{(Frozen)SIPURI}}} from which the @host@ {{{host}}} attribute is used for the query domain. 
  
 timeout: 

 >How 
   [[BR]]timeout:[[BR]] 
   How many seconds to wait for a response from a nameserver. 
  
 lifetime: 

 >How 
   [[BR]]lifetime:[[BR]] 
   How many seconds to wait for a response from all nameservers in total. 



 h4. 


 ==== notifications 



 *DNSLookupDidSucceed* 
 >This ==== 


  '''DNSLookupDidSucceed''':: 
   This notification is sent when one of the lookup methods succeeds in finding a result. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 result: 

 >The 
   [[BR]]result:[[BR]] 
   The result of the DNS lookup in the format described in each method. 

 *DNSLookupDidFail* 
 >This 

  '''DNSLookupDidFail''':: 
   This notification is sent when one of the lookup methods fails in finding a result. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 error: 

 >A @str@ 
   [[BR]]error:[[BR]] 
   A {{{str}}} object describing the error which resulted in the DNS lookup failure. 

 *DNSLookupTrace* 
 >This 

  '''DNSLookupTrace''':: 
   This notification is sent several times during a lookup process for each individual DNS query. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 query_type: 

 >The 
   [[BR]]query_type:[[BR]] 
   The type of the query, @"NAPTR"@, @"SRV"@, @"A"@, @"NS"@ {{{"NAPTR"}}}, {{{"SRV"}}}, {{{"A"}}}, {{{"NS"}}} etc. 
  
 query_name: 

 >The 
   [[BR]]query_name:[[BR]] 
   The name which was queried. 
  
 answer: 

 >The 
   [[BR]]answer:[[BR]] 
   The answer returned by dnspython, or @None@ {{{None}}} if an error occurred. 
  
 error: 

 >The 
   [[BR]]error:[[BR]] 
   The exception which caused the query to fail, or @None@ {{{None}}} if no error occurred. 
  
 context: 

 >The 
   [[BR]]context:[[BR]] 
   The name of the method which was called on the @DNSLookup@ {{{DNSLookup}}} object. 
  
 service: 

 >The 
   [[BR]]service:[[BR]] 
   The service which was queried for, only available when context is @"lookup_service"@. 
  
 uri: 

 >The {{{"lookup_service"}}}. 
   [[BR]]uri:[[BR]] 
   The uri which was queried for. 
  
 nameservers: 

 >The 
   [[BR]]nameservers:[[BR]] 
   The list of nameservers that was used to perform the lookup. 



 h3. 


 === Route 


 === 

 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@ {{{DNSLookup.lookup_sip_proxy}}} and can be used with the @Session@ {{{Session}}} or a @(Frozen)RouteHeader@ {{{(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@). ({{{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. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *address*, *port*=None, *transport*=@'udp'@) 
 >Creates ==== 


  '''!__init!__'''(''self'', '''address''', '''port'''=None, '''transport'''={{{'udp'}}}):: 
   Creates the Route object with the specified parameters as attributes. 
 >Each 
   Each of these attributes can be accessed on the object once instanced. 
  
 >+_address_+: 

 >The 
   [[BR]]''address'':[[BR]] 
   The IPv4 address that the request in question should be sent to as a string. 
  
 >+_port_+: 

 >The 
   [[BR]]''port'':[[BR]] 
   The port to send the requests to, represented as an int, or None if the default port is to be used. 
  
 >+_transport_+: 

 >The 
   [[BR]]''transport'':[[BR]] 
   The transport to use, this can be a string of either "udp", "tcp" or "tls" (case insensitive). 

 *get_uri*(_self_) 
 >Returns 

  '''get_uri'''(''self''):: 
   Returns a @SIPURI@ {{{SIPURI}}} object which contains the adress, port and transport as parameter. This can be used to easily construct a @RouteHeader@: {{{RouteHeader}}}: 
   <pre> 
     {{{ 
     route = Route("1.2.3.4", port=1234, transport="tls") 
     route_header = RouteHeader(route.get_uri()) 
 </pre> 



 h2. 
   }}} 


 == SIP Accounts 


 == 

 Account Management is implemented in [browser:sipsimple/account.py] (@sipsimple.account@ ({{{sipsimple.account}}} module) and offers support for SIP accounts registered at SIP providers and SIP bonjour accounts which are discovered using mDNS. 


 h3. 

 === AccountManager 


 === 

 The @sipsimple.account.AccountManager@ {{{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@ {{{start}}} method has been called. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_) 
 >The @__init__@ ==== 


  '''!__init!__'''(''self''):: 
   The {{{__init__}}} method allows the @AccountManager@ {{{AccountManager}}} to be instantiated without passing any parameters. A reference to the @AccountManager@ {{{AccountManager}}} can be obtained anywhere before it is started. 

 *start*(_self_) 
 >This 

  '''start'''(''self''):: 
   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 [[SipConfigurationAPI#ConfigurationManager|ConfigurationManager]] [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] has been started. A *SIPAccountManagerDidAddAccount* '''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. 

 *stop*(_self_) 
 >Calling 

  '''stop'''(''self''):: 
   Calling this method will deactivate all accounts managed by the @AccountManager@. {{{AccountManager}}}. This method is called automatically by the SIPApplication when it stops. 

 *has_account*(_self_, *id*) 
 >This 

  '''has_account'''(''self'', '''id'''):: 
   This method returns @True@ {{{True}}} if an account which has the specifed SIP ID (must be a string) exists and @False@ {{{False}}} otherwise. 

 *get_account*(_self_, *id*) 
 >Returns 

  '''get_account'''(''self'', '''id'''):: 
   Returns the account (either an @Account@ {{{Account}}} instance or the @BonjourAccount@ {{{BonjourAccount}}} instance) with the specified SIP ID. Will raise a @KeyError@ {{{KeyError}}} if such an account does not exist. 

 *get_accounts*(_self_) 
 >Returns 

  '''get_accounts'''(''self''):: 
   Returns a list containing all the managed accounts. 

 *iter_accounts*(_self_) 
 >Returns 

  '''iter_accounts'''(''self''):: 
   Returns an iterator through all the managed accounts. 

 *find_account*(_self_, *contact_uri*) 
 >Returns 

  '''find_account'''(''self'', '''contact_uri'''):: 
   Returns an account with matches the specified @contact_uri@ {{{contact_uri}}} which must be a @sipsimple.core.SIPURI@ {{{sipsimple.core.SIPURI}}} instance. Only the accounts with the enabled flag set will be considered. Returns None if such an account does not exist. 


 h4. 

 ==== notifications 



 *SIPAccountManagerDidAddAccount* 
 >This ==== 


  '''SIPAccountManagerDidAddAccount''':: 
   This notification is sent when a new account becomes available to the @AccountManager@. {{{AccountManager}}}. The notification is also sent when the accounts are loaded from the configuration. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_account_+: 

 >The 
   [[BR]]''account'':[[BR]] 
   The account object which was added. 

 *SIPAccountManagerDidRemoveAccount* 
 >This 

  '''SIPAccountManagerDidRemoveAccount''':: 
   This notification is sent when an account is deleted using the @delete@ {{{delete}}} method. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_account_+: 

 >The 
   [[BR]]''account'':[[BR]] 
   The account object which was deleted. 

 *SIPAccountManagerDidChangeDefaultAccount* 
 >This 

  '''SIPAccountManagerDidChangeDefaultAccount''':: 
   This notification is sent when the default account changes. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_old_account_+: 

    
   [[BR]]''old_account'':[[BR]] 
    This is the account object which used to be the default account. 
  
 >+_account_+: 

    
   [[BR]]''account'':[[BR]] 
    This is the account object which is the new default account. 


 h3. 

 === Account 


 === 

 The @sipsimple.account.Account@ {{{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 [[SipConfigurationAPI#Account|Configuration API]]. [wiki:SipConfigurationAPI#Account Configuration API]. 

 There is exactly one instance of @Account@ {{{Account}}} per SIP account used and it is uniquely identifiable by its SIP ID, in the form _user@domain_. ''user@domain''. It is a singleton, in the sense that instantiating @Account@ {{{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 [[SipMiddlewareApi#AccountManager|AccountManager]]. [wiki:SipMiddlewareApi#AccountManager AccountManager]. The next sections will use a lowercase, monospaced @account@ {{{account}}} to represent an instance of @Account@. 


 h4. {{{Account}}}. 

 ==== states 


 ==== 

 The @Account@ {{{Account}}} objects have a setting flag called @enabled@ {{{enabled}}} which, if set to @False@ {{{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()@ {{{save()}}} method needs to be called, as the flag is a setting and will not be used until this method is called: 
 <pre> 
 {{{ 
 account.enabled = True 
 account.save() 
 </pre> }}} 

 The @Account@ {{{Account}}} objects will activate automatically when they are loaded/created if the @enabled@ {{{enabled}}} flag is set to @True@ {{{True}}} and the @sipsimple.engine.Engine@ {{{sipsimple.engine.Engine}}} is running; if it is not running, the accounts will activate after the engine starts. 

 In order to create a new account, just create a new instance of @Account@ {{{Account}}} with an id which doesn't belong to any other account. 

 The other functions of @Account@ {{{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: 


 *Account.registration.enabled* 
 >This 


  '''Account.registration.enabled''':: 
   This flag controls the automatic registration of the account. The notifications *SIPAccountRegistrationDidSucceed*, *SIPAccountRegistrationDidFail* '''SIPAccountRegistrationDidSucceed''', '''SIPAccountRegistrationDidFail''' and *SIPAccountRegistrationDidEnd* '''SIPAccountRegistrationDidEnd''' are used to inform the status of this registration. 

 *Account.presence.enabled* 
 >This 

  '''Account.presence.enabled''':: 
   This flag controls the automatic subscription to buddies for the _presence_ ''presence'' event and the publication of data in this event. (Not implemented yet) 

 *Account.dialog_event.enabled* 
 >This 

  '''Account.dialog_event.enabled''':: 
   This flag controls the automatic subscription to buddies for the _dialog-info_ ''dialog-info'' event and the publication of data in this event. (Not implemented yet) 

 *Account.message_summary.enabled* 
 >This 

  '''Account.message_summary.enabled''':: 
   This flag controls the automatic subscription to the _message-summary_ ''message-summary'' event in order to find out about voicemail messages. (Not implemented yet) 

 The @save()@ {{{save()}}} method needs to be called after changing these flags in order for them to take effect. The methods available on @Account@ {{{Account}}} objects are inherited from [[SipConfigurationAPI#SettingsObject|SettingsObject]]. 


 h4. [wiki:SipConfigurationAPI#SettingsObject SettingsObject]. 

 ==== attributes 


 ==== 

 The following attributes can be used on an Account object and need to be considered read-only. 


 *id* 
 >This 


  '''id''':: 
   This attribute is of type @sipsimple.configuration.datatypes.SIPAddress@ {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of @str@) {{{str}}}) and contains the SIP id of the account. It can be used as a normal string in the form _user@domain_, ''user@domain'', but it also allows access to the components via the attributes @username@ {{{username}}} and @domain@. {{{domain}}}. 
   <pre> 
   {{{ 
   account.id # 'alice@example.com' 
   account.id.username # 'alice' 
   account.id.domain # 'example.com' 
 </pre> 

 *contact* 
 >This 
   }}} 

  '''contact''':: 
   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@. {{{sipsimple.account.ContactURIFactory}}}. It can be indexed by a string representing a transport (@'udp'@, @'tcp'@, @'tls'@) ({{{'udp'}}}, {{{'tcp'}}}, {{{'tls'}}}) or a @sipsimple.util.Route@ {{{sipsimple.util.Route}}} object which will return a @sipsimple.core.SIPURI@ {{{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+ __init__ when building the @ContactURIFactory@ {{{ContactURIFactory}}} object. 
   <pre> 
   {{{ 
   account.contact # 'ContactURIFactory(username=hnfkybrt)' 
   account.contact.username # 'hnfkybrt' 
   account.contact['udp'] # <SIPURI "sip:hnfkybrt@10.0.0.1:53024"> 
   account.contact['tls'] # <SIPURI "sip:hnfkybrt@10.0.0.1:54478;transport=tls"> 
 </pre> 

 *credentials* 
 >This 
   }}} 

  '''credentials''':: 
   This attribute is of type @sipsimple.core.Credentials@ {{{sipsimple.core.Credentials}}} which is built from the @id.username@ {{{id.username}}} attribute and the @password@ {{{password}}} setting of the Account. Whenever this setting is changed, this attribute is updated. 
   <pre> 
   {{{ 
   account.credentials # <Credentials for 'alice'> 
 </pre> 

 *uri* 
 >This 
   }}} 

  '''uri''':: 
   This attribute is of type @sipsimple.core.SIPURI@ {{{sipsimple.core.SIPURI}}} which can be used to form a @FromHeader@ {{{FromHeader}}} associated with this account. It contains the SIP ID of the account. 
   <pre> 
   {{{ 
   account.uri # <SIPURI "sip:alice@example.com"> 
 </pre> 


 h4. 
   }}} 

 ==== notifications 



 *CFGSettingsObjectDidChange* 
 >This ==== 


  '''CFGSettingsObjectDidChange''':: 
   This notification is sent when the @save()@ {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the @SettingsObject@ {{{SettingsObject}}} class, it is exaplained in detail in [[SipConfigurationAPI#SettingsObjectNotifications|SettingsObject Notifications]]. 

 *SIPAccountWillActivate* 
 >This [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications]. 

  '''SIPAccountWillActivate''':: 
   This notification is sent when the @Account@ {{{Account}}} is about to be activated, but before actually performing any activation task. See @SIPAccountDidActivate@ {{{SIPAccountDidActivate}}} for more detail. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountDidActivate* 
 >This 

  '''SIPAccountDidActivate''':: 
   This notification is sent when the @Account@ {{{Account}}} activates. This can happen when the @Account@ {{{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. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountWillDeactivate* 
 >This 

  '''SIPAccountWillDeactivate''':: 
   This notification is sent when the @Account@ {{{Account}}} is about to be deactivated, but before performing any deactivation task. See @SIPAccountDidDeactivate@ {{{SIPAccountDidDeactivate}}} for more detail. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountDidDeactivate* 
 >This 

  '''SIPAccountDidDeactivate''':: 
   This notification is sent when the @Account@ {{{Account}}} deactivates. This can happend when the @Engine@ {{{Engine}}} is stopped or when the enabled flag of the account is set to @False@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{False}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountWillRegister* 
 >This 

  '''SIPAccountWillRegister''':: 
   This notification is sent when the account is about to register for the first time. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountRegistrationWillRefresh* 
 >This 

  '''SIPAccountRegistrationWillRefresh''':: 
   This notification is sent when a registration is about to be refreshed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountRegistrationDidSucceed* 
 >This 

  '''SIPAccountRegistrationDidSucceed''':: 
   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: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_contact_header_+: 

    
   [[BR]]''contact_header'':[[BR]] 
    The Contact header which was registered. 
  
 >+_contact_header_list_+: 

    
   [[BR]]''contact_header_list'':[[BR]] 
    A list containing all the contacts registered for this SIP account. 
  
 >+_expires_+: 

    
   [[BR]]''expires'':[[BR]] 
    The amount in seconds in which this registration will expire. 
  
 >+_registrar_+: 

 >The @sipsimple.util.Route@ 
   [[BR]]''registrar'':[[BR]] 
   The {{{sipsimple.util.Route}}} object which was used. 

 *SIPAccountRegistrationDidFail* 
 >This 

  '''SIPAccountRegistrationDidFail''':: 
   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: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_error_+: 

    
   [[BR]]''error'':[[BR]] 
    The reason for the failure of the REGISTER request. 
  
 >+_timeout_+: 

    
   [[BR]]''timeout'':[[BR]] 
    The amount in seconds as a @float@ {{{float}}} after which the registration will be tried again. 

 *SIPAccountRegistrationDidEnd* 
 >This 

  '''SIPAccountRegistrationDidEnd''':: 
   This notification is sent when a registration is ended (the account is unregistered). The data contained in this notification is: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_registration_+: 

    
   [[BR]]''registration'':[[BR]] 
    The @sipsimple.core.Registration@ {{{sipsimple.core.Registration}}} object which ended. 

 *SIPAccountRegistrationDidNotEnd* 
 >This 

  '''SIPAccountRegistrationDidNotEnd''':: 
   This notification is sent when a registration fails to end (the account is not unregistered). The data contained in this notification is: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP status code received. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The SIP status reason received. 
  
 >+_registration_+: 

 >The @sipsimple.core.Registration@ 
   [[BR]]''registration'':[[BR]] 
   The {{{sipsimple.core.Registration}}} object which ended. 

 *SIPAccountRegistrationGotAnswer* 
 >This 

  '''SIPAccountRegistrationGotAnswer''':: 
   This notification is sent whenever a response is received to a sent REGISTER request for this account. The data contained in this notification is: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_code_+: 

 >The 
   [[BR]]''code'':[[BR]] 
   The SIP status code received. 
  
 >+_reason_+: 

 >The 
   [[BR]]''reason'':[[BR]] 
   The SIP status reason received. 
  
 >+_registration_+: 

 >The @sipsimple.core.Registration@ 
   [[BR]]''registration'':[[BR]] 
   The {{{sipsimple.core.Registration}}} object which was used. 
  
 >+_registrar_+: 

 >The @sipsimple.util.Route@ 
   [[BR]]''registrar'':[[BR]] 
   The {{{sipsimple.util.Route}}} object which was used. 

 *SIPAccountMWIDidGetSummary* 
 >This 

  '''SIPAccountMWIDidGetSummary''':: 
   This notification is sent when a NOTIFY is received with a message-summary payload. The data contained in this notification is: 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 >+_message_summary_+: 

 >A @sipsimple.payloads.messagesummary.MessageSummary@ 
   [[BR]]''message_summary'':[[BR]] 
   A {{{sipsimple.payloads.messagesummary.MessageSummary}}} object with the parsed payload from the NOTIFY request. 


 h3. 

 === BonjourAccount 


 === 

 The @sipsimple.account.BonjourAccount@ {{{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@, {{{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. 


 h4. 

 ==== states 


 ==== 

 The @BonjourAccount@ {{{BonjourAccount}}} has an @enabled@ {{{enabled}}} flag which controls whether this account will be used or not. If it is set to @False@, {{{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@ {{{BonjourAccount}}} is activated, it will broadcast the contact address on the LAN and discover its neighbours sending notifications as this happens. 


 h4. 

 ==== attributes 


 ==== 

 The following attributes can be used on a BonjourAccount object and need to be considered read-only. 


 *id* 
 >This 


  '''id''':: 
   This attribute is of type @sipsimple.configuration.datatypes.SIPAddress@ {{{sipsimple.configuration.datatypes.SIPAddress}}} (a subclass of @str@) {{{str}}}) and contains the SIP id of the account, which is @'bonjour@local'@. {{{'bonjour@local'}}}. It can be used as a normal string, but it also allows access to the components via the attributes @username@ {{{username}}} and @domain@. {{{domain}}}. 
   <pre> 
   {{{ 
   bonjour_account.id # 'bonjour@local' 
   bonjour_account.id.username # 'bonjour' 
   bonjour_account.id.domain # 'local' 
 </pre> 

 *contact* 
 >This 
   }}} 

  '''contact''':: 
   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@. {{{sipsimple.account.ContactURIFactory}}}. It can be indexed by a string representing a transport (@'udp'@, @'tcp'@, @'tls'@) ({{{'udp'}}}, {{{'tcp'}}}, {{{'tls'}}}) or a @sipsimple.util.Route@ {{{sipsimple.util.Route}}} object which will return a @sipsimple.core.SIPURI@ {{{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+ __init__ when building the @ContactURIFactory@ {{{ContactURIFactory}}} object. 
   <pre> 
   {{{ 
   bonjour_account.contact # 'ContactURIFactory(username=lxzvgack)' 
   bonjour_account.contact.username # 'lxzvgack' 
   bonjour_account.contact['udp'] # <SIPURI "sip:lxzvgack@10.0.0.1:53024"> 
   bonjour_account.contact['tls'] # <SIPURI "sip:lxzvgack@10.0.0.1:54478;transport=tls"> 
 </pre> 

 *credentials* 
 >This 
   }}} 

  '''credentials''':: 
   This attribute is of type @sipsimple.core.Credentials@ {{{sipsimple.core.Credentials}}} object which is built from the @contact.username@ {{{contact.username}}} attribute; the password is set to the empty string. 
   <pre> 
   {{{ 
   bonjour_account.credentials # <Credentials for 'alice'> 
 </pre> 

 *uri* 
 >This 
   }}} 

  '''uri''':: 
   This attribute is of type @sipsimple.core.SIPURI@ {{{sipsimple.core.SIPURI}}} which can be used to form a @FromHeader@ {{{FromHeader}}} associated with this account. It contains the contact address of the bonjour account: 
   <pre> 
   {{{ 
   bonjour_account.uri # <SIPURI "sip:lxzvgack@10.0.0.1"> 
 </pre> 


 h4. 
   }}} 

 ==== notifications 


 *BonjourAccountDidAddNeighbour* 
 >This ==== 

  '''BonjourAccountDidAddNeighbour''':: 
   This notification is sent when a new Bonjour neighbour is discovered. 
  
 >+_service_description_+: 

 >BonjourServiceDescription 
   [[BR]]''service_description'':[[BR]] 
   BonjourServiceDescription object uniquely identifying this neighbour in the mDNS library. 
  
 >+_display_name_+: 

 >The 
   [[BR]]''display_name'':[[BR]] 
   The name of the neighbour as it is published. 
  
 >+_host_+: 

 >The 
   [[BR]]''host'':[[BR]] 
   The hostname of the machine from which the Bonjour neighbour registered its contact address. 
  
 >+_uri_+: 

 >The 
   [[BR]]''uri'':[[BR]] 
   The contact URI of the Bonjour neighbour, as a @FrozenSIPURI@ {{{FrozenSIPURI}}} object. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountDidUpdateNeighbour* 
 >This 

  '''BonjourAccountDidUpdateNeighbour''':: 
   This notification is sent when an existing Bonjour neighbour has updates its published data. 
  
 >+_service_description_+: 

 >BonjourServiceDescription 
   [[BR]]''service_description'':[[BR]] 
   BonjourServiceDescription object uniquely identifying this neighbour in the mDNS library. 
  
 >+_display_name_+: 

 >The 
   [[BR]]''display_name'':[[BR]] 
   The name of the neighbour as it is published. 
  
 >+_host_+: 

 >The 
   [[BR]]''host'':[[BR]] 
   The hostname of the machine from which the Bonjour neighbour registered its contact address. 
  
 >+_uri_+: 

 >The 
   [[BR]]''uri'':[[BR]] 
   The contact URI of the Bonjour neighbour, as a @FrozenSIPURI@ {{{FrozenSIPURI}}} object. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountDidRemoveNeighbour* 
 >This 

  '''BonjourAccountDidRemoveNeighbour''':: 
   This notification is sent when a Bonjour neighbour unregisters. 
  
 >+_service_description_+: 

 >The 
   [[BR]]''service_description'':[[BR]] 
   The BonjourServiceDescription object, which uniquely identifies a neighbour, that got unregistered. 

 *BonjourAccountDiscoveryDidFail* 
 >This 

  '''BonjourAccountDiscoveryDidFail''':: 
   This notification is sent once per transport when the Bonjour account has failed to perform the discovery process for the indicated transport. 
  
 >+_reason_+: 

 >String 
   [[BR]]''reason'':[[BR]] 
   String defining the reason of the failure. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the discovery failed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountDiscoveryFailure* 
 >This 

  '''BonjourAccountDiscoveryFailure''':: 
   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. 
  
 >+_error_+: 

 >String 
   [[BR]]''error'':[[BR]] 
   String defining the error of the failure. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the neighbour resoution failed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountRegistrationDidEnd* 
 >This 

  '''BonjourAccountRegistrationDidEnd''':: 
   This notification is sent once per transport when the Bonjour account unregisters its contact address for the indicated transport using mDNS. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the registration ended. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountRegistrationDidFail* 
 >This 

  '''BonjourAccountRegistrationDidFail''':: 
   This notification is sent once per transport when the Bonjour account fails to register its contact address for the indicated transport using mDNS. 
  
 >+_reason_+: 

 >A 
   [[BR]]''reason'':[[BR]] 
   A human readable error message. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the registration failed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountRegistrationUpdateDidFail* 
 >This 

  '''BonjourAccountRegistrationUpdateDidFail''':: 
   This notification is sent once per transport when the Bonjour account fails to update its data for the indicated transport using mDNS. 
  
 >+_reason_+: 

 >A 
   [[BR]]''reason'':[[BR]] 
   A human readable error message. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the registration update failed. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountRegistrationDidSucceed* 
 >This 

  '''BonjourAccountRegistrationDidSucceed''':: 
   This notification is sent once per transport when the Bonjour account successfully registers its contact address for the indicated transport using mDNS. 
  
 >+_name_+: 

 >The 
   [[BR]]''name'':[[BR]] 
   The contact address registered. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the registration succeeded. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *BonjourAccountWillInitateDiscovery* 
 >This 

  '''BonjourAccountWillInitateDiscovery''':: 
   This notification is sent when the Bonjour account is about to start the discovery process for the indicated transport. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the discovery will be started. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

   *BonjourAccountWillRegister* 
 >This '''BonjourAccountWillRegister''':: 
   This notification is sent just before the Bonjour account starts the registering process for the indicated transport. 
  
 >+_transport_+: 

 >String 
   [[BR]]''transport'':[[BR]] 
   String specifying the transport for which the registration will be started. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *CFGSettingsObjectDidChange* 
 >This 

  '''CFGSettingsObjectDidChange''':: 
   This notification is sent when the @save()@ {{{save()}}} method is called on the account after some of the settings were changed. As the notification belongs to the @SettingsObject@ {{{SettingsObject}}} class, it is exaplained in detail in [[SipConfigurationAPI#SettingsObjectNotifications|SettingsObject Notifications]]. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ [wiki:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications]. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountWillActivate* 
 >This 

  '''SIPAccountWillActivate''':: 
   This notification is sent when the @BonjourAccount@ {{{BonjourAccount}}} is about to be activated, but before actually performing any activation task. See @SIPAccountDidActivate@ {{{SIPAccountDidActivate}}} for more detail. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountDidActivate* 
 >This 

  '''SIPAccountDidActivate''':: 
   This notification is sent when the @BonjourAccount@ {{{BonjourAccount}}} activates. This can happen when the @BonjourAccount@ {{{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. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountWillDeactivate* 
 >This 

  '''SIPAccountWillDeactivate''':: 
   This notification is sent when the @BonjourAccount@ {{{BonjourAccount}}} is about to be deactivated, but before performing any deactivation task. See @SIPAccountDidDeactivate@ {{{SIPAccountDidDeactivate}}} for more detail. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *SIPAccountDidDeactivate* 
 >This 

  '''SIPAccountDidDeactivate''':: 
   This notification is sent when the @BonjourAccount@ {{{BonjourAccount}}} deactivates. This can happend when the @Engine@ {{{Engine}}} is stopped or when the enabled flag of the account is set to @False@. 
  
 >+_timestamp_+: 

 >A @datetime.datetime@ {{{False}}}. 
   [[BR]]''timestamp'':[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 



 h2. 


 == Audio 


 == 

 The high-level audio API hides the complexity of using the low-level PJMEDIA interface. This is implemented in the @sipsimple.audio@ {{{sipsimple.audio}}} module and contains the following components: 
 
  * IAudioPort: an interface describing an object capable of producing and/or consuming audio data. 
 
  * AudioDevice: an object conforming to the IAudioPort interface which describes a physical audio device. 
 
  * AudioBridge: a collection of objects conforming to IAudioPort which connects all of them in a full mesh. 
 
  * WavePlayer: an object conforming to the IAudioPort interface which can playback the audio data from a @.wav@ {{{.wav}}} file. 
 
  * WaveRecorder: an object conforming to the IAudioPort interface which can record audio data to a @.wav@ {{{.wav}}} file. 


 h3. 

 === IAudioPort 


 === 

 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. 


 h4. 

 ==== attributes 



 *mixer* 
 >The @AudioMixer@ ==== 


  '''mixer''':: 
   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. 

 *consumer_slot* 
 >An 

  '''consumer_slot''':: 
   An integer representing the slot (see [[SipCoreApiDocumentation#AudioMixer|AudioMixer]]) [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to consume audio data, or @None@ {{{None}}} if this object is not a consumer. 

 *producer_slot* 
 >An 

  '''producer_slot''':: 
   An integer representing the slot (see [[SipCoreApiDocumentation#AudioMixer|AudioMixer]]) [wiki:SipCoreApiDocumentation#AudioMixer AudioMixer]) which this object uses to produce audio data, or @None@ {{{None}}} if this object is not a producer. 


 h4. 

 ==== notifications 

 

 *AudioPortDidChangeSlots* 
 >This ==== 
 

  '''AudioPortDidChangeSlots''':: 
   This notification needs to be sent by implementations of this interface when the slots it has change, so as to let the @AudioBridges@ {{{AudioBridges}}} it is part of know that reconnections need to be made. 
  
 consumer_slot_changed: 

 >A 
   [[BR]]consumer_slot_changed:[[BR]] 
   A bool indicating whether the consumer slot was changed. 
  
 producer_slot_changed: 

 >A 
   [[BR]]producer_slot_changed:[[BR]] 
   A bool indicating whether the producer slot was changed. 
  
 old_consumer_slot: 

 >The 
   [[BR]]old_consumer_slot:[[BR]] 
   The old slot for consuming audio data. Only required if consumer_slot_changed is @True@. 
  
 new_consumer_slot: 

 >The {{{True}}}. 
   [[BR]]new_consumer_slot:[[BR]] 
   The new slot for consuming audio data. Only required if consumer_slot_changed is @True@. 
  
 old_producer_slot: 

 >The {{{True}}}. 
   [[BR]]old_producer_slot:[[BR]] 
   The old slot for producing audio data. Only required if producer_slot_changed is @True@. 
  
 new_producer_slot: 

 >The {{{True}}}. 
   [[BR]]new_producer_slot:[[BR]] 
   The new slot for producing audio data. Only required if producer_slot_changed is @True@. 


 h3. {{{True}}}. 

 === AudioDevice 


 === 

 The AudioDevice represents the physical audio device which is part of a @AudioMixer@, {{{AudioMixer}}}, implementing the @IAudioPort@ {{{IAudioPort}}} interface. As such, it can be uniquely identified by the mixer it represents. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *mixer*, *input_muted*=@False@, *output_muted*=@False@): 
 >Instantiates ==== 


  '''!__init!__'''(''self'', '''mixer''', '''input_muted'''={{{False}}}, '''output_muted'''={{{False}}}): 
   Instantiates a new AudioDevice which represents the physical device associated with the specified @AudioMixer@. 
  
 mixer: 

 >The @AudioMixer@ {{{AudioMixer}}}. 
   [[BR]]mixer:[[BR]] 
   The {{{AudioMixer}}} whose physical device this object represents. 
  
 input_muted: 

 >A 
   [[BR]]input_muted:[[BR]] 
   A boolean which indicates whether this object should act as a producer of audio data. 
  
 output_muted: 

 >A 
   [[BR]]output_muted:[[BR]] 
   A boolean which indicates whether this object should act as a consumer of audio data. 


 h4. 

 ==== attributes 



 *input_muted* 
 >A ==== 


  '''input_muted''':: 
   A writable property which controls whether this object should act as a producer of audio data. An @AudioPortDidChange@ {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within the @AudioBridges@ {{{AudioBridges}}} this object is part of. 

 *output_muted* 
 >A 

  '''output_muted''':: 
   A writable property which controls whether this object should act as a consumer of audio data. An @AudioPortDidChange@ {{{AudioPortDidChange}}} slots notification is sent when this attribute is changed to force connections to be reconsidered within    the @AudioBridges@ {{{AudioBridges}}} this object is part of. 


 h3. 

 === AudioBridge 


 === 

 The @AudioBridge@ {{{AudioBridge}}} is the basic component which is able to connect @IAudioPort@ {{{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@ {{{IAudioPort}}} itself, an @AudioBridge@ {{{AudioBridge}}} can be part of another @AudioBridge@. {{{AudioBridge}}}. The @AudioBridge@ {{{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@. {{{AudioBridge}}}. 
 > Note: although this is not enforced, there should never be any cycles when connecting @AudioBridges@. 


 h4. {{{AudioBridges}}}. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *mixer*) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''mixer'''):: 
   Instantiate a new @AudioBridge@ {{{AudioBridge}}} which uses the specified @AudioMixer@ {{{AudioMixer}}} for mixing. 

 *add*(_self_, *port*) 
 >Add 

  '''add'''(''self'', '''port'''):: 
   Add an implementation of @IAudioPort@ {{{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@; {{{AudioBridge}}}; thus, this object acts like a set. 

 *remove*(_self_, *port*) 
 >Remove 

  '''remove'''(''self'', '''port'''):: 
   Remove a port from this @AudioBridge@. {{{AudioBridge}}}. The port must have previously been added to the @AudioBridge@, {{{AudioBridge}}}, otherwise a @ValueError@ {{{ValueError}}} is raised. 


 h3. 

 === WavePlayer 


 === 

 A @WavePlayer@ {{{WavePlayer}}} is an implementation of @IAudioPort@ {{{IAudioPort}}} which is capable of producing audio data read from a @.wav@ {{{.wav}}} file. This object is completely reusable, as it can be started and stopped any number of times. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *mixer*, *filename*, *volume*=@100@, *loop_count*=@1@, *pause_time*=@0@, *initial_play*=@True@) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''mixer''', '''filename''', '''volume'''={{{100}}}, '''loop_count'''={{{1}}}, '''pause_time'''={{{0}}}, '''initial_play'''={{{True}}}):: 
   Instantiate a new @WavePlayer@ {{{WavePlayer}}} which is capable of playing a @.wav@ {{{.wav}}} file repeatedly. All the parameters are available as attributes of the object, but should not be changed once the object has been started. 
  
 mixer: 

 >The @AudioMixer@ 
   [[BR]]mixer:[[BR]] 
   The {{{AudioMixer}}} this object is connected to. 
  
 filename: 

 >The 
   [[BR]]filename:[[BR]] 
   The full path to the @.wav@ {{{.wav}}} file from which audio data is to be read. 
  
 volume: 

 >The 
   [[BR]]volume:[[BR]] 
   The volume at which the file should be played. 
  
 loop_count: 

 >The 
   [[BR]]loop_count:[[BR]] 
   The number of times the file should be played, or @0@ {{{0}}} for infinity. 
  
 pause_time: 

 >How 
   [[BR]]pause_time:[[BR]] 
   How many seconds to wait between successive plays of the file.  
  
 initial_play: 

 >Whether  
   [[BR]]initial_play:[[BR]] 
   Whether or not the file to play once the @WavePlayer@ {{{WavePlayer}}} is started, or to wait @pause_time@ {{{pause_time}}} seconds before the first play. 

 *start*(_self_) 
 >Start 

  '''start'''(''self''):: 
   Start playing the @.wav@ {{{.wav}}} file. 

 *stop*(_self_) 
 >Stop 

  '''stop'''(''self''):: 
   Stop playing the @.wav@ {{{.wav}}} file immediately. 

 *play*(_self_) 
 >Play 

  '''play'''(''self''):: 
   Play the @.wav@ {{{.wav}}} file. This method is an alternative to the start/stop methods, it runs on a waitable green thread. One may call @play().wait()@ {{{play().wait()}}} in order to green-block waiting for the file playback to end. 


 h4. 

 ==== attributes 



 *is_active* 
 >A ==== 


  '''is_active''':: 
   A boolean indicating whether or not this @WavePlayer@ {{{WavePlayer}}} is currently playing. 


 h4. 

 ==== notifications 



 *WavePlayerDidStart* 
 >This ==== 


  '''WavePlayerDidStart''':: 
   This notification is sent when the @WavePlayer@ {{{WavePlayer}}} starts playing the file the first time after the @start()@ {{{start()}}} method has been called. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *WavePlayerDidEnd* 
 >This 

  '''WavePlayerDidEnd''':: 
   This notification is sent when the @WavePlayer@ {{{WavePlayer}}} is done playing either as a result of playing the number of times it was told to, or because the @stop()@ {{{stop()}}} method has been called. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *WavePlayerDidFail* 
 >This 

  '''WavePlayerDidFail''':: 
   This notification is sent when the @WavePlayer@ {{{WavePlayer}}} is not capable of playing the @.wav@ {{{.wav}}} file. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 
  
 error: 

 >The 
   [[BR]]error:[[BR]] 
   The exception raised by the @WaveFile@ {{{WaveFile}}} which identifies the cause for not being able to play the @.wav@ {{{.wav}}} file. 


 h3. 

 === WaveRecorder 


 === 

 A @WaveRecorder@ {{{WaveRecorder}}} is an implementation of @IAudioPort@ {{{IAudioPort}}} is is capable of consuming audio data and writing it to a @.wav@ {{{.wav}}} file. Just like @WavePlayer@, {{{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. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_, *mixer*, *filename*) 
 >Instantiate ==== 


  '''!__init!__'''(''self'', '''mixer''', '''filename'''):: 
   Instantiate a new @WaveRecorder@. 
  
 mixer: 

 >The @AudioMixer@ {{{WaveRecorder}}}. 
   [[BR]]mixer:[[BR]] 
   The {{{AudioMixer}}} this @WaveRecorder@ {{{WaveRecorder}}} is connected to. 
  
 filename: 

 >The 
   [[BR]]filename:[[BR]] 
   The full path to the @.wav@ {{{.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()@ {{{start()}}} method is called. 

 *start*(_self_) 
 >Start 

  '''start'''(''self''):: 
   Start consuming audio data and writing it to the @.wav@ {{{.wav}}} file. If this object is not part of an @AudioBridge@, {{{AudioBridge}}}, not audio data will be written. 

 *stop*(_self_) 
 >Stop 

  '''stop'''(''self''):: 
   Stop consuming audio data and close the @.wav@ {{{.wav}}} file. 


 h4. 

 ==== attributes 



 *is_active* 
 >A ==== 


  '''is_active''':: 
   A boolean indicating whether or not this @WaveRecorder@ {{{WaveRecorder}}} is currently recording audio data. 



 h2. 


 == Conference 


 == 

 Conference support is implemented in the @sipsimple.conference@ {{{sipsimple.conference}}} module. Currently, only audio conferencing is supported. 


 h3. 

 === AudioConference 


 === 

 This class contains the basic implementation for audio conferencing. It acts as a container for @AudioStream@ {{{AudioStream}}} objects which it will connect in a full mesh, such that all participants can hear all other participants. 


 h4. 

 ==== methods 



 *<notextile>__init__</notextile>*(_self_) 
 >Instantiates ==== 


  '''!__init!__'''(''self''):: 
   Instantiates a new @AudioConference@ {{{AudioConference}}} which is ready to contain @AudioStream@ {{{AudioStream}}} objects. 

 *add*(_self_, *stream*) 
 >Add 

  '''add'''(''self'', '''stream'''):: 
   Add the specified @AudioStream@ {{{AudioStream}}} object to the conference. 

 *remove*(_self_, *stream*) 
 >Removes 

  '''remove'''(''self'', '''stream'''):: 
   Removes the specified @AudioStream@ {{{AudioStream}}} object from the conference. Raises a @ValueError@ {{{ValueError}}} if the stream is not part of the conference. 

 *hold*(_self_) 
 >Puts 

  '''hold'''(''self''):: 
   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. 

 *unhold*(_self_) 
 >Removes 

  '''unhold'''(''self''):: 
   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. 


 h4. 

 ==== attributes 



 *bridge* 
 >An @AudioBridge@ ==== 


  '''bridge''':: 
   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@ {{{WavePlayer}}} to all the participants or record the whole conference using a @WaveRecorder@. 

 *on_hold* 
 >A {{{WaveRecorder}}}. 

  '''on_hold''':: 
   A boolean indicating whether or not the conference is "on hold". 

 *streams* 
 >The 

  '''streams''':: 
   The list of streams which are part of this conference. The application must not manipulate this list in any way. 



 h2. 


 == XCAP support 


 == 

 The @sipsimple.xcap@ {{{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 
 which can be managed by means of this module are: 
 
  * *contact list*, '''contact list''', by means of the @resource-lists@ {{{resource-lists}}} and @rls-services@ {{{rls-services}}} XCAP applications 
 
  * *presence policies*, '''presence policies''', by means of the @org.openmobilealliance.pres-rules@ {{{org.openmobilealliance.pres-rules}}} or @pres-rules@ {{{pres-rules}}} XCAP applications 
 
  * *dialoginfo policies*, '''dialoginfo policies''', by means of the @org.openxcap.dialog-rules@ {{{org.openxcap.dialog-rules}}} XCAP application 
 
  * *status icon*, '''status icon''', by means of the @org.openmobilealliance.pres-content@ {{{org.openmobilealliance.pres-content}}} XCAP application 
 
  * *offline status*, '''offline status''', by means of the @pidf-manipulation@ {{{pidf-manipulation}}} XCAP application 

 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 
 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 
 the resources stored on the XCAP server. 


 h3. 

 === Contact 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 A @Contact@ {{{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@, {{{resource-lists}}}, {{{rls-services}}}, 
 @org.openmobilealliance.pres-rules@ {{{org.openmobilealliance.pres-rules}}} or @pres-rules@, {{{pres-rules}}}, and @org.openxcap.dialog-rules@ {{{org.openxcap.dialog-rules}}} applications. The URI associated with the contact is considered a unique identifier. Information 
 found in various places about the same URI is aggregated into a single @Contact@ {{{Contact}}} instance. More information about the contact is described within the attributes section. 


 h4. 

 ==== attributes 


 *name* 
 >A ==== 

  '''name''':: 
   A human-readable name which can be associated with the contact. This is stored using the @display-name@ {{{display-name}}} standard @resource-lists@ {{{resource-lists}}} element. 

 *uri* 
 >The 

  '''uri''':: 
   The uniquely identifying URI. 

 *group* 
 >A 

  '''group''':: 
   A human-readable group name which can be used to group contacts together. If this is not @None@, {{{None}}}, the contact will be reachable from the @oma_buddylist@ {{{oma_buddylist}}} list within the @resource-lists@ 
 >document, {{{resource-lists}}} 
   document, as defined by OMA. The group of a contact is the first @display-name@ {{{display-name}}} of an ancestor list which contains the contact information. 

 *subscribe_to_presence* 
 >A 

  '''subscribe_to_presence''':: 
   A boolean flag which indicates whether a subscription to the @presence@ {{{presence}}} event is desired. If this is @True@, {{{True}}}, the contact's URI is referenced from a @rls-services@ {{{rls-services}}} service which defines 
   @presence@ {{{presence}}} as one of the packages. Thus, a contact with this flag set is guaranteed to be referenced by an RLS service. 

 *subscribe_to_dialoginfo* 
 >A 

  '''subscribe_to_dialoginfo''':: 
   A boolean flag which indicates whether a subscription to the @dialog@ {{{dialog}}} event is desired. If this is @True@, {{{True}}}, the contact's URI is referenced from a @rls-services@ {{{rls-services}}} service which defines 
   @dialog@ {{{dialog}}} as one of the packages. Thus, a contact with this flag set is guaranteed to be refereneced by an RLS service. 

 *presence_policies* 
 >Either @None@ 

  '''presence_policies''':: 
   Either {{{None}}} or a list of @PresencePolicy@ {{{PresencePolicy}}} objects which represent @org.openmobilealliance.pres-rules@ {{{org.openmobilealliance.pres-rules}}} or @pres-rules@ {{{pres-rules}}} rules which reference this contact's URI either directly 
   (through an identity condition) or indirectly through resource lists (using the OMA external-list common policy extension). 

 *dialoginfo_policies* 
 >Either @None@ 

  '''dialoginfo_policies''':: 
   Either {{{None}}} or a list of @DialoginfoPolicy@ {{{DialoginfoPolicy}}} objects which represent @org.openxcap.dialog-rules@ {{{org.openxcap.dialog-rules}}} rules which reference this contact's URI through an identity condition. 

 *attributes* 
 >A 

  '''attributes''':: 
   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 
 >extension 
   extension to resource-lists. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *name*, *uri*, *group*, ***attributes*) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''name''', '''uri''', '''group''', '''**attributes'''):: 
   Initializes a new @Contact@ {{{Contact}}} instance. The policies are by default set to @None@ {{{None}}} and the @subscribe_to_presence@ {{{subscribe_to_presence}}} and @subscribe_to_dialoginfo@ {{{subscribe_to_dialoginfo}}} flags to @True@. 



 h3. {{{True}}}. 


 === Service 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 A @Service@ {{{Service}}} represents a URI managed by a Resource List Server (RLS). Subscriptions to this URI will be handled by the RLS. 


 h4. 

 ==== attributes 


 *uri* 
 >The ==== 

  '''uri''':: 
   The URI which can be used to access a service provided by the RLS. 

 *packages* 
 >A 

  '''packages''':: 
   A list of strings containing the SIP events which can be subscribed for to the URI. 

 *entries* 
 >A 

  '''entries''':: 
   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. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *uri*, *packages*, *entries*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''uri''', '''packages''', '''entries'''={{{None}}}):: 
   Initializes a new @Service@ {{{Service}}} instance. 



 h3. 


 === Policy 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 @Policy@ {{{Policy}}} is the base class for @PresencePolicy@ {{{PresencePolicy}}} and @DialoginfoPolicy@. {{{DialoginfoPolicy}}}. It describes the attributes common to both. 


 h4. 

 ==== attributes 


 *id* 
 >A ==== 

  '''id''':: 
   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. 

 *action* 
 >A 

  '''action''':: 
   A string having one of the values @"allow"@, @"confirm"@, @"polite-block"@ {{{"allow"}}}, {{{"confirm"}}}, {{{"polite-block"}}} or @"block"@. 

 *validity* 
 >Either @None@, {{{"block"}}}. 

  '''validity''':: 
   Either {{{None}}}, or a list of @datetime@ {{{datetime}}} instance 2-tuples representing the intervals when this policy applies. Example valid validity list which represents two intervals, each of two hours: 
   <pre> 
   {{{ 
   from datetime import datetime, timedelta 
   now = datetime.now() 
   one_hour = timedelta(seconds=3600) 
   one_day = timedelta(days=1) 
   validity = [(now-one_hour, now+one_hour), (now+one_day-one_hour, now+one_day+one_hour)] 
 </pre> 

 *sphere* 
 >Either @None@ 
   }}} 

  '''sphere''':: 
   Either {{{None}}} or a string representing the sphere of presentity when this policy applies. 

 *multi_identity_conditions* 
 >Either @None@ 

  '''multi_identity_conditions''':: 
   Either {{{None}}} or a list of @CatchAllCondition@ {{{CatchAllCondition}}} or @DomainCondition@ {{{DomainCondition}}} objects as defined below. This is used to apply this policy to multiple users. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *id*, *action*, *name*=@None@, *validity*=@None@, *sphere*=@None@, *multi_identity_conditions*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''id''', '''action''', '''name'''={{{None}}}, '''validity'''={{{None}}}, '''sphere'''={{{None}}}, '''multi_identity_conditions'''={{{None}}}):: 
   Initializes a new @Policy@ {{{Policy}}} instance. 

 *check_validity*(_self_, *timestamp*, *sphere*=@Any@) 
 >Returns 

  '''check_validity'''(''self'', '''timestamp''', '''sphere'''={{{Any}}}):: 
   Returns a boolean indicating whether this policy applies at the specific moment given by timestamp (which must be a @datetime@ {{{datetime}}} instance) in the context of the specific sphere. 



 h3. 


 === CatchAllCondition 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 @CatchAllCondition@ {{{CatchAllCondition}}} represents a condition which matches any user, but which can have some exceptions. 


 h4. 

 ==== attributes 


 *exceptions* 
 >A ==== 

  '''exceptions''':: 
   A list containing @DomainException@ {{{DomainException}}} or @UserException@ {{{UserException}}} objects to define when this condition does not apply. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *exceptions*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''exceptions'''={{{None}}}):: 
   Initializes a new @CatchAllCondition@ {{{CatchAllCondition}}} instance. 



 h3. 


 === DomainCondition 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 @DomainCondition@ {{{DomainCondition}}} represents a condition which matches any user within a specified domain, but which can have some exceptions. 


 h4. 

 ==== attributes 


 *domain* 
 >A ==== 

  '''domain''':: 
   A string containing the domain for which this condition applies. 

 *exceptions* 
 >A 

  '''exceptions''':: 
   A list containing @UserEception@ {{{UserEception}}} objects to define when this condition does not apply. 



 h4. 


 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *domain*, *exceptions*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''domain''', '''exceptions'''={{{None}}}):: 
   Initializes a new @DomainCondition@ {{{DomainCondition}}} instance. 



 h3. 


 === DomainException 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 @DomainException@ {{{DomainException}}} is used as an exception for a @CatchAllCondition@ {{{CatchAllCondition}}} which excludes all users within a specified domain. 


 h4. 

 ==== attributes 


 *domain* 
 >A ==== 

  '''domain''':: 
   A string containing the domain which is to be excluded from the @CatchAllCondition@ {{{CatchAllCondition}}} containing this object as an exception. 



 h4. 


 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *domain*) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''domain'''):: 
   Initializes a new @DomainException@ {{{DomainException}}} instance. 



 h3. 


 === UserException 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 @UserException@ {{{UserException}}} is used as an exception for either a @CatchAllCondition@ {{{CatchAllCondition}}} or a @DomainCondition@ {{{DomainCondition}}} and excludes a user identified by an URI. 


 h4. 

 ==== attributes 


 *uri* 
 >A ==== 

  '''uri''':: 
   A string containing the URI which is to be excluded from the @CatchAllCondition@ {{{CatchAllCondition}}} or @DomainCondition@ {{{DomainCondition}}} containing this object as an exception. 



 h4. 


 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *uri*) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''uri'''):: 
   Initializes a new @UserException@ {{{UserException}}} instance. 



 h3. 


 === PresencePolicy 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 A @PresencePolicy@ {{{PresencePolicy}}} represents either a @org.openmobilealliance.pres-rules@ {{{org.openmobilealliance.pres-rules}}} or @pres-rules@ {{{pres-rules}}} rule. It subclasses @Policy@ {{{Policy}}} and inherits its attributes, but defines additional 
 attributes corresponding to the transformations which can be specified in a rule. 


 h4. 

 ==== attributes 


  ==== 

  All of the following attributes only make sense for a policy having a @"allow"@ {{{"allow"}}} action. 

 *provide_devices* 
 >Either @sipsimple.util.All@, 

  '''provide_devices''':: 
   Either {{{sipsimple.util.All}}}, or a list of @Class@, @OccurenceID@ {{{Class}}}, {{{OccurenceID}}} or @DeviceID@ {{{DeviceID}}} objects as defined below. 

 *provide_persons* 
 >Either @sipsimple.util.All@, 

  '''provide_persons''':: 
   Either {{{sipsimple.util.All}}}, or a list of @Class@ {{{Class}}} or @OccurenceID@ {{{OccurenceID}}} objects as defined below. 

 *provide_services* 
 >Either @sipsimple.util.All@, 

  '''provide_services''':: 
   Either {{{sipsimple.util.All}}}, or a list of @Class@, @OccurenceID@, @ServiceURI@ {{{Class}}}, {{{OccurenceID}}}, {{{ServiceURI}}} or @ServiceURIScheme@ {{{ServiceURIScheme}}} objects as defined below. 

 *provide_activities* 
 >Either @None@ 

  '''provide_activities''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_class* 
 >Either @None@ 

  '''provide_class''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_device_id* 
 >Either @None@ 

  '''provide_device_id''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_mood* 
 >Either @None@ 

  '''provide_mood''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_place_is* 
 >Either @None@ 

  '''provide_place_is''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_place_type* 
 >Either @None@ 

  '''provide_place_type''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_privacy* 
 >Either @None@ 

  '''provide_privacy''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_relationship* 
 >Either @None@ 

  '''provide_relationship''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_status_icon* 
 >Either @None@ 

  '''provide_status_icon''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_sphere* 
 >Either @None@ 

  '''provide_sphere''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_time_offset* 
 >Either @None@ 

  '''provide_time_offset''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 

 *provide_user_input* 
 >Either @None@ 

  '''provide_user_input''':: 
   Either {{{None}}} (if the transformation is not be specified) or one of the strings @"false"@, @"bare"@, @"thresholds"@, @"full"@. 

 *provide_unknown_attributes* 
 >Either @None@ {{{"false"}}}, {{{"bare"}}}, {{{"thresholds"}}}, {{{"full"}}}. 

  '''provide_unknown_attributes''':: 
   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@ {{{provide-unknown-attribute}}} (singular form). 

 *provide_all_attributes* 
 >Either @None@ 

  '''provide_all_attributes''':: 
   Either {{{None}}} (if the transformation is not be specified) or a boolean. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *id*, *action*, *name*=@None@, *validity*=@None@, *sphere*=@None@, *multi_identity_conditions*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''id''', '''action''', '''name'''={{{None}}}, '''validity'''={{{None}}}, '''sphere'''={{{None}}}, '''multi_identity_conditions'''={{{None}}}):: 
   Initializes a new @PresencePolicy@ {{{PresencePolicy}}} instance. The @provide_devices@, @provide_persons@ {{{provide_devices}}}, {{{provide_persons}}} and @provide_services@ {{{provide_services}}} are initialized to @sipsimple.util.All@, @provide_all_attributes@ {{{sipsimple.util.All}}}, {{{provide_all_attributes}}} to @True@ {{{True}}} and the rest to @None@. 



 h3. {{{None}}}. 


 === DialoginfoPolicy 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 A @DialoginfoPolicy@ {{{DialoginfoPolicy}}} represents a @org.openxcap.dialog-rules@ {{{org.openxcap.dialog-rules}}} rule. It subclasses @Policy@ {{{Policy}}} and inherits all of its attributes. It does not add any other attributes or methods and thus 
 has an identical API. 



 h3. 


 === Icon 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 An @Icon@ {{{Icon}}} instance represents a status icon stored using the @org.openmobilealliance.pres-content@ {{{org.openmobilealliance.pres-content}}} application. 


 h4. 

 ==== attributes 


 *data* 
 >The ==== 

  '''data''':: 
   The binary data of the image, as    a string. 

 *mime_type* 
 >The 

  '''mime_type''':: 
   The MIME type of the image, one of @image/jpeg@, @image/gif@ {{{image/jpeg}}}, {{{image/gif}}} or @image/png@. 

 *description* 
 >An {{{image/png}}}. 

  '''description''':: 
   An optional description of the icon. 

 *location* 
 >An 

  '''location''':: 
   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 
 >responses, 
   responses, that is used otherwise the XCAP URI of the icon is used. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *data*, *mime_type*, *description*=@None@, *location*=@None@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''data''', '''mime_type''', '''description'''={{{None}}}, '''location'''={{{None}}}):: 
   Initializes a new @Icon@ {{{Icon}}} instance. 



 h3. 


 === OfflineStatus 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 An @OfflineStatus@ {{{OfflineStatus}}} instance represents data stored using the @pidf-manipulation@ {{{pidf-manipulation}}} application. 


 h4. 

 ==== attributes 


 *activity* 
 >A ==== 

  '''activity''':: 
   A string representing an activity within a @person@ {{{person}}} element. 

 *note* 
 >A 

  '''note''':: 
   A string stored as a note within a @person@ {{{person}}} element. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *activity*=@None@, *note*=@Note@) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''activity'''={{{None}}}, '''note'''={{{Note}}}):: 
   Initializes a new @OfflineStatus@ {{{OfflineStatus}}} instance. 



 h3. 


 === XCAPManager 


 === 

 Implemented in [browser:sipsimple/xcap/+init+.py] [browser:sipsimple/xcap/__init__.py] 

 The XCAPManager is the central entity used to manage resource via the XCAP protocol. It uses a storage factory provided by @SIPApplication@ {{{SIPApplication}}} through the @Storage API@. {{{Storage API}}}. It has state machine as described in the following diagram: 

 !{ align=center}xcap-manager-state.png! [[Image(xcap-manager-state.png, align=center)]] 

 The @load@ {{{load}}} method needs to be called just once in order to load the data from the cache. Once this is done, the @start@ {{{start}}} and @stop@ {{{stop}}} methods can be called as needed. Initially in the @stopped@ {{{stopped}}} state, 
 the start method will result in a transition to the @initializing@ {{{initializing}}} state. While in the @initializing@ {{{initializing}}} state, the XCAP manager will try to connect to the XCAP server and retrieve the 
 capabilities (@xcap-caps@ ({{{xcap-caps}}} application). It will then initiate a SUBSCRIBE for the @xcap-diff@ {{{xcap-diff}}} event (if configured) and transition to the @fetching@ {{{fetching}}} state. In the @fetching@ {{{fetching}}} state, it 
 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 
 @insync@ {{{insync}}} state. Otherwise, it inserts a @normalize@ {{{normalize}}} operation at the beginning of the journal (described below) and transitions to the @updating@ {{{updating}}} state. In the @updating@ {{{updating}}} state, it 
 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 
 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@ {{{fetching}}} state; if any other error occurs, the update is 
 retried periodically. If the update succeeds, data is extracted from the documents and the @XCAPManagerDidReloadData@ {{{XCAPManagerDidReloadData}}} notification is sent. The XCAPManager then transitions to the @insync@ {{{insync}}} 
 state. A call to the @stop@ {{{stop}}} method will result in a transition to the @stopping@ {{{stopping}}} state, termination of any existing SUBSCRIBE dialog and a transition to the @stopped@ {{{stopped}}} state. 

 Modifications to the settings which control the XCAPManager can result in either a transition to the @initializing@ {{{initializing}}} state or the termination of any previous SUBSCRIBE dialog and creation of a new 
 one. 

 The subscription to the @xcap-diff@ {{{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 
 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@ {{{xcap-diff}}} event is not supported by the provider. If subscription for @xcap-diff@ {{{xcap-diff}}} event fails, a fetch of all the documents will be tried every 2 minutes. 

 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@ {{{If-Match}}} and 
 @If-None-Match@ {{{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 
 is not modified. 

 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 
 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 
 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 
 of the document. 


 h4. 

 ==== configuration 


 *Account.id*, *Account.auth.username*, *Account.auth.password* 
 >These ==== 

  '''Account.id''', '''Account.auth.username''', '''Account.auth.password''':: 
   These are used both for the @xcap-diff@ {{{xcap-diff}}} subscription and the XCAP server connection.  

 *Account.sip.subscribe_interval* 
 >This  

  '''Account.sip.subscribe_interval''':: 
   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. 

 *Account.xcap.xcap_root* 
 >This 

  '''Account.xcap.xcap_root''':: 
   This specifies the XCAP root used for contacting the XCAP server and managing the resources. If this setting is @None@, {{{None}}}, a TXT DNS query is made for the @xcap@ {{{xcap}}} subdomain of the SIP account's 
 >domain. 
   domain. The result is interpreted as being an XCAP root. Example record for account alice@example.org: 
   <pre> 
   {{{ 
   xcap.example.org.      IN    TXT       "https://xcap.example.org/xcap-root" 
 </pre> 

 *SIPSimpleSettings.sip.transport_list* 
 >This 
   }}} 

  '''SIPSimpleSettings.sip.transport_list''':: 
   This controls the transports which can be used for the subscription. 


 h4. 

 ==== methods 


 *<notextile>__init__</notextile>*(_self_, *account*) 
 >Initializes ==== 

  '''!__init!__'''(''self'', '''account'''):: 
   Initializes an XCAPManager for the specified account. 

 *load*(_self_) 
 >Allows 

  '''load'''(''self''):: 
   Allows the XCAPManager to the load its internal data from cache. 

 *start*(_self_) 
 >Starts 

  '''start'''(''self''):: 
   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 
 >thread. 

 *stop*(_self_) 
 >Stops 
   thread. 

  '''stop'''(''self''):: 
   Stops the XCAPManager from performing any tasks. Waits until the @xcap-diff@ {{{xcap-diff}}} subscription, if any, is terminated. This method must be called in a green thread. 

 *start_transaction*(_self_) 
 >This 

  '''start_transaction'''(''self''):: 
   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@ {{{commit_transaction}}} method is called. 
 >This 
   This does not have the same meaning as a relational database transaction, since there is no @rollback@ {{{rollback}}} operation. 

 *commit_transaction*(_self_) 
 >Applies 

  '''commit_transaction'''(''self''):: 
   Applies the modifications queued after a call to @start_transaction@. {{{start_transaction}}}. This method needs to be called the exact same number of times the @start_transaction@ {{{start_transaction}}} method was called. Does not have 
 >any 
   any effect if @start_transaction@ {{{start_transaction}}} was not previously called. 

  The following methods results in XCAP operations being queued on the journal: 

 *add_group*(_self_, *group*) 
 >Add 

  '''add_group'''(''self'', '''group'''):: 
   Add a contact group with the specified name. 

 *rename_group*(_self_, *old_name*, *new_name*) 
 >Change 

  '''rename_group'''(''self'', '''old_name''', '''new_name'''):: 
   Change the name of the contact group @old_name@ {{{old_name}}} to @new_name@. {{{new_name}}}. If such a contact group does not exist, the operation does not do anything. 

 *remove_group*(_self_, *group*) 
 >Remove 

  '''remove_group'''(''self'', '''group'''):: 
   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. 

 *add_contact*(_self_, *contact*) 
 >Adds 

  '''add_contact'''(''self'', '''contact'''):: 
   Adds a new contact, described by a @Contact@ {{{Contact}}} object. If the contact with the same URI and a not-@None@ not-{{{None}}} group already exists, the operation does not do anything. Otherwise, the contact 
 >is 
   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@, ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, 
   @wp_prs_block_anonymous@, @wp_prs_allow_own@) {{{wp_prs_block_anonymous}}}, {{{wp_prs_allow_own}}}) is ignored. 

 *update_contact*(_self_, *contact*, ***attributes*) 
 >Modifies 

  '''update_contact'''(''self'', '''contact''', '''**attributes'''):: 
   Modifies a contact's properties. The keywords can be any of the @Contact@ {{{Contact}}} attributes, with the same meaning. The URI of the contact to be modified is taken from the first argument. If such 
 >a 
   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@, ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, {{{wp_prs_block_anonymous}}}, 
   @wp_prs_allow_own@) {{{wp_prs_allow_own}}}) is ignored. The URI of a contact can be changed by specified the keyword argument @uri@ {{{uri}}} with the new value. 

 *remove_contact*(_self_, *contact*) 
 >Removes 

  '''remove_contact'''(''self'', '''contact'''):: 
   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. 

 *add_presence_policy*(_self_, *policy*) 
 >Adds 

  '''add_presence_policy'''(''self'', '''policy'''):: 
   Adds a new presence policy, described by a @PresencePolicy@ {{{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 
 >specified, 
   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 
 >are 
   are some multi_identity_conditions), a new one will be automatically generated. 

 *update_presence_policy*(_self_, *policy*, ***attributes*) 
 >Modifies 

  '''update_presence_policy'''(''self'', '''policy''', '''**attributes'''):: 
   Modifies a presence policy's properties. The keywords can be any of the @PresencePolicy@ {{{PresencePolicy}}} attributes, with the same meaning. The id of the policy to be modified is taken from the first argument. 
 >If 
   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 
 >multi_identity_conditions 
   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. 

 *remove_presence_policy*(_self_, *policy*) 
 >Removes 

  '''remove_presence_policy'''(''self'', '''policy'''):: 
   Removes the presence policy identified by the id attribute of the @PresencePolicy@ {{{PresencePolicy}}} object specified. If the id is @None@ {{{None}}} or does not exist in the document, the operation does not do 
 >anything. 
   anything. Some standard OMA policies (@wp_prs_unlisted@, @wp_prs_allow_unlisted@, @wp_prs_block_anonymous@, @wp_prs_allow_own@, @wp_prs_grantedcontacts@, ({{{wp_prs_unlisted}}}, {{{wp_prs_allow_unlisted}}}, {{{wp_prs_block_anonymous}}}, {{{wp_prs_allow_own}}}, {{{wp_prs_grantedcontacts}}}, 
   @wp_prs_blockedcontacts@) {{{wp_prs_blockedcontacts}}}) cannot be removed. 

 *add_dialoginfo_policy*(_self_, *policy*) 
 >Adds 

  '''add_dialoginfo_policy'''(''self'', '''policy'''):: 
   Adds a new dialoginfo policy, described by a @DialoginfoPolicy@ {{{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 
 >not 
   not specified, one will be automatically generated (recommended). 

 *update_dialoginfo_policy*(_self_, *policy*, ***attributes*) 
 >Modifies 

  '''update_dialoginfo_policy'''(''self'', '''policy''', '''**attributes'''):: 
   Modifies a dialoginfo policy's properties. The keywords can be any of the @DialoginfoPolicy@ {{{DialoginfoPolicy}}} attributes, with the same meanining. The id of the policy to be modified is taken from the first 
 >argument. 
   argument. If such a policy does not exist and there is sufficient information about the policy, it is added. 

 *remove_dialoginfo_policy*(_self_, *policy*) 
 >Removes 

  '''remove_dialoginfo_policy'''(''self'', '''policy'''):: 
   Removes the dialoginfo policy identified by the id attribute of the @DialoginfoPolicy@ {{{DialoginfoPolicy}}} object specified. If the id is @None@ {{{None}}} or does not exist in the document, the operation does not do 
 >anything. 

 *set_status_icon*(_self_, *icon*) 
 >Sets 
   anything. 

  '''set_status_icon'''(''self'', '''icon'''):: 
   Sets the status icon using the information from the @Icon@ {{{Icon}}} object specified. The @location@ {{{location}}} attribute is ignored. The MIME type must be one of @image/gif@, @image/png@ {{{image/gif}}}, {{{image/png}}} or 
   @image/jpeg@. {{{image/jpeg}}}. If the argument is @None@, {{{None}}}, the status icon is deleted. 

 *set_offline_status*(_self_, *status*) 
 >Sets 

  '''set_offline_status'''(''self'', '''status'''):: 
   Sets the offline status using the information from the @OfflineStatus@ {{{OfflineStatus}}} object specified. If the argument is @None@, {{{None}}}, the offline status document is deleted. 


 h4. 

 ==== notifications 


 *XCAPManagerWillStart* 
 >This ==== 

  '''XCAPManagerWillStart''':: 
   This notification is sent just after calling the @start@ {{{start}}} method. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerDidStart* 
 >This 

  '''XCAPManagerDidStart''':: 
   This notification is sent after the XCAPManager has started doing its tasks (contacting the XCAP server, subscribing to @xcap-diff@ {{{xcap-diff}}} event). This notification does not mean that 
 >any 
   any of these operations were successful, as the XCAPManager will retry them continuously should they fail. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerWillEnd* 
 >This 

  '''XCAPManagerWillEnd''':: 
   This notification is sent just after calling the @stop@ {{{stop}}} method. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerDidEnd* 
 >This 

  '''XCAPManagerDidEnd''':: 
   This notification is sent when the XCAPManager has stopped performing any tasks. This also means that any active @xcap-diff@ {{{xcap-diff}}} subscription has been terminated. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerDidDiscoverServerCapabilities* 
 >This 

  '''XCAPManagerDidDiscoverServerCapabilities''':: 
   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 
 >information 
   information about the server's capabilities (obtained using the @xcap-caps@ {{{xcap-caps}}} application). 
  
 contactlist_supported: 

 >A 
   [[BR]]contactlist_supported:[[BR]] 
   A boolean indicating the support of documents needed for contact management (@resource-lists@ ({{{resource-lists}}} and @rls-services@). 
  
 presence_policies_supported: 

 >A {{{rls-services}}}). 
   [[BR]]presence_policies_supported:[[BR]] 
   A boolean indicating the support of documents needed for presence policy management (@org.openmobilealliance.pres-rules@ ({{{org.openmobilealliance.pres-rules}}} or @pres-rules@). 
  
 dialoginfo_policies_supported: 

 >A {{{pres-rules}}}). 
   [[BR]]dialoginfo_policies_supported:[[BR]] 
   A boolean indicating the support of documents needed for dialoginfo policy management (@org.openxcap.dialog-rules@). 
  
 status_icon_supported: 

 >A ({{{org.openxcap.dialog-rules}}}). 
   [[BR]]status_icon_supported:[[BR]] 
   A boolean indicating the support of documents needed for status icon management (@org.openmobilealliance.pres-content@). 
  
 offline_status_supported: 

 >A ({{{org.openmobilealliance.pres-content}}}). 
   [[BR]]offline_status_supported:[[BR]] 
   A boolean indicating the support of documents needed for offline status management (@pidf-manipulation@). 
  
 timestamp: 

 >A @datetime.datetime@ ({{{pidf-manipulation}}}). 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerDidReloadData* 
 >This 

  '''XCAPManagerDidReloadData''':: 
   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. 
  
 contacts: 

 >A 
   [[BR]]contacts:[[BR]] 
   A list of @Contact@ {{{Contact}}} objects. 
  
 groups: 

 >A 
   [[BR]]groups:[[BR]] 
   A list of strings. 
  
 services: 

 >A 
   [[BR]]services:[[BR]] 
   A list of @Service@ {{{Service}}} objects. 
  
 presence_policies: 

 >A 
   [[BR]]presence_policies:[[BR]] 
   A list of @PresencePolicy@ {{{PresencePolicy}}} objects. 
  
 dialoginfo_policies: 

 >A 
   [[BR]]dialoginfo_policies:[[BR]] 
   A list of @DialoginfoPolicy@ {{{DialoginfoPolicy}}} objects. 
  
 status_icon: 

 >A @StatusIcon@ 
   [[BR]]status_icon:[[BR]] 
   A {{{StatusIcon}}} object if one is stored, @None@ {{{None}}} otherwise. 
  
 offline_status: 

 >A @OfflineStatus@ 
   [[BR]]offline_status:[[BR]] 
   A {{{OfflineStatus}}} object if offline status information is stored, @None@ {{{None}}} otherwise. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent. 

 *XCAPManagerDidChangeState* 
 >This 

  '''XCAPManagerDidChangeState''':: 
   This notification is sent when the XCAPManager transitions from one state to another. 
  
 prev_state: 

 >The 
   [[BR]]prev_state:[[BR]] 
   The old state of the XCAPManager, a string. 
  
 state: 

 >The 
   [[BR]]state:[[BR]] 
   The new state of the XCAPManager, a string. 
  
 timestamp: 

 >A @datetime.datetime@ 
   [[BR]]timestamp:[[BR]] 
   A {{{datetime.datetime}}} object indicating when the notification was sent.