Skip to content

saltyrtc/saltyrtc-task-relayed-data-js

Repository files navigation

SaltyRTC Relayed Data Task for JavaScript

CircleCI npm Version npm Downloads License Join our chat on Gitter

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".)

Installing

Via npm

You can install this library (and its peer dependencies) via npm:

npm install --save @saltyrtc/task-relayed-data @saltyrtc/client tweetnacl msgpack-lite

Usage

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.

Testing

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

Security

Responsible Disclosure / Reporting Security Issues

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

License

MIT, see LICENSE.md.

About

JavaScript implementation of the Relayed Data task.

Resources

License

Stars

Watchers

Forks

Packages

No packages published