# electron-webrtc-webtorrent

> Use WebRTC in Node.js via a hidden Electron process

Latest version **0.3.7** (published 2023-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install electron-webrtc-webtorrent
pnpm add electron-webrtc-webtorrent
yarn add electron-webrtc-webtorrent
bun add electron-webrtc-webtorrent
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.7 |
| Published | 2023-06-22 |
| First published | 2023-06-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 5 |
| Unpacked size | 33.5 KB |
| Known vulnerabilities | 0 (+61 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Drakonkat |
| Maintainers | drakonkat |
| Keywords | webrtc, electron, webtorrent |

## Links

- npm: https://www.npmjs.com/package/electron-webrtc-webtorrent
- Repository: https://github.com/drakonkat/electron-webrtc
- Homepage: https://github.com/drakonkat/electron-webrtc#readme
- Issues: https://github.com/drakonkat/electron-webrtc/issues
- npm.io page: https://npm.io/package/electron-webrtc-webtorrent

## Dependencies (5)

- [hat](https://npm.io/package/hat.md) ^0.0.3
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [ndjson](https://npm.io/package/ndjson.md) ^1.5.0
- [electron](https://npm.io/package/electron.md) ^1.6.11
- [get-browser-rtc](https://npm.io/package/get-browser-rtc.md) ^1.1.0

## Recent versions

- 0.3.7 (latest) — 2023-06-22
- 0.3.5 — 2023-06-21
- 0.3.4 — 2023-06-14
- 0.3.3 — 2023-06-13
- 0.3.2 — 2023-06-12
- 0.3.1 — 2023-06-12

## README

# electron-webrtc-webtorrent

[![npm version](https://img.shields.io/npm/v/electron-webrtc.svg)](https://www.npmjs.com/package/electron-webrtc)
## Status - unstable 

### FORKED from the original to update the RTCPeerConnections and make it work with webtorrent 

#### TODO LIST
- Upgrade electron and update all the method relative to WRTC
- Improve stability
- Test on linux, windows and mac

Use WebRTC in Node.js via a hidden Electron process

WebRTC is a powerful web API that lets browsers make peer-to-peer connections, and has already been
deployed in [many popular browsers](http://caniuse.com/#feat=rtcpeerconnection). It may sometimes be
useful to let Node.js programs use WebRTC, e.g. in [`webtorrent-hybrid`](https://github.com/feross/webtorrent-hybrid). However, the modules for WebRTC in Node ([`node-webrtc`](https://github.com/js-platform/node-webrtc) and [`node-rtc-peer-connection`](https://github.com/nickdesaulniers/node-rtc-peer-connection)) are either hard to install, broken, or incomplete.

## Status

This module is compatible with [`simple-peer`](https://github.com/feross/simple-peer) and passes its tests.

`electron-webrtc` is intended for use with RTCDataChannels, so the MediaStream API is not supported.

## Usage

`npm i electron-webrtc-webtorrent`

```js
// call exported function to create Electron process
wrtc = require('electron-webrtc-webtorrent')({electron: path.resolve(path.join(__dirname, "../node_modules/electron-webrtc-webtorrent/node_modules/electron/dist/electron.exe"))});
global.WRTC = wrtc
```

### Methods

#### `var wrtc = require('electron-webrtc')([opts])`

Calling the function exported by this module will create a new hidden Electron process. It is recommended to only create one, since Electron uses a lot of resources.

An optional `opts` object may contain specific options (including headless mode). See [`electron-eval`](https://github.com/mappum/electron-eval#var-daemon--electronevalopts)

The object returned by this function has the same API as the [`node-webrtc`](https://github.com/js-platform/node-webrtc) package.

Any errors that occur when communicating with the Electron daemon will be emitted by the `wrtc` object (`wrtc.on('error', ...)`).

#### `wrtc.close()`

Closes the Electron process and releases its resources. You may not need to do this since the Electron process will close automatically after the Node process terminates.

### Properties

#### `wrtc.electronDaemon`

A handle to the [`electron-eval`](https://github.com/mappum/electron-eval) daemon that this module uses to talk to the Electron process.

### Events

#### - `error`
Emitted by `RTCPeerConnection` or `RTCDataChannel` when `daemon.eval()` evaluates code that throws an internal error.

### Running on a headless server

Chromium normally won't run on a headless server since it expects a screen that it can render to. So to work around this, we can use `Xvfb`, a utility that creates a framebuffer that Chromium can use as a virtual screen.

First, install `Xvfb`:
```sh
apt-get install xvfb # Ubuntu/Debian
yum install xorg-x11-server-Xvfb # CentOS
```

Create the `HEADLESS` env variable:
```sh
export HEADLESS=true
```

Or if you want to do it programmatically, initialize a new instance and pass in `headless` as a key as demonstrated:
```js
var wrtc = require('electron-webrtc')({ headless: true })
```

Now you may run your WebRTC code with `electron-webrtc-webtorrent` :)

## Related Modules

- [`node-webrtc`](https://github.com/js-platform/node-webrtc)
- [`node-rtc-peer-connection`](https://github.com/nickdesaulniers/node-rtc-peer-connection)
- [`electron-eval`](https://github.com/mappum/electron-eval)
- [`electron-webrtc`](https://github.com/mappum/electron-webrtc)

---
_Source: https://npm.io/package/electron-webrtc-webtorrent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
