SipMSRPApi

Version 5 (Oliver Bril, 03/31/2009 12:46 pm)

1 1 Adrian Georgescu
= MSRP API =
2 1 Adrian Georgescu
3 1 Adrian Georgescu
[[TOC(WikiStart, Sip*, depth=3)]]
4 1 Adrian Georgescu
5 1 Adrian Georgescu
Message Session Relay Protocol (MSRP) is a protocol for transmitting a series of related instant messages in the context of a session. Message sessions are treated like any other media stream when set up via a rendezvous or session creation protocol such as the Session Initiation Protocol (SIP). 
6 1 Adrian Georgescu
7 1 Adrian Georgescu
 * MSRP sessions are defined in [http://tools.ietf.org/html/rfc4975 RFC 4975].
8 1 Adrian Georgescu
 * MSRP relay extension used for NAT traversal of instant messaging and file transfer sessions is defined in [http://tools.ietf.org/html/rfc4976 RFC 4976].
9 1 Adrian Georgescu
10 5 Oliver Bril
The MSRP protocol is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-msrplib;a=summary msrplib] Python package. On top of it, {{{sipsimple}}} provides higher level classes integrated into middleware notification and configuration systems:
11 1 Adrian Georgescu
12 4 Oliver Bril
 * {{{sipsimple.msrp.MSRPChat}}}
13 4 Oliver Bril
 * {{{sipsimple.msrp.MSRPFileTransfer}}}
14 1 Adrian Georgescu
 * {{{sipsimple.msrp.MSRPDesktopSharing}}}
15 1 Adrian Georgescu
16 5 Oliver Bril
Those classes are used internally by [wiki:SipMiddlewareApi#Session Session], which provides the necessary methods to access their features. The notifications posted by these classes are also handled internally by [wiki:SipMiddlewareApi#Session Session]. The notifications that are relevant to the user are then reposted by the Session instance.
17 5 Oliver Bril
Refer to [wiki:SipMiddlewareApi#Session Session documentation] for details on Session API.
18 5 Oliver Bril
19 4 Oliver Bril
== MSRPChat ==
20 1 Adrian Georgescu
21 5 Oliver Bril
{{{sipsimple.msrp.MSRPChat}}} implements Instance Messaging over MSRP in the context of SIPSIMPLE middleware. This class
22 1 Adrian Georgescu
23 5 Oliver Bril
 * automatically wraps outgoing messages with Message/CPIM if that's necessary according to accept-types
24 5 Oliver Bril
 * unwraps incoming Message/CPIM messages
25 5 Oliver Bril
 * plays notification sounds on received/sent message
26 5 Oliver Bril
27 5 Oliver Bril
=== methods ===
28 5 Oliver Bril
29 5 Oliver Bril
 '''!__init!__'''(''self'', ''account'', ''remote_uri'', ''outgoing'')::
30 5 Oliver Bril
 Initialize MSRPChat instance.
31 5 Oliver Bril
32 5 Oliver Bril
 '''initialize'''(''self'')::
33 5 Oliver Bril
 Initialize the MSRP connection; connect to the relay if necessary. When done, fire MSRPChatDidInitialize (with 'sdpmedia' attribute, containing the appropriate 'SDPMedia' instance)
34 5 Oliver Bril
35 5 Oliver Bril
 '''start'''(''self'', ''remote_media'')::
36 5 Oliver Bril
 Complete the MSRP connection establishment; this includes binding the MSRP session. [[BR]]
37 5 Oliver Bril
 When done, fire MSRPChatDidStart. At this point each incoming message is posted as a {{{MSRPChatGotMessage}}} notification
38 5 Oliver Bril
39 5 Oliver Bril
 '''end'''(''self'')::
40 5 Oliver Bril
 Close the MSRP connection or cleanup after initialize(), whatever is necessary. [[BR]]
41 5 Oliver Bril
 Before doing anything post {{{MSRPChatWillEnd}}}.
42 5 Oliver Bril
 When done, post {{{MSRPChatDidEnd}}}. If there was an error, post {{{MSRPChatDidFail}}}.
43 5 Oliver Bril
 {{{MSRPChatDidEnd}}} will be posted anyway.
44 5 Oliver Bril
45 5 Oliver Bril
46 5 Oliver Bril
=== notifications ===
47 5 Oliver Bril
48 5 Oliver Bril
 '''MSRPChatGotMessage''':
49 5 Oliver Bril
 Posted for each incoming message with the following attributes:
50 5 Oliver Bril
 - cpim_headers (dict); if cpim wrapper was not used, empty dict
51 5 Oliver Bril
 - message (MSRPData)
52 5 Oliver Bril
 - content (str) - the actual string that the remote user has typed
53 5 Oliver Bril
54 4 Oliver Bril
== MSRPFileTransfer ==
55 4 Oliver Bril
56 4 Oliver Bril
== MSRPDesktopSharing ==
57 4 Oliver Bril
58 4 Oliver Bril
== msrplib ==
59 4 Oliver Bril
60 1 Adrian Georgescu
{{{msrplib}}} is based upon [http://twistedmatrix.com twisted] and [http://devel.ag-projects.com/~denis/eventlet/ eventlet] and provides a set of
61 1 Adrian Georgescu
classes for establishing and managing MSRP connection.
62 1 Adrian Georgescu
63 1 Adrian Georgescu
The library consist of the following modules:
64 1 Adrian Georgescu
65 1 Adrian Georgescu
 '''msrplib.transport'''::
66 1 Adrian Georgescu
 Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connection.
67 2 Redmine Admin
68 1 Adrian Georgescu
 '''msrplib.connect'''::
69 1 Adrian Georgescu
 Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance.
70 1 Adrian Georgescu
71 1 Adrian Georgescu
 '''msrplib.session'''::
72 1 Adrian Georgescu
 Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection.
73 1 Adrian Georgescu
74 1 Adrian Georgescu
 '''msrplib.protocol'''::
75 1 Adrian Georgescu
 Provides representation and parsing of MSRP entities - chunks and URIs.
76 1 Adrian Georgescu
77 1 Adrian Georgescu
 '''msrplib.trafficlog'''::
78 1 Adrian Georgescu
 Defines {{{Logger}}} class that is used through out the library to log the connection state.
79 1 Adrian Georgescu
  
80 4 Oliver Bril
=== Usage ===
81 1 Adrian Georgescu
82 4 Oliver Bril
==== Establish a connection ====
83 3 Oliver Bril
84 1 Adrian Georgescu
{{{msrplib.connect}}} provides a number of classes to establish a connection, so the first
85 1 Adrian Georgescu
thing to do is to select which one applies to your situation:
86 1 Adrian Georgescu
87 1 Adrian Georgescu
    1. Calling endpoint, not using a relay ({{{ConnectorDirect}}})
88 1 Adrian Georgescu
    2. Answering endpoint, not using a relay ({{{AcceptorDirect}}})
89 1 Adrian Georgescu
    3. Calling endpoint, using a relay ({{{ConnectorRelay}}})
90 1 Adrian Georgescu
    4. Answering endpoint, using a relay ({{{AcceptorRelay}}})
91 1 Adrian Georgescu
92 1 Adrian Georgescu
The answering endpoint may skip using the relay if sure that it's accessible
93 1 Adrian Georgescu
directly. The calling endpoint is unlikely to need the relay.
94 1 Adrian Georgescu
95 1 Adrian Georgescu
Once you have an instance of the right class (use the convenience functions
96 1 Adrian Georgescu
{{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the
97 1 Adrian Georgescu
connection is the same:
98 1 Adrian Georgescu
99 1 Adrian Georgescu
{{{
100 1 Adrian Georgescu
full_local_path = connector.prepare()
101 1 Adrian Georgescu
try:
102 1 Adrian Georgescu
    ... put full_local_path in SDP 'a:path' attribute
103 1 Adrian Georgescu
    ... get full_remote_path from remote's 'a:path: attribute
104 1 Adrian Georgescu
    ... (the order of the above steps is reversed if you're the
105 1 Adrian Georgescu
    ... answering party, but that does not affect connector's usage)
106 1 Adrian Georgescu
    msrptransport = connector.complete(full_remote_path)
107 1 Adrian Georgescu
finally:
108 1 Adrian Georgescu
    connector.cleanup()
109 1 Adrian Georgescu
}}}
110 1 Adrian Georgescu
111 1 Adrian Georgescu
To customize connection's parameters, create a new {{{protocol.URI}}} object and pass
112 1 Adrian Georgescu
it to prepare() function, e.g.
113 1 Adrian Georgescu
{{{
114 1 Adrian Georgescu
local_uri = protocol.URI(use_tls=False, port=5000)
115 1 Adrian Georgescu
connector.prepare(local_uri)
116 1 Adrian Georgescu
}}}
117 1 Adrian Georgescu
118 1 Adrian Georgescu
{{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters
119 1 Adrian Georgescu
used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently
120 1 Adrian Georgescu
only respected by {{{AcceptorDirect}}}.
121 1 Adrian Georgescu
122 1 Adrian Georgescu
Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}}
123 1 Adrian Georgescu
will open a port just to handle one incoming connection and close it right after.
124 1 Adrian Georgescu
If your application behaves more like a server, i.e. opens a port and listens on it
125 1 Adrian Georgescu
constantly, use {{{MSRPServer}}} class.
126 3 Oliver Bril
127 4 Oliver Bril
=== Components ===
128 1 Adrian Georgescu
129 4 Oliver Bril
==== a connector or acceptor ====
130 3 Oliver Bril
131 4 Oliver Bril
===== attributes =====
132 4 Oliver Bril
===== methods =====
133 1 Adrian Georgescu
134 4 Oliver Bril
==== transport.MSRPTransport ====
135 1 Adrian Georgescu
136 1 Adrian Georgescu
Low level access to MSRP connection.
137 1 Adrian Georgescu
138 4 Oliver Bril
===== attributes =====
139 3 Oliver Bril
140 4 Oliver Bril
===== methods =====
141 3 Oliver Bril
142 3 Oliver Bril
 '''make_chunk'''(''self'', ''transaction_id''={{{None}}}, ''method''={{{'SEND'}}}, ''code''={{{None}}}, ''comment''={{{None}}}, ''data''={{{''}}}, ''contflag''={{{None}}}, ''start''={{{1}}}, ''end''={{{None}}}, ''length''={{{None}}}, ''message_id''={{{None}}})::
143 1 Adrian Georgescu
 Make a new chunk ({{{protocol.MSRPData}}} instance) with proper {{{From-Path}}}, {{{To-Path}}}, {{{Byte-Range}}} and {{{Message-ID}}} headers set up based on MSRPTransport's state and the parameters provided. Use ''data'' for payload, and ''start''/''end''/''length'' to generate {{{Byte-Range}}} header. Generate new random strings for default values of ''transaction_id'' and ''message_id''. 
144 1 Adrian Georgescu
 [[BR]]''contflag'':[[BR]]
145 1 Adrian Georgescu
 MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}}, unless you have a partial {{{SEND}}} chunk, in which case it is {{{'+'}}}
146 1 Adrian Georgescu
147 4 Oliver Bril
==== session.MSRPSession ====
148 4 Oliver Bril
===== attributes =====
149 4 Oliver Bril
===== methods =====
150 1 Adrian Georgescu
151 4 Oliver Bril
==== connect.MSRPServer ====
152 4 Oliver Bril
===== attributes =====
153 4 Oliver Bril
===== methods =====