« Previous - Version 11/33 (diff) - Next » - Current version
Saúl Ibarra Corretgé, 07/30/2015 05:47 pm


SylkServer WebRTC gateway application

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.

Architecture

TODO

WebSocket API

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.

The API uses JSON messages and is modeled around 2 concepts: requests and events.

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.

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.

All messages are valid JSON and contain the "sylkrtc" key indicating the message type. A message without the "sylkrtc" key is an invalid message.

Establishing the connection

In order to connect to SylkServer to begin to use the API a WebSocket connection must be established, using the sylkRTC-1 subprotocol. Example:

var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');

After the connection is established, a 'ready' event will be sent to the client, indicating that the connection is ready to be used:

{
  "sylkrtc": "event",
  "event": "ready" 
}

Example:

var conn = new WebSocket('wss://example.com/webrtcgateway/ws', 'sylkRTC-1');
conn.onmessage = function(event) {
    var message = JSON.parse(event.data);
    switch (message.sylkrtc) {
        case 'event':
            if (message.event === 'ready') {
                console.log('Ready to rock!');
            }
            break;
        default:
            console.log('Received message type: ' + message.sylkrtc);
            break;
    }
};

Account management

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.

Note: it's not necessary to register an account in order to make outgoing calls.

add_account

Configures an account on the current connection.

{'account': 'saghul@sip2sip.info',
 'password': '884edfee38ed471b8a15006700139485',
 'sylkrtc': 'add_account',
 'transaction': '04013f0f-25bb-4082-a02f-44399df492ff'}

The password MUST be in HA1 format

remove_account

Removes an account from the current connection.

{'account': 'saghul@sip2sip.info',
 'sylkrtc': 'remove_account',
 'transaction': 'bd3ee25d-5f16-4f76-b34e-8ac3fe0a4ac0'}

register

Triggers the account registration via SIP.

{'account': 'saghul@sip2sip.info',
 'sylkrtc': 'register',
 'transaction': 'bcb87b0f-0cc7-42a9-897e-81f035910670'}

The registration progress will be reported in form of events.

{'account': 'saghul@sip2sip.info',
 'data': {'state': 'registering'},
 'event': 'registration_state',
 'sylkrtc': 'account_event'}

{'account': 'saghul@sip2sip.info',
 'data': {'state': 'registered'},
 'event': 'registration_state',
 'sylkrtc': 'account_event'}

Example of failed registration:

{'account': 'saghul@sip2sip.info',
 'data': {'reason': '904 Operation has no matching challenge ',
          'state': 'failed'},
 'event': 'registration_state',
 'sylkrtc': 'account_event'}

unregister

Unregister the account, via SIP.

{'account': 'saghul@sip2sip.info',
 'sylkrtc': 'unregister',
 'transaction': '1c81eea0-b247-4ced-b3b3-3ced1eba810e'}

Calling

Outgoing calls

TODO

Incoming calls

TODO

Configuration

TODO

Client libraries

In order to interact with SylkServer's WebRTC gateway, we provide the sylkrtc.js 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.