saltyrtc-task-webrtc
Version:
A SaltyRTC WebRTC task implementation.
70 lines (43 loc) • 2.6 kB
Markdown
# SaltyRTC WebRTC Task for JavaScript
[](https://travis-ci.org/saltyrtc/saltyrtc-task-webrtc-js)
[](https://github.com/saltyrtc/saltyrtc-task-webrtc-js)
[](https://www.npmjs.com/package/saltyrtc-task-webrtc)
[](https://www.npmjs.com/package/saltyrtc-task-webrtc)
[](https://github.com/saltyrtc/saltyrtc-task-webrtc-js)
This is a [SaltyRTC](https://github.com/saltyrtc/saltyrtc-meta) WebRTC task implementation
for JavaScript, written in TypeScript.
The development is still ongoing, the current version is only at alpha-level
and should not be used for production yet.
## 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`.
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`
The handover can be initiated using the handover method:
let started = task.handover(peerConnection);
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.
To know when the handover is finished, please subscribe to the `handover` event on the client directly.
## Coding Guidelines
- Write clean ES2015
- Favor `const` over `let`
## License
MIT, see `LICENSE.md`.