Project

General

Profile

WebRTC » History » Version 20

Saúl Ibarra Corretgé, 07/31/2015 03:44 PM

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
6
h2. Architecture
7
8 1 Saúl Ibarra Corretgé
TODO
9 2 Saúl Ibarra Corretgé
10
h2. WebSocket API
11
12 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.
13 1 Saúl Ibarra Corretgé
14 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.
15 5 Saúl Ibarra Corretgé
16
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.
17
18
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.
19 1 Saúl Ibarra Corretgé
20 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.
21
22 5 Saúl Ibarra Corretgé
h3. Establishing the connection
23 1 Saúl Ibarra Corretgé
24 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:
25
26
<pre>
27
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
28
</pre>
29
30
After the connection is established, a 'ready' event will be sent to the client, indicating that the connection is ready to be used:
31
32
<pre>
33 18 Saúl Ibarra Corretgé
{"event": "ready", "sylkrtc": "event"}
34 6 Saúl Ibarra Corretgé
</pre>
35 1 Saúl Ibarra Corretgé
36 7 Saúl Ibarra Corretgé
Example:
37
38
<pre>
39
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
40
conn.onmessage = function(event) {
41
    var message = JSON.parse(event.data);
42
    switch (message.sylkrtc) {
43
        case 'event':
44
            if (message.event === 'ready') {
45
                console.log('Ready to rock!');
46
            }
47
            break;
48
        default:
49
            console.log('Received message type: ' + message.sylkrtc);
50
            break;
51 1 Saúl Ibarra Corretgé
    }
52 7 Saúl Ibarra Corretgé
};
53
</pre>
54
55
h3. Account management
56 5 Saúl Ibarra Corretgé
57 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.
58 8 Saúl Ibarra Corretgé
59 10 Saúl Ibarra Corretgé
Note: it's not necessary to register an account in order to make outgoing calls.
60 1 Saúl Ibarra Corretgé
61 18 Saúl Ibarra Corretgé
h5. account-add
62 13 Saúl Ibarra Corretgé
63 8 Saúl Ibarra Corretgé
Configures an account on the current connection.
64
65 1 Saúl Ibarra Corretgé
<pre>
66 8 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
67
 'password': '884edfee38ed471b8a15006700139485',
68 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-add',
69 8 Saúl Ibarra Corretgé
 'transaction': '04013f0f-25bb-4082-a02f-44399df492ff'}
70 1 Saúl Ibarra Corretgé
</pre>
71 8 Saúl Ibarra Corretgé
72
The password MUST be in "HA1 format":https://en.wikipedia.org/wiki/Digest_access_authentication#Overview
73 9 Saúl Ibarra Corretgé
74 18 Saúl Ibarra Corretgé
h5. account-remove
75 9 Saúl Ibarra Corretgé
76
Removes an account from the current connection.
77
78 8 Saúl Ibarra Corretgé
<pre>
79 1 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
80 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-remove',
81 9 Saúl Ibarra Corretgé
 'transaction': 'bd3ee25d-5f16-4f76-b34e-8ac3fe0a4ac0'}
82
</pre>
83 1 Saúl Ibarra Corretgé
84 13 Saúl Ibarra Corretgé
h5. register
85 1 Saúl Ibarra Corretgé
86 9 Saúl Ibarra Corretgé
Triggers the account registration via SIP.
87 1 Saúl Ibarra Corretgé
88 9 Saúl Ibarra Corretgé
<pre>
89
{'account': 'saghul@sip2sip.info',
90 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-register',
91 9 Saúl Ibarra Corretgé
 'transaction': 'bcb87b0f-0cc7-42a9-897e-81f035910670'}
92
</pre>
93
94
The registration progress will be reported in form of events.
95
96
<pre>
97
{'account': 'saghul@sip2sip.info',
98
 'data': {'state': 'registering'},
99
 'event': 'registration_state',
100
 'sylkrtc': 'account_event'}
101
102
{'account': 'saghul@sip2sip.info',
103
 'data': {'state': 'registered'},
104
 'event': 'registration_state',
105
 'sylkrtc': 'account_event'}
106 1 Saúl Ibarra Corretgé
</pre>
107 9 Saúl Ibarra Corretgé
108
Example of failed registration:
109
110
<pre>
111 1 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
112 9 Saúl Ibarra Corretgé
 'data': {'reason': '904 Operation has no matching challenge ',
113
          'state': 'failed'},
114
 'event': 'registration_state',
115
 'sylkrtc': 'account_event'}
116 1 Saúl Ibarra Corretgé
</pre>
117 9 Saúl Ibarra Corretgé
118 18 Saúl Ibarra Corretgé
h5. account-unregister
119 13 Saúl Ibarra Corretgé
120 1 Saúl Ibarra Corretgé
Unregister the account, via SIP.
121 10 Saúl Ibarra Corretgé
122
<pre>
123
{'account': 'saghul@sip2sip.info',
124 18 Saúl Ibarra Corretgé
 'sylkrtc': 'account-unregister',
125 1 Saúl Ibarra Corretgé
 'transaction': '1c81eea0-b247-4ced-b3b3-3ced1eba810e'}
126 10 Saúl Ibarra Corretgé
</pre>
127 9 Saúl Ibarra Corretgé
128 18 Saúl Ibarra Corretgé
h3. Sessions
129 1 Saúl Ibarra Corretgé
130 18 Saúl Ibarra Corretgé
h5. Incoming sessions
131 1 Saúl Ibarra Corretgé
132 18 Saúl Ibarra Corretgé
Incoming sessions are received via an *incoming_session* event:
133 14 Saúl Ibarra Corretgé
134 1 Saúl Ibarra Corretgé
<pre>
135 14 Saúl Ibarra Corretgé
{'account': 'saghul@sip2sip.info',
136 20 Saúl Ibarra Corretgé
 'data': {'originator': '31208005163@ag-projects.com', 'sdp': '...'},
137 18 Saúl Ibarra Corretgé
 'event': 'incoming_session',
138 1 Saúl Ibarra Corretgé
 'session': '509b256aa6a14540a2a37553e6bd33e1',
139 14 Saúl Ibarra Corretgé
 'sylkrtc': 'account_event'}
140 1 Saúl Ibarra Corretgé
141 14 Saúl Ibarra Corretgé
</pre>
142 1 Saúl Ibarra Corretgé
143 18 Saúl Ibarra Corretgé
The "session-answer" request can be used in order to answer an incoming session:
144 1 Saúl Ibarra Corretgé
145
<pre>
146 15 Saúl Ibarra Corretgé
{'sdp': '...',
147
 'session': '38dffdf81acb44b2b11b61f4488c4ca9',
148 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-answer',
149 15 Saúl Ibarra Corretgé
 'transaction': '179a855f-75a0-45a4-b5ef-0be8eb8389d1'}
150 1 Saúl Ibarra Corretgé
</pre>
151 15 Saúl Ibarra Corretgé
152 18 Saúl Ibarra Corretgé
h5. Outgoing sessions
153 14 Saúl Ibarra Corretgé
154 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.
155 1 Saúl Ibarra Corretgé
156 14 Saúl Ibarra Corretgé
<pre>
157
{'account': 'saghul@sip2sip.info',
158
 'sdp': '...',
159
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
160 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-create',
161 1 Saúl Ibarra Corretgé
 'transaction': '7afcb91a-8a64-4664-9448-8cb760492e1f',
162
 'uri': '3333@sip2sip.info'}
163 14 Saúl Ibarra Corretgé
</pre>
164
165 15 Saúl Ibarra Corretgé
h5. Trickle ICE
166
167 18 Saúl Ibarra Corretgé
As new candidates are discovered they must be sent to the server using 'session-trickle' requests:
168 14 Saúl Ibarra Corretgé
169
<pre>
170
{'candidates': [{'candidate': 'candidate:0 1 UDP 2130379007 192.168.99.44 59051 typ host',
171
                 'sdpMLineIndex': 0,
172
                 'sdpMid': ''}],
173 1 Saúl Ibarra Corretgé
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
174 18 Saúl Ibarra Corretgé
 'sylkrtc': 'session-trickle',
175 1 Saúl Ibarra Corretgé
 'transaction': 'ecf777d8-7d26-4f16-bace-18f6fae5d8f8'}
176
</pre>
177
178 19 Saúl Ibarra Corretgé
Use an empty list of candidates to indicate that no more candidates will be sent.
179
180 15 Saúl Ibarra Corretgé
This applies to both incoming and outgoing calls.
181
182
There is no need to wait for the acknowledgement for the "session-create" or "session-answer" request before sending "session-trickle" requests.
183 1 Saúl Ibarra Corretgé
184 19 Saúl Ibarra Corretgé
h5. Terminating sessions
185 15 Saúl Ibarra Corretgé
186 19 Saúl Ibarra Corretgé
A session can be terminated at any time by sending the "session-terminate" request:
187 1 Saúl Ibarra Corretgé
188 15 Saúl Ibarra Corretgé
<pre>
189
{'session': '38dffdf81acb44b2b11b61f4488c4ca9',
190 19 Saúl Ibarra Corretgé
 'sylkrtc': 'session-terminate',
191 15 Saúl Ibarra Corretgé
 'transaction': '4d169de8-fe55-41f8-9a5c-c5f66c0a23c7'}
192 1 Saúl Ibarra Corretgé
</pre>
193 15 Saúl Ibarra Corretgé
194
h5. Events
195
196 19 Saúl Ibarra Corretgé
Session state related events are reported via the "session_event" event:
197 16 Saúl Ibarra Corretgé
198
<pre>
199
'data': {'state': 'established'},
200
 'event': 'state',
201
 'session': '38dffdf81acb44b2b11b61f4488c4ca9',
202
 'sylkrtc': 'session_event'}
203
</pre>
204
205
<pre>
206
{'data': {'sdp': '...', 'state': 'accepted'},
207
 'event': 'state',
208
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
209
 'sylkrtc': 'session_event'}
210
</pre>
211
212
<pre>
213
{'data': {'reason': '200 to BYE', 'state': 'terminated'},
214 1 Saúl Ibarra Corretgé
 'event': 'state',
215
 'session': '20c40185-1ef2-419e-b91a-70415778acb4',
216 16 Saúl Ibarra Corretgé
 'sylkrtc': 'session_event'}
217
</pre>
218
219 19 Saúl Ibarra Corretgé
Valid session states:
220 17 Saúl Ibarra Corretgé
221 19 Saúl Ibarra Corretgé
* incoming: initial state for incoming sessions, no state event is sent for this state.
222
* progress: on outgoing sessions, when in progress.
223
* 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. 
224
* established: the session has been established media-wise.
225
* terminated: session was terminated, the "reason" attribute indicates the termination reason.
226 4 Saúl Ibarra Corretgé
227
h2. Configuration
228
229 2 Saúl Ibarra Corretgé
TODO
230
231
h2. Client libraries
232 1 Saúl Ibarra Corretgé
233
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.