Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oakfang/coven
A pain-free way to handle a mesh of peers via WebRTC
https://github.com/oakfang/coven
Last synced: 3 months ago
JSON representation
A pain-free way to handle a mesh of peers via WebRTC
- Host: GitHub
- URL: https://github.com/oakfang/coven
- Owner: oakfang
- License: mit
- Created: 2017-01-21T10:37:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-09-01T04:01:28.000Z (over 3 years ago)
- Last Synced: 2024-10-05T06:59:43.789Z (4 months ago)
- Language: JavaScript
- Size: 283 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# coven
A pain-free way to handle a mesh of peers via WebRTC
## Usage (node client)
```js
const wrtc = require('wrtc');
const ws = require('ws');
const Coven = require('coven');const coven = new Coven({ ws, wrtc, signaling: 'wss://coven-broker.now.sh' });
coven.once('open', () => console.log('Connected to signaling server'));
coven.on('connection', peerId => console.log(`Connected to peer ${peerId}`));
coven.on('disconnection', peerId =>
console.log(`Disconnected from peer ${peerId}`)
);
coven.on('message', ({ peerId, message }) => {
coven.sendTo(peerId, message);
});
//...
const [peerId] = coven.activePeers;
coven.sendTo(peerId, 'fsdfsd');
```## Usage (browser client)
```js
import Coven from 'coven';const coven = new Coven({ signaling: 'wss://coven-broker.now.sh' });
coven.once('open', () => console.log('Connected to signaling server'));
coven.on('connection', peerId => console.log(`Connected to peer ${peerId}`));
coven.on('disconnection', peerId =>
console.log(`Disconnected from peer ${peerId}`)
);
coven.on('message', ({ peerId, message }) => {
coven.sendTo(peerId, message);
});
//...
const [peerId] = coven.activePeers;
coven.sendTo(peerId, 'fsdfsd');
```## Usage (server)
```js
const createSignalingBroker = require('coven/server');
const DEFAULT_PORT = 4000;
const PORT = +(process.env.PORT || DEFAULT_PORT);createSignalingBroker({
port: PORT,
onMessage({ room, type, origin, target }) {
console.log(`[${room}::${type}] ${origin} -> ${target || ''}`);
},
});
```