Project

General

Profile

SipMSRPApi » History » Version 6

Oliver Bril, 03/31/2009 12:52 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
 * unwraps incoming Message/CPIM messages
25
 * 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
 When done, post {{{MSRPChatDidEnd}}}. If there was an error, post {{{MSRPChatDidFail}}}.
43
 {{{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
=== notifications ===
70
71
 '''MSRPChatGotMessage''':
72
 Posted for each incoming message with the following attributes:
73
 - cpim_headers (dict); if cpim wrapper was not used, empty dict
74
 - message (MSRPData)
75
 - content (str) - the actual string that the remote user has typed
76
77 4 Oliver Bril
== MSRPFileTransfer ==
78
79
== MSRPDesktopSharing ==
80
81
== msrplib ==
82
83 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
84
classes for establishing and managing MSRP connection.
85
86
The library consist of the following modules:
87
88
 '''msrplib.transport'''::
89
 Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connection.
90 2 Redmine Admin
91 1 Adrian Georgescu
 '''msrplib.connect'''::
92
 Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance.
93
94
 '''msrplib.session'''::
95
 Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection.
96
97
 '''msrplib.protocol'''::
98
 Provides representation and parsing of MSRP entities - chunks and URIs.
99
100
 '''msrplib.trafficlog'''::
101
 Defines {{{Logger}}} class that is used through out the library to log the connection state.
102
  
103 4 Oliver Bril
=== Usage ===
104 1 Adrian Georgescu
105 4 Oliver Bril
==== Establish a connection ====
106 3 Oliver Bril
107 1 Adrian Georgescu
{{{msrplib.connect}}} provides a number of classes to establish a connection, so the first
108
thing to do is to select which one applies to your situation:
109
110
    1. Calling endpoint, not using a relay ({{{ConnectorDirect}}})
111
    2. Answering endpoint, not using a relay ({{{AcceptorDirect}}})
112
    3. Calling endpoint, using a relay ({{{ConnectorRelay}}})
113
    4. Answering endpoint, using a relay ({{{AcceptorRelay}}})
114
115
The answering endpoint may skip using the relay if sure that it's accessible
116
directly. The calling endpoint is unlikely to need the relay.
117
118
Once you have an instance of the right class (use the convenience functions
119
{{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the
120
connection is the same:
121
122
{{{
123
full_local_path = connector.prepare()
124
try:
125
    ... put full_local_path in SDP 'a:path' attribute
126
    ... get full_remote_path from remote's 'a:path: attribute
127
    ... (the order of the above steps is reversed if you're the
128
    ... answering party, but that does not affect connector's usage)
129
    msrptransport = connector.complete(full_remote_path)
130
finally:
131
    connector.cleanup()
132
}}}
133
134
To customize connection's parameters, create a new {{{protocol.URI}}} object and pass
135
it to prepare() function, e.g.
136
{{{
137
local_uri = protocol.URI(use_tls=False, port=5000)
138
connector.prepare(local_uri)
139
}}}
140
141
{{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters
142
used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently
143
only respected by {{{AcceptorDirect}}}.
144
145
Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}}
146
will open a port just to handle one incoming connection and close it right after.
147
If your application behaves more like a server, i.e. opens a port and listens on it
148
constantly, use {{{MSRPServer}}} class.
149 3 Oliver Bril
150 4 Oliver Bril
=== Components ===
151 1 Adrian Georgescu
152 4 Oliver Bril
==== a connector or acceptor ====
153 3 Oliver Bril
154 4 Oliver Bril
===== attributes =====
155
===== methods =====
156 1 Adrian Georgescu
157 4 Oliver Bril
==== transport.MSRPTransport ====
158 1 Adrian Georgescu
159
Low level access to MSRP connection.
160
161 4 Oliver Bril
===== attributes =====
162 3 Oliver Bril
163 4 Oliver Bril
===== methods =====
164 3 Oliver Bril
165
 '''make_chunk'''(''self'', ''transaction_id''={{{None}}}, ''method''={{{'SEND'}}}, ''code''={{{None}}}, ''comment''={{{None}}}, ''data''={{{''}}}, ''contflag''={{{None}}}, ''start''={{{1}}}, ''end''={{{None}}}, ''length''={{{None}}}, ''message_id''={{{None}}})::
166 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''. 
167
 [[BR]]''contflag'':[[BR]]
168
 MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}}, unless you have a partial {{{SEND}}} chunk, in which case it is {{{'+'}}}
169
170 4 Oliver Bril
==== session.MSRPSession ====
171
===== attributes =====
172
===== methods =====
173 1 Adrian Georgescu
174 4 Oliver Bril
==== connect.MSRPServer ====
175
===== attributes =====
176
===== methods =====