https://github.com/shinyoshiaki/simple-datachannel
https://github.com/shinyoshiaki/simple-datachannel
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shinyoshiaki/simple-datachannel
- Owner: shinyoshiaki
- Created: 2018-07-16T08:19:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-28T08:26:42.000Z (almost 7 years ago)
- Last Synced: 2025-02-17T18:47:32.509Z (3 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-datachannel
#### Simple WebRTC data channels.
## features
- simple-peer like
- can make multi data-channels for a peer
## install```
npm install simple-datachannel
```## usage
For example manual signaling and send message each other through multi data-channels.
```js
import WebRTC from "simple-datachannel";
const peerOffer = new WebRTC();
const peerAnswer = new WebRTC();peerOffer.makeOffer({ disable_stun: true });
peerOffer.ev.on("signal", sdp => {
console.log("offer signal");
peerAnswer.makeAnswer(sdp, { disable_stun: true });
peerAnswer.ev.on("signal", sdp => {
peerOffer.setAnswer(sdp);
});
});peerOffer.ev.once("connect", () => {
console.log("offer connected");peerOffer.ev.on("data", data => console.log("ondata offer", data));
peerOffer.send("hello", "test");
peerOffer.send("test", "second");
});peerAnswer.ev.once("connect", () => {
console.log("answer connected");
peerAnswer.ev.on("data", data => console.log("ondata answer", data));peerAnswer.send("hi", "test");
peerAnswer.send("test!!", "third");
});
```## events
### `ev.on('signal', function (data) {})`
Fired when the peer wants to send signaling data to the remote peer.
### `peer.on('connect', function () {})`
Fired when the peer connection and data channel are ready to use.
### `peer.on('disconnect', function () {})`
Fired when the peer connection and data channel disconnected.
### `peer.on('data', function (data) {})`
Received a message from the remote peer (via the data channel).
`data` will be either a `String` or a `Buffer/Uint8Array`
## license
MIT. Copyright (c) [shinyoshiaki](https://twitter.com/ShinYoshiaki).