WebRTC Task for saltyrtc-client-js.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
dist
rollup
src
tests
.editorconfig
.gitignore
CHANGELOG.md
LICENSE.md
README.md
RELEASING.md
karma.conf.js
package-lock.json
package.json
saltyrtc-task-webrtc.d.ts
tsconfig.json

README.md

SaltyRTC WebRTC Task for JavaScript

CircleCI Supported ES Standard npm Version npm Downloads License Chat on Gitter

This is a SaltyRTC WebRTC task implementation for JavaScript (ES5 / ES2015), written in TypeScript 2.

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

Installing

Via npm

You can install this library via npm:

npm install --save @saltyrtc/task-webrtc @saltyrtc/client

Usage

When creating the task instance, you can specify whether or not a handover to a secure data channel is desired.

let task = new WebRTCTask(true);

You can also specify the max DataChannel chunk size:

let task = new WebRTCTask(true, 65536);

If you don't specify any values, handover defaults to true and the chunk size defaults to 16384.

The handover can be initiated using the handover method:

let started = task.handover(peerConnection);

Note: You should call this method before creating offer/answer!

To send offers, answers and candidates, use the following task methods:

  • .sendOffer(offer: RTCSessionDescriptionInit): void
  • .sendAnswer(answer: RTCSessionDescriptionInit): void
  • .sendCandidate(candidate: RTCIceCandidateInit): void
  • .sendCandidates(candidates: RTCIceCandidateInit[]): void

You can register and deregister event handlers with the on, once and off methods:

task.on('candidates', (e) => {
    for (let candidateInit of e.data) {
        pc.addIceCandidate(candidateInit);
    }
});

The following events are available:

  • offer(saltyrtc.tasks.webrtc.Offer): An offer message was received.
  • answer(saltyrtc.tasks.webrtc.Answer): An answer message was received.
  • candidates(saltyrtc.tasks.webrtc.Candidates): A candidates message was received.
  • disconnected(number): A previously authenticated peer disconnected from the signaling server.

To know when the handover is finished, please subscribe to the handover event on the client directly.

Testing

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

Security

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

License

MIT, see LICENSE.md.