• Stars
    star
    316
  • Rank 132,587 (Top 3 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

βš› Use WebRTC in Node.js via a hidden Electron process

electron-webrtc

npm version Build Status Dependency Status

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. It may sometimes be useful to let Node.js programs use WebRTC, e.g. in webtorrent-hybrid. However, the modules for WebRTC in Node (node-webrtc and node-rtc-peer-connection) are either hard to install, broken, or incomplete.

As a hack, this module talks to an invisible Electron instance in the background (using electron-eval) to use Chromium's built-in WebRTC implementation.

Status

This module is compatible with simple-peer and passes its tests.

electron-webrtc is intended for use with RTCDataChannels, so the MediaStream API is not supported.

Usage

npm install electron-webrtc

// call exported function to create Electron process
var wrtc = require('electron-webrtc')()

// handle errors that may occur when trying to communicate with Electron
wrtc.on('error', function (err) { console.log(err) })

// uses the same API as the `wrtc` package
var pc = new wrtc.RTCPeerConnection(config)

// compatible with `simple-peer`
var peer = new SimplePeer({
  initiator: true,
  wrtc: wrtc
})

// listen for errors
wrtc.on('error', function (err, source) {
  console.error(err)
})

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

The object returned by this function has the same API as the 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 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:

apt-get install xvfb # Ubuntu/Debian
yum install xorg-x11-server-Xvfb # CentOS

Create the HEADLESS env variable:

export HEADLESS=true

Or if you want to do it programmatically, initialize a new instance and pass in headless as a key as demonstrated:

var wrtc = require('electron-webrtc')({ headless: true })

Now you may run your WebRTC code with electron-webrtc :)

Related Modules

More Repositories

1

gitbanner

🎈 Generates a git repo to show a cool banner on your Github profile
JavaScript
596
star
2

webcoin

πŸŒπŸ’° SPV Bitcoin client for Node.js and the browser
JavaScript
412
star
3

mercury

πŸ’± Decentralized cryptocurrency exchange
Java
159
star
4

peer-exchange

πŸ‘©β†”οΈπŸ‘¨ Decentralized peer discovery and signaling
JavaScript
152
star
5

node-hackrf

πŸ“» Control a HackRF device (e.g. Jawbreaker, HackRF One, or Rad1o) from Node.js
C
146
star
6

watt

πŸ’‘ Powerful control flow using ES6 generators
JavaScript
142
star
7

DCPU-16

πŸ’Ύ A javascript emulator for DCPU-16 (the computer system in Mojang's new game, 0x10c). Works in browsers and Node.
JavaScript
92
star
8

rust-bitcoin-script

Inline Bitcoin scripts in Rust
Rust
86
star
9

js-tendermint

A JS light client for Tendermint blockchains
JavaScript
72
star
10

coins

Cryptocurrency middleware for Lotion
JavaScript
64
star
11

redstone

πŸ”» A distributed, infinite-player Minecraft server that runs on Node.js.
CoffeeScript
61
star
12

hackrf-stream

A stream interface to receive and transmit on a HackRF radio from Node.js
JavaScript
54
star
13

electron-eval

Run code inside a hidden Electron window
JavaScript
52
star
14

0x10code

πŸ’» A website for sharing and developing code for DCPU16, from Mojang's game 0x10c.
JavaScript
49
star
15

bitcoin-net

🌐 Bitcoin networking that works in Node and the browser
JavaScript
23
star
16

tendermint-node

Run a Tendermint full node from Node.js
JavaScript
22
star
17

blockchain-spv

β—Ύβ—Ύβ—Ύ Stores blockchain headers and verifies transactions with SPV
JavaScript
22
star
18

if

Conditional branching for Node.js
JavaScript
22
star
19

muta

Mutate your objects without mutating your objects
JavaScript
19
star
20

bitcoin-protocol

πŸ”£ Bitcoin network protocol streams
JavaScript
14
star
21

bitcoin-merkle-proof

🌲 Build and verify Bitcoin Merkle proofs
JavaScript
12
star
22

htlc

Hashed TimeLock Contracts for Coins/Lotion
JavaScript
11
star
23

node-bitcoind

Spawn a Bitcoin Core full node from Node.js
JavaScript
11
star
24

old

Make the 'new' keyword optional for ES6 classes
JavaScript
11
star
25

blockchain-download

Download blockchain data from peers
JavaScript
11
star
26

filecoin-whitepaper

NOTICE: This is not associated with the Filecoin project made by Protocol Labs, and is not being actively worked on
HTML
10
star
27

js-hyperx

Atom syntax highlighting for hyperx
CoffeeScript
10
star
28

webcoin-bitcoin

Bitcoin parameters for Webcoin
JavaScript
8
star
29

modbox

Securely box untrusted JS modules, with CPU and memory limiting
JavaScript
8
star
30

proxmise

Proxied Promises - Create async getters for arbitrary object paths
JavaScript
8
star
31

blockchain-state

A writable stream for applications that consume blocks
JavaScript
6
star
32

coinmarketcat

CryptoKitties market data
JavaScript
6
star
33

bitcoin-inventory

Exchange transactions with peers
JavaScript
5
star
34

bitcoin-wallet

Simple HD wallet
JavaScript
5
star
35

node-sock

Simple networking for Node.js
CoffeeScript
4
star
36

deterministic-json

Deterministic JSON parse/stringify, with support for Buffers
JavaScript
4
star
37

event-cleanup

Wrap an EventEmitter for easy listener cleanup
JavaScript
4
star
38

bitcoin-filter

Bitcoin connection Bloom filtering (BIP37)
JavaScript
4
star
39

bitcoin-util

Utility functions for Bitcoin hashes and targets
JavaScript
4
star
40

on-object

Register many EventEmitter listeners at once using objects
JavaScript
4
star
41

js-crypto

JS equivalent of Tendermint's go-crypto package
JavaScript
4
star
42

staking

Proof-of-stake middleware for Lotion
JavaScript
4
star
43

airwave

An SDR application built on Electron
JavaScript
3
star
44

peerhub

Peer discovery and signalling for WebRTC P2P networks
JavaScript
3
star
45

fft-stream

A stream that transforms SDR I/Q samples into the frequency domain
JavaScript
2
star
46

species

My entry for the 24th Ludum Dare compo.
JavaScript
2
star
47

ipfs-code-viewer

View code in IPFS with automatic syntax highlighting
CSS
2
star
48

qwoptimizer

AI that learns to play QWOP using machine learning
JavaScript
2
star
49

outfitly

The social network for clothes. This app uses node.js, express, and MongoDB.
JavaScript
2
star
50

toronto

A lisp that compiles to JS
JavaScript
1
star
51

webcoin-bitcoin-testnet

Bitcoin testnet3 parameters for webcoin
JavaScript
1
star
52

dstate

Store changing state data as commits that can be rolled back
JavaScript
1
star
53

js-merkleeyes

Client for Tendermint's merkleeyes KV store
JavaScript
1
star
54

tenderdash

A dashboard for your Tendermint node
JavaScript
1
star
55

mongorest

Connect/Express middleware that lets you easily provide a REST API for your MongoDB data.
JavaScript
1
star
56

npmscan

Scans NPM for available package names
JavaScript
1
star
57

aptt-blog

The official blog of Aptt.
1
star
58

versionbits

Track Bitcoin versionbits deployments (BIP9)
JavaScript
1
star
59

number-script

Ordinal JavaScript
JavaScript
1
star
60

aoc-2019

Advent of Code 2019
Rust
1
star
61

mercuryex.com

The website for Mercury
HTML
1
star
62

versionbits-web

A web viewer for Bitcoin versionbits deployments
JavaScript
1
star
63

webcoin-bridge

πŸŒ‰ Bridge connections from the Websocket/WebRTC network to the TCP network
JavaScript
1
star