electron-webrtc

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

  • 所有者: mappum/electron-webrtc
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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 :)

主要指標

概覽
名稱與所有者mappum/electron-webrtc
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證
所有者活动
創建於2016-01-19 07:32:12
推送於2018-02-20 04:43:35
最后一次提交2017-01-16 20:00:52
發布數20
最新版本名稱v0.3.0 (發布於 2017-01-16 20:00:52)
第一版名稱v0.0.1 (發布於 2016-01-11 20:04:35)
用户参与
星數318
關注者數16
派生數47
提交數93
已啟用問題?
問題數20
打開的問題數11
拉請求數10
打開的拉請求數4
關閉的拉請求數95
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?