Project

General

Profile

WebRTC » History » Version 24

Adrian Georgescu, 08/01/2015 06:03 AM

1 1 Saúl Ibarra Corretgé
h1. SylkServer WebRTC gateway application
2
3 2 Saúl Ibarra Corretgé
Starting with version 3.0.0 SylkServer includes a WebRTC gateway application. The application implements a WebSocket protocol which WebRTC endpoints can use in order to interact with the SIP world.
4
5 24 Adrian Georgescu
h2. Deployment scenarios
6
7
 * Web page calling using a WebRTC enabled web browsers like Firefox and Google Chrome by using a standard SIP account
8
 * Mobile iOS and Android application for audio and video calling
9
10 2 Saúl Ibarra Corretgé
h2. Architecture
11 1 Saúl Ibarra Corretgé
12 21 Saúl Ibarra Corretgé
The SylkServer WebRTC gateway application consists of different (internal and external) components, which together aim to provide the same communication experience as with "Blink":http://icanblink.com or any other feature-full SIP client.
13
14
TODO: diagram
15
16
All interaction with the gateway from the Web's side is performed through a WebSocket connection using the "sylkRTC protocol" described in this document.
17
18
h5. Audio / video sessions
19
20
Audio and video sessions support is provided through an external component: "Janus.":https://github.com/meetecho/janus-gateway SylkServer communicates directly with Janus and offers a complete API together with the rest of the components described below.
21
22
h5. Chat sessions
23
24
Not implemented yet, consider this an early blueprint.
25
26
Chat sessions are implemented as an internal component which translates JSON messages over WebSocket with MSRP chat messages. The payload will remain unchanged, so CPIM is mandatory and will be used end to end. A library such as "cpim.js":https://github.com/eface2face/cpim.js can be used to parse chat messages in a JavaScript application.
27
28
h5. Contacts management and presence
29
30
Not implemented yet, consider this an early blueprint.
31
32
Contacts management is implemented as an internal component which fetches the user's XCAP documents and translates the contact list into JSON format, which is then sent over the WebSocket connection.
33
34
Presence information is gathered by sending SIP SUBSCRIBE requests on behalf of the user. The presence information is combined with the contact information and provided via JSON events to the application.
35 2 Saúl Ibarra Corretgé
36
h2. WebSocket API
37
38 5 Saúl Ibarra Corretgé
SylkServer offers the WebSocket API in order to interact with the WebRTC gateway in the @ws(s)://hostname:port/webrtcgateway/ws@ endpoint. Both WebSocket and Secure WebSocket are supported, depending on how SylkServer was configured, check the configuration section.
39 1 Saúl Ibarra Corretgé
40 18 Saúl Ibarra Corretgé
The API uses JSON messages and is modeled around 2 concepts: requests and events. We call this the sylkRTC protocol.
41 5 Saúl Ibarra Corretgé
42
A request represents an action which SylkServer should perform, and it's identified with a transaction ID which the user must provide. SylkServer will reply with either an 'ack' or an 'error' response, with the associated transaction ID. An example transaction is that of adding an account.
43
44
Events are notifications sent by SylkServer to the client. They are the result of some change triggered by a user action, but they don't have a transaction ID associated with them. An example event would be the connection state changed event.
45 1 Saúl Ibarra Corretgé
46 7 Saúl Ibarra Corretgé
All messages are valid JSON and contain the "sylkrtc" key indicating the message type. A message without the "sylkrtc" key is an invalid message.
47
48 5 Saúl Ibarra Corretgé
h3. Establishing the connection
49 1 Saúl Ibarra Corretgé
50 6 Saúl Ibarra Corretgé
In order to connect to SylkServer to begin to use the API a WebSocket connection must be established, using the @sylkRTC-1@ subprotocol. Example:
51
52
<pre>
53
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
54
</pre>
55
56
After the connection is established, a 'ready' event will be sent to the client, indicating that the connection is ready to be used:
57
58
<pre>
59 18 Saúl Ibarra Corretgé
{"event": "ready", "sylkrtc": "event"}
60 6 Saúl Ibarra Corretgé
</pre>
61 1 Saúl Ibarra Corretgé
62 7 Saúl Ibarra Corretgé
Example:
63
64
<pre>
65
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
66
conn.onmessage = function(event) {
67
    var message = JSON.parse(event.data);
68
    switch (message.sylkrtc) {
69
        case 'event':
70
            if (message.event === 'ready') {
71
                console.log('Ready to rock!');
72
            }
73
            break;
74
        default:
75
            console.log('Received message type: ' + message.sylkrtc);
76
            break;
77 1 Saúl Ibarra Corretgé
    }
78 7 Saúl Ibarra Corretgé
};
79
</pre>
80
81
h3. Account management
82 5 Saúl Ibarra Corretgé
83 18 Saúl Ibarra Corretgé
Multiple accounts can be managed from a single WebSocket connection. 2 types of requests are used to manage accounts: "account-add" and "account-remove". Once an account has been added it can be registered via SIP using the "account-register" command, and unregistered using the "account-unregister" command.
84 8 Saúl Ibarra Corretgé
85 10 Saúl Ibarra Corretgé
Note: it's not necessary to register an account in order to make outgoing calls.
86 1 Saúl Ibarra Corretgé
87 18 Saúl Ibarra Corretgé
h5. account-add
88 13 Saúl Ibarra Corretgé
89 8 Saúl Ibarra Corretgé
Configures an account on the current connection.
90
91 1 Saúl Ibarra Corretgé
<pre>
92 8 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
93
 'password': '884edfee38ed471b8a15006700139485',
94 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-add',
95 8 Saúl Ibarra Corretgé
 'transaction': '04013f0f-25bb-4082-a02f-44399df492ff'}
96 1 Saúl Ibarra Corretgé
</pre>
97 8 Saúl Ibarra Corretgé
98
The password MUST be in "HA1 format":https://en.wikipedia.org/wiki/Digest_access_authentication#Overview
99 9 Saúl Ibarra Corretgé
100 18 Saúl Ibarra Corretgé
h5. account-remove
101 9 Saúl Ibarra Corretgé
102
Removes an account from the current connection.
103
104 8 Saúl Ibarra Corretgé
<pre>
105 1 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
106 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-remove',
107 9 Saúl Ibarra Corretgé
 'transaction': 'bd3ee25d-5f16-4f76-b34e-8ac3fe0a4ac0'}
108
</pre>
109 1 Saúl Ibarra Corretgé
110 13 Saúl Ibarra Corretgé
h5. register
111 1 Saúl Ibarra Corretgé
112 9 Saúl Ibarra Corretgé
Triggers the account registration via SIP.
113 1 Saúl Ibarra Corretgé
114 9 Saúl Ibarra Corretgé
<pre>
115
{'account': 'saghul@sip2sip.info',
116 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-register',
117 9 Saúl Ibarra Corretgé
 'transaction': 'bcb87b0f-0cc7-42a9-897e-81f035910670'}
118
</pre>
119
120
The registration progress will be reported in form of events.
121
122
<pre>
123
{'account': 'saghul@sip2sip.info',
124
 'data': {'state': 'registering'},
125
 'event': 'registration_state',
126
 'sylkrtc': 'account_event'}
127
128
{'account': 'saghul@sip2sip.info',
129
 'data': {'state': 'registered'},
130
 'event': 'registration_state',
131
 'sylkrtc': 'account_event'}
132 1 Saúl Ibarra Corretgé
</pre>
133 9 Saúl Ibarra Corretgé
134
Example of failed registration:
135
136
<pre>
137 1 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
138 9 Saúl Ibarra Corretgé
 'data': {'reason': '904 Operation has no matching challenge ',
139
          'state': 'failed'},
140
 'event': 'registration_state',
141
 'sylkrtc': 'account_event'}
142 1 Saúl Ibarra Corretgé
</pre>
143 9 Saúl Ibarra Corretgé
144 18 Saúl Ibarra Corretgé
h5. account-unregister
145 13 Saúl Ibarra Corretgé
146 1 Saúl Ibarra Corretgé
Unregister the account, via SIP.
147 10 Saúl Ibarra Corretgé
148
<pre>
149
{'account': 'saghul@sip2sip.info',
150 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-unregister',
151 1 Saúl Ibarra Corretgé
 'transaction': '1c81eea0-b247-4ced-b3b3-3ced1eba810e'}
152 10 Saúl Ibarra Corretgé
</pre>
153 9 Saúl Ibarra Corretgé
154 18 Saúl Ibarra Corretgé
h3. Sessions
155 1 Saúl Ibarra Corretgé
156 18 Saúl Ibarra Corretgé
h5. Incoming sessions
157 1 Saúl Ibarra Corretgé
158 18 Saúl Ibarra Corretgé
Incoming sessions are received via an *incoming_session* event:
159 14 Saúl Ibarra Corretgé
160 1 Saúl Ibarra Corretgé
<pre>
161 14 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
162 20 Saúl Ibarra Corretgé
 'data': {'originator': '31208005163@ag-projects.com', 'sdp': '...'},
163 18 Saúl Ibarra Corretgé
 'event': 'incoming_session',
164 1 Saúl Ibarra Corretgé
 'session': '509b256aa6a14540a2a37553e6bd33e1',
165 14 Saúl Ibarra Corretgé
 'sylkrtc': 'account_event'}
166 1 Saúl Ibarra Corretgé
167 14 Saúl Ibarra Corretgé
</pre>
168 1 Saúl Ibarra Corretgé
169 18 Saúl Ibarra Corretgé
The "session-answer" request can be used in order to answer an incoming session:
170 1 Saúl Ibarra Corretgé
171
<pre>
172 15 Saúl Ibarra Corretgé
{'sdp': '...',
173
 'session': '38dffdf81acb44b2b11b61f4488c4ca9',
174 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-answer',
175 15 Saúl Ibarra Corretgé
 'transaction': '179a855f-75a0-45a4-b5ef-0be8eb8389d1'}
176 1 Saúl Ibarra Corretgé
</pre>
177 15 Saúl Ibarra Corretgé
178 18 Saúl Ibarra Corretgé
h5. Outgoing sessions
179 14 Saúl Ibarra Corretgé
180 18 Saúl Ibarra Corretgé
In order to create an outgoing session the "session-create" request is used, by passing the SDP returned by the web browser. There is no need to wait for all ICE candidates since trickle ICE is used.
181 1 Saúl Ibarra Corretgé
182 14 Saúl Ibarra Corretgé
<pre>
183
{'account': 'saghul@sip2sip.info',
184
 'sdp': '...',
185
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
186 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-create',
187 1 Saúl Ibarra Corretgé
 'transaction': '7afcb91a-8a64-4664-9448-8cb760492e1f',
188
 'uri': '3333@sip2sip.info'}
189 14 Saúl Ibarra Corretgé
</pre>
190
191 15 Saúl Ibarra Corretgé
h5. Trickle ICE
192
193 18 Saúl Ibarra Corretgé
As new candidates are discovered they must be sent to the server using 'session-trickle' requests:
194 14 Saúl Ibarra Corretgé
195
<pre>
196
{'candidates': [{'candidate': 'candidate:0 1 UDP 2130379007 192.168.99.44 59051 typ host',
197
                 'sdpMLineIndex': 0,
198
                 'sdpMid': ''}],
199 1 Saúl Ibarra Corretgé
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
200 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-trickle',
201 1 Saúl Ibarra Corretgé
 'transaction': 'ecf777d8-7d26-4f16-bace-18f6fae5d8f8'}
202
</pre>
203
204 19 Saúl Ibarra Corretgé
Use an empty list of candidates to indicate that no more candidates will be sent.
205
206 15 Saúl Ibarra Corretgé
This applies to both incoming and outgoing calls.
207
208
There is no need to wait for the acknowledgement for the "session-create" or "session-answer" request before sending "session-trickle" requests.
209 1 Saúl Ibarra Corretgé
210 19 Saúl Ibarra Corretgé
h5. Terminating sessions
211 15 Saúl Ibarra Corretgé
212 19 Saúl Ibarra Corretgé
A session can be terminated at any time by sending the "session-terminate" request:
213 1 Saúl Ibarra Corretgé
214 15 Saúl Ibarra Corretgé
<pre>
215
{'session': '38dffdf81acb44b2b11b61f4488c4ca9',
216 19 Saúl Ibarra Corretgé
 'sylkrtc': 'session-terminate',
217 15 Saúl Ibarra Corretgé
 'transaction': '4d169de8-fe55-41f8-9a5c-c5f66c0a23c7'}
218 1 Saúl Ibarra Corretgé
</pre>
219 15 Saúl Ibarra Corretgé
220
h5. Events
221
222 19 Saúl Ibarra Corretgé
Session state related events are reported via the "session_event" event:
223 16 Saúl Ibarra Corretgé
224
<pre>
225
'data': {'state': 'established'},
226
 'event': 'state',
227
 'session': '38dffdf81acb44b2b11b61f4488c4ca9',
228
 'sylkrtc': 'session_event'}
229
</pre>
230
231
<pre>
232
{'data': {'sdp': '...', 'state': 'accepted'},
233
 'event': 'state',
234
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
235
 'sylkrtc': 'session_event'}
236
</pre>
237
238
<pre>
239
{'data': {'reason': '200 to BYE', 'state': 'terminated'},
240 1 Saúl Ibarra Corretgé
 'event': 'state',
241
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
242 16 Saúl Ibarra Corretgé
 'sylkrtc': 'session_event'}
243
</pre>
244
245 19 Saúl Ibarra Corretgé
Valid session states:
246 17 Saúl Ibarra Corretgé
247 19 Saúl Ibarra Corretgé
* incoming: initial state for incoming sessions, no state event is sent for this state.
248
* progress: on outgoing sessions, when in progress.
249
* accepted: both for incoming and outgoing, when the session has been accepted by the remote party. For incoming, an "sdp" attribute will be present in the "data" section, as shown in the example above. 
250
* established: the session has been established media-wise.
251
* terminated: session was terminated, the "reason" attribute indicates the termination reason.
252 4 Saúl Ibarra Corretgé
253
h2. Configuration
254
255 2 Saúl Ibarra Corretgé
TODO
256
257 23 Saúl Ibarra Corretgé
h2. JavaScript client library
258 1 Saúl Ibarra Corretgé
259
In order to interact with SylkServer's WebRTC gateway, we provide the "sylkrtc.js":http://projects.ag-projects.com/projects/sylkrtc JavaScript library. It implements the API described in this document in an easy to use manner. Check the README file in the project for the JavaScript API documentation.