WebRTC

Version 7 (Saúl Ibarra Corretgé, 07/30/2015 05:00 pm)

1 1 Saúl Ibarra Corretgé
h1. SylkServer WebRTC gateway application
2 1 Saúl Ibarra Corretgé
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 2 Saúl Ibarra Corretgé
5 2 Saúl Ibarra Corretgé
6 2 Saúl Ibarra Corretgé
h2. Architecture
7 2 Saúl Ibarra Corretgé
8 1 Saúl Ibarra Corretgé
TODO
9 2 Saúl Ibarra Corretgé
10 2 Saúl Ibarra Corretgé
h2. WebSocket API
11 2 Saúl Ibarra Corretgé
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 5 Saúl Ibarra Corretgé
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 5 Saúl Ibarra Corretgé
18 5 Saúl Ibarra Corretgé
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 7 Saúl Ibarra Corretgé
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 6 Saúl Ibarra Corretgé
26 6 Saúl Ibarra Corretgé
<pre>
27 6 Saúl Ibarra Corretgé
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
28 6 Saúl Ibarra Corretgé
</pre>
29 6 Saúl Ibarra Corretgé
30 6 Saúl Ibarra Corretgé
After the connection is established, a 'ready' event will be sent to the client, indicating that the connection is ready to be used:
31 6 Saúl Ibarra Corretgé
32 6 Saúl Ibarra Corretgé
<pre>
33 6 Saúl Ibarra Corretgé
{
34 6 Saúl Ibarra Corretgé
  "sylkrtc": "event",
35 6 Saúl Ibarra Corretgé
  "event": "ready"
36 6 Saúl Ibarra Corretgé
}
37 6 Saúl Ibarra Corretgé
38 6 Saúl Ibarra Corretgé
</pre>
39 1 Saúl Ibarra Corretgé
40 7 Saúl Ibarra Corretgé
Example:
41 7 Saúl Ibarra Corretgé
42 7 Saúl Ibarra Corretgé
<pre>
43 7 Saúl Ibarra Corretgé
var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
44 7 Saúl Ibarra Corretgé
conn.onmessage = function(event) {
45 7 Saúl Ibarra Corretgé
    var message = JSON.parse(event.data);
46 7 Saúl Ibarra Corretgé
    switch (message.sylkrtc) {
47 7 Saúl Ibarra Corretgé
        case 'event':
48 7 Saúl Ibarra Corretgé
            if (message.event === 'ready') {
49 7 Saúl Ibarra Corretgé
                console.log('Ready to rock!');
50 7 Saúl Ibarra Corretgé
            }
51 7 Saúl Ibarra Corretgé
            break;
52 7 Saúl Ibarra Corretgé
        default:
53 7 Saúl Ibarra Corretgé
            console.log('Received message type: ' + message.sylkrtc);
54 7 Saúl Ibarra Corretgé
            break;
55 7 Saúl Ibarra Corretgé
    }
56 7 Saúl Ibarra Corretgé
};
57 7 Saúl Ibarra Corretgé
</pre>
58 7 Saúl Ibarra Corretgé
59 5 Saúl Ibarra Corretgé
h3. Account management
60 5 Saúl Ibarra Corretgé
61 5 Saúl Ibarra Corretgé
TODO
62 5 Saúl Ibarra Corretgé
63 5 Saúl Ibarra Corretgé
h3. Calling
64 5 Saúl Ibarra Corretgé
65 5 Saúl Ibarra Corretgé
TODO
66 2 Saúl Ibarra Corretgé
67 4 Saúl Ibarra Corretgé
h2. Configuration
68 4 Saúl Ibarra Corretgé
69 4 Saúl Ibarra Corretgé
TODO
70 4 Saúl Ibarra Corretgé
71 2 Saúl Ibarra Corretgé
h2. Client libraries
72 2 Saúl Ibarra Corretgé
73 2 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.