SipMSRPApi » History » Version 8
Oliver Bril, 03/31/2009 01:53 PM
1 | 1 | Adrian Georgescu | = MSRP API = |
---|---|---|---|
2 | |||
3 | [[TOC(WikiStart, Sip*, depth=3)]] |
||
4 | |||
5 | 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 | |||
7 | * MSRP sessions are defined in [http://tools.ietf.org/html/rfc4975 RFC 4975]. |
||
8 | * 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 | |||
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 | * {{{sipsimple.msrp.MSRPFileTransfer}}} |
||
14 | 1 | Adrian Georgescu | * {{{sipsimple.msrp.MSRPDesktopSharing}}} |
15 | |||
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 | Refer to [wiki:SipMiddlewareApi#Session Session documentation] for details on Session API. |
||
18 | |||
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 | 7 | Oliver Bril | * unwraps incoming Message/CPIM messages; for each incoming message, {{{MSRPChatGotMessage}}} is posted. |
25 | 5 | Oliver Bril | * plays notification sounds on received/sent message |
26 | |||
27 | === methods === |
||
28 | |||
29 | '''!__init!__'''(''self'', ''account'', ''remote_uri'', ''outgoing''):: |
||
30 | Initialize MSRPChat instance. |
||
31 | |||
32 | '''initialize'''(''self''):: |
||
33 | Initialize the MSRP connection; connect to the relay if necessary. When done, fire MSRPChatDidInitialize (with 'sdpmedia' attribute, containing the appropriate 'SDPMedia' instance) |
||
34 | |||
35 | '''start'''(''self'', ''remote_media''):: |
||
36 | Complete the MSRP connection establishment; this includes binding the MSRP session. [[BR]] |
||
37 | When done, fire MSRPChatDidStart. At this point each incoming message is posted as a {{{MSRPChatGotMessage}}} notification |
||
38 | |||
39 | '''end'''(''self''):: |
||
40 | Close the MSRP connection or cleanup after initialize(), whatever is necessary. [[BR]] |
||
41 | Before doing anything post {{{MSRPChatWillEnd}}}. |
||
42 | 7 | Oliver Bril | When done, post {{{MSRPChatDidEnd}}}. If there was an error, post {{{MSRPChatDidFail}}}. |
43 | 5 | Oliver Bril | {{{MSRPChatDidEnd}}} will be posted anyway. |
44 | |||
45 | 6 | Oliver Bril | '''send_message'''(''self'', ''content'', ''content_type''={{{'text/plain'}}}, ''to_uri''={{{None}}}, ''dt''={{{None}}}):: |
46 | Send IM message. Prefer Message/CPIM wrapper if it is supported. If called before the connection was established, the messages will be |
||
47 | queued until MSRPChatDidStart notification. |
||
48 | |||
49 | Return generated MSRP chunk (MSRPData instance); to get Message-ID use its 'message_id' attribute. |
||
50 | |||
51 | ''content'' str:[[BR]] |
||
52 | content of the message |
||
53 | |||
54 | ''to_uri'' SIPURI:[[BR]] |
||
55 | "To" header of CPIM wrapper; use to override the default supplied to {{{__init__}}}. |
||
56 | May only differ from the one supplied in __init__ if the remote party supports private messages. If it does not, {{{MSRPChatError}}} will be raised; |
||
57 | |||
58 | ''content_type'' str:[[BR]] |
||
59 | Content-Type of wrapped message if Message/CPIM is used (Content-Type of MSRP message is always Message/CPIM in that case); |
||
60 | otherwise, Content-Type of MSRP message. |
||
61 | |||
62 | These MSRP headers are used to enable end-to-end success reports and to disable hop-to-hop successful responses: |
||
63 | {{{ |
||
64 | Failure-Report: partial |
||
65 | Success-Report: yes |
||
66 | }}} |
||
67 | |||
68 | 5 | Oliver Bril | |
69 | 1 | Adrian Georgescu | === notifications === |
70 | |||
71 | 7 | Oliver Bril | * MSRPChatDidInitialize |
72 | * MSRPChatDidStart |
||
73 | * MSRPChatWillEnd |
||
74 | * MSRPChatDidEnd |
||
75 | * MSRPChatDidFail |
||
76 | * MSRPChatGotMessage |
||
77 | - cpim_headers (dict) |
||
78 | - message (MSRPData) |
||
79 | - content (str) - the actual string that the remote user has typed |
||
80 | * MSRPChatDidDeliverMessage |
||
81 | * MSRPChatDidNotDeliverMessage |
||
82 | 5 | Oliver Bril | |
83 | 4 | Oliver Bril | == MSRPFileTransfer == |
84 | |||
85 | == MSRPDesktopSharing == |
||
86 | |||
87 | == msrplib == |
||
88 | |||
89 | 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 |
90 | classes for establishing and managing MSRP connection. |
||
91 | |||
92 | The library consist of the following modules: |
||
93 | |||
94 | '''msrplib.transport''':: |
||
95 | Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connection. |
||
96 | 2 | Redmine Admin | |
97 | 1 | Adrian Georgescu | '''msrplib.connect''':: |
98 | Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance. |
||
99 | |||
100 | '''msrplib.session''':: |
||
101 | Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection. |
||
102 | |||
103 | '''msrplib.protocol''':: |
||
104 | Provides representation and parsing of MSRP entities - chunks and URIs. |
||
105 | |||
106 | '''msrplib.trafficlog''':: |
||
107 | Defines {{{Logger}}} class that is used through out the library to log the connection state. |
||
108 | |||
109 | 4 | Oliver Bril | === Usage === |
110 | 1 | Adrian Georgescu | |
111 | 4 | Oliver Bril | ==== Establish a connection ==== |
112 | 3 | Oliver Bril | |
113 | 1 | Adrian Georgescu | {{{msrplib.connect}}} provides a number of classes to establish a connection, so the first |
114 | thing to do is to select which one applies to your situation: |
||
115 | |||
116 | 1. Calling endpoint, not using a relay ({{{ConnectorDirect}}}) |
||
117 | 2. Answering endpoint, not using a relay ({{{AcceptorDirect}}}) |
||
118 | 3. Calling endpoint, using a relay ({{{ConnectorRelay}}}) |
||
119 | 4. Answering endpoint, using a relay ({{{AcceptorRelay}}}) |
||
120 | |||
121 | The answering endpoint may skip using the relay if sure that it's accessible |
||
122 | directly. The calling endpoint is unlikely to need the relay. |
||
123 | |||
124 | Once you have an instance of the right class (use the convenience functions |
||
125 | {{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the |
||
126 | connection is the same: |
||
127 | |||
128 | {{{ |
||
129 | full_local_path = connector.prepare() |
||
130 | try: |
||
131 | ... put full_local_path in SDP 'a:path' attribute |
||
132 | ... get full_remote_path from remote's 'a:path: attribute |
||
133 | ... (the order of the above steps is reversed if you're the |
||
134 | ... answering party, but that does not affect connector's usage) |
||
135 | msrptransport = connector.complete(full_remote_path) |
||
136 | finally: |
||
137 | connector.cleanup() |
||
138 | }}} |
||
139 | |||
140 | To customize connection's parameters, create a new {{{protocol.URI}}} object and pass |
||
141 | it to prepare() function, e.g. |
||
142 | {{{ |
||
143 | local_uri = protocol.URI(use_tls=False, port=5000) |
||
144 | connector.prepare(local_uri) |
||
145 | }}} |
||
146 | |||
147 | {{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters |
||
148 | used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently |
||
149 | only respected by {{{AcceptorDirect}}}. |
||
150 | |||
151 | Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}} |
||
152 | will open a port just to handle one incoming connection and close it right after. |
||
153 | If your application behaves more like a server, i.e. opens a port and listens on it |
||
154 | constantly, use {{{MSRPServer}}} class. |
||
155 | 3 | Oliver Bril | |
156 | 4 | Oliver Bril | === Components === |
157 | 1 | Adrian Georgescu | |
158 | 4 | Oliver Bril | ==== a connector or acceptor ==== |
159 | 3 | Oliver Bril | |
160 | 8 | Oliver Bril | {{{msrplib.connect}}} provides 2 connectors (with and without relay) and 2 acceptors (likewise, with or without relay). All of them have the exact same interface, |
161 | |||
162 | '''prepare'''(''self'', ''local_uri''={{{None}}}):: |
||
163 | Depending on type of the connector, use local_uri to prepare the MSRP connection, which means: |
||
164 | * connecting and authenticating at the relay if a relay is used ({{{ConnectorRelay}}} and {{{AcceptorRelay}}}) |
||
165 | * start listening on a local port for DirectAcceptor |
||
166 | |||
167 | ''local_uri'' is used to specify the connection parameters, e.g. local port and local ip. |
||
168 | If not provided, suitable ''local_uri'' will be generated. |
||
169 | ''local_uri'' maybe updated in place by {{{prepare()}}} method if the real settings used are different from those specified. |
||
170 | |||
171 | {{{prepare}}} returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute. |
||
172 | |||
173 | '''complete'''(''self'', ''full_remote_path''):: |
||
174 | Complete establishing the MSRP connection, which means |
||
175 | * establishing the connection if it wasn't already established ({{{ConnectorDirect}}}) |
||
176 | * bind the connection, i.e. exchange empty chunk to verify each other's From-Path and To-Path |
||
177 | |||
178 | ''full_remote_path'' should be a list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. |
||
179 | |||
180 | {{{complete}}} returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks. |
||
181 | |||
182 | 1 | Adrian Georgescu | |
183 | 4 | Oliver Bril | ==== transport.MSRPTransport ==== |
184 | 1 | Adrian Georgescu | |
185 | Low level access to MSRP connection. |
||
186 | |||
187 | 4 | Oliver Bril | ===== attributes ===== |
188 | 3 | Oliver Bril | |
189 | 4 | Oliver Bril | ===== methods ===== |
190 | 3 | Oliver Bril | |
191 | '''make_chunk'''(''self'', ''transaction_id''={{{None}}}, ''method''={{{'SEND'}}}, ''code''={{{None}}}, ''comment''={{{None}}}, ''data''={{{''}}}, ''contflag''={{{None}}}, ''start''={{{1}}}, ''end''={{{None}}}, ''length''={{{None}}}, ''message_id''={{{None}}}):: |
||
192 | 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''. |
193 | [[BR]]''contflag'':[[BR]] |
||
194 | MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}}, unless you have a partial {{{SEND}}} chunk, in which case it is {{{'+'}}} |
||
195 | |||
196 | 4 | Oliver Bril | ==== session.MSRPSession ==== |
197 | ===== attributes ===== |
||
198 | ===== methods ===== |
||
199 | 1 | Adrian Georgescu | |
200 | 4 | Oliver Bril | ==== connect.MSRPServer ==== |
201 | ===== attributes ===== |
||
202 | ===== methods ===== |