The entrypoint to the library is the `sylkrtc` object. Several objects (`Connection`, `Account` and `Call`) inherit from Node's `EventEmitter` class, you may want to check [its documentation](https://nodejs.org/api/events.html).
### sylkrtc
The main entrypoint to the library. It exposes the main function to connect to SylkServer and some utility functions for general use.
#### sylkrtc.createConnection(options={})
Creates a `sylkrtc` connection towards a SylkServer instance. The supported options are "server" and optional object "userAgent". Where server should point to the WebSocket endpoint of the WebRTC gateway application. Example: `wss://1.2.3.4:8088/webrtcgateway/ws`.
It returns a `Connection` object.
Example:
let connection = sylkrtc.createConnection({server: 'wss://1.2.3.4:8088/webrtcgateway/ws'});
If the optional userAgent object is given, it should contain:
* `name` : string with the name of the application.
* `attachMediaStream`: function to easily attach a media stream to an element. It reexports [attachmediastream](https://github.com/otalk/attachMediaStream).
* `closeMediaStream`: function to close the given media stream.
* `sanatizeHtml`: function to XSS sanitize html strings
### Connection
Object representing the interaction with SylkServer. Multiple connections can be created with
`sylkrtc.createConnection`, but typically only one is needed. Reconnecting in case the connection is interrupted is
taken care of automatically.
Events emitted:
* **stateChanged**: indicates the WebSocket connection state has changed. Two arguments are provided: `oldState` and
`newState`, the old connection state and the new connection state, respectively. Possible state values are: null,
connecting, connected, ready, disconnected and closed. If the connection is involuntarily interrupted the state will
transition to disconnected and the connection will be retried. Once the closed state is set, as a result of the user
calling Connection.close(), the connection can no longer be used or reconnected.
#### Connection.addAccount(options={}, cb=null)
Configures an `Account` to be used through `sylkrtc`. 2 options are required: *account* (the account ID) and
*password*. An optional *displayName* can be set. The account won't be registered, it will just be created.
Optionally *realm* can be passed, which will be used instead of the domain for the HA1 calculation.
The *password* won't be stored or transmitted as given, the HA1 hash (as used in
[Digest access authentication](https://en.wikipedia.org/wiki/Digest_access_authentication)) is created and used instead.
The `cb` argument is a callback which will be called with an error and the account object
Send a (SIP) message to uri. The message will be send with IMDN enabled. `message` should contain a string, `type` should contain the message content type like
'text/plain', 'text/html', 'image/png'. The function returns an instance of `Message`.