• Public
  • Public/Protected
  • All


SaltyRTC JavaScript Client

Travis branch Supported ES Standard npm Version npm Downloads License CII Best Practices

This is a SaltyRTC v1 implementation for JavaScript (ES5) written in TypeScript 2.0+.

Warning: This is beta software. Use at your own risk. Testing and review is welcome!

The library has been tested with Firefox 45+ and Chromium 49+.


Via npm

You can install this library via npm:

npm install --save @saltyrtc/client msgpack-lite tweetnacl


Alternatively, copy one of the following files to your project directly:

  • ES2015: dist/saltyrtc-client.es2015.js
  • ES5: dist/saltyrtc-client.es5.js
  • ES5 minified: dist/saltyrtc-client.es5.min.js
  • ES5 minified polyfilled: dist/saltyrtc-client.es5.min.polyfill.js

Make sure to manually add the following external dependencies to your project:


First, create a keypair:

let permanentKey = new saltyrtcClient.KeyStore();

Then, create a SaltyRTCBuilder instance:

let builder = new saltyrtcClient.SaltyRTCBuilder()
    .connectTo(saltyrtcHost, saltyrtcPort)

Depending on whether you're the initiator or the responder, initialize the SaltyRTC instance:

let initiator = builder.asInitiator();
let responder = builder.initiatorInfo(permanentKey.publicKeyBytes, initiator.authTokenBytes).asResponder();

You can also use trusted keys to connect:

let trustingInitiator = builder.withTrustedPeerKey(responderKey).asInitiator();
let trustingResponder = builder.withTrustedPeerKey(initiatorKey).asResponder();

Now you can connect both sides:


You can query the current signaling state:

>>> console.log(initiator.state)

And you can register callbacks for certain events:

initiator.on('handover', () => console.log('Handover is done'));
responder.on('state-change', (newState) => console.log('New signaling state:', newState));

The following events are available:

  • state-change(saltyrtcClient.SignalingState): The signaling state changed.
  • state-change:<new-state>(void): The signaling state change event, filtered by state.
  • new-responder(responderId): A responder has connected. This event is only dispatched for the initiator.
  • application(data): An application message has arrived.
  • handover(void): The handover to the data channel is done.
  • signaling-connection-lost(responderId): The signaling connection to the specified peer was lost.
  • connection-closed(closeCode): The connection was closed.
  • connection-error(ErrorEvent): A websocket connection error occured.


Install dependencies:

$ npm install

To compile the TypeScript sources to a single JavaScript (ES5 / Minified ES5 / ES2015) file:

$ npm run dist

The resulting files will be located in dist/.

Due to a bug (https://github.com/rollup/rollup-plugin-typescript/issues/43), rollup does not currently output non-fatal errors from TypeScript. To see those, simply issue npm run validate in your main directory.

$ npm run validate


To compile the test sources, run:

$ npm run rollup_tests

Then simply open tests/testsuite.html in your browser!

Alternatively, run the tests automatically in Firefox and Chrome:

$ npm test


Responsible Disclosure / Reporting Security Issues

Please report security issues directly to one or both of the following contacts:

Coding Guidelines

  • Write clean ES2015
  • Favor const over let


MIT, see LICENSE.md.

Generated using TypeDoc