Project

General

Profile

WebRTC » History » Version 16

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