This is a SaltyRTC Relayed Data task implementation for JavaScript (ES5 / ES2015), written in TypeScript.
⚠️ Note: The SaltyRTC client libraries are in maintenance mode. They will still receive bugfixes and regular maintenance, but if you want to start using these libraries, be prepared that you will need to take over maintenance at some point in time. (If you are interested in maintaining the libraries, please let us know, our e-mails are in the README, section "Security".)
You can install this library (and its peer dependencies) via npm
:
npm install --save @saltyrtc/task-relayed-data @saltyrtc/client tweetnacl msgpack-lite
Create a new task instance:
const task = new RelayedDataTask();
(If you want to enable debug console messages, you can pass true
to the constructor:)
const task = new RelayedDataTask(true);
Once the connection is established (when the SaltyRTC
instance raises the
state-change:task
event), you can send messages using the sendMessage
method:
task.sendMessage("hello");
task.sendMessage({"type": "custom", "value": "You can also send objects"});
When a new message arrives from the peer, an event is emitted. You can register
and deregister event handlers with the on
, once
and off
methods:
task.on('data', (ev) => {
console.log('New data message arrived:', ev.data);
});
The following events are available:
data
: A new message from the peer was received.
To run tests:
npm run build_tests
Then open tests/testsuite.html
in your browser.
To run linting checks:
npm run lint
You can also install a pre-push hook to do the linting:
echo -e '#!/bin/sh\nnpm run lint' > .git/hooks/pre-push
chmod +x .git/hooks/pre-push
Please report security issues directly to one or both of the following contacts:
- Danilo Bargen
- Email: mail@dbrgn.ch
- Threema: EBEP4UCA
- GPG: EA456E8BAF0109429583EED83578F667F2F3A5FA
- Lennart Grahl
- Email: lennart.grahl@gmail.com
- Threema: MSFVEW6C
- GPG: 3FDB14868A2B36D638F3C495F98FBED10482ABA6
MIT, see LICENSE.md
.