From e27cb2ac4bcc80f45c9e64103e67695414d72ef0 Mon Sep 17 00:00:00 2001 From: Taylor Sarrafian Date: Thu, 5 Jul 2018 13:37:00 -0700 Subject: [PATCH 1/2] Replaced `electron-webrtc` with `wrtc`. `wrtc@0.1.6` is now working on Node.js. --- README.md | 35 ----------------------------------- bin/prepareHeadless.sh | 32 -------------------------------- lib/global.js | 22 ++-------------------- package.json | 4 ++-- 4 files changed, 4 insertions(+), 89 deletions(-) delete mode 100755 bin/prepareHeadless.sh diff --git a/README.md b/README.md index 7bfcf27..f7efedb 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,6 @@ In node.js, the `webtorrent` package only connects to normal TCP/UDP peers, not WebRTC peers. If you want to connect to all types of peers, including WebRTC peers, from node.js, you need to use this package (`webtorrent-hybrid`). -Previous versions (0.x) of this package used [wrtc](https://github.com/js-platform/node-webrtc), a WebRTC implementation via native extensions, the current one is based on [electron-webrtc](https://github.com/mappum/electron-webrtc) (which in turn uses [electron-prebuilt](https://github.com/electron-userland/electron-prebuilt)) for better compatibility. It creates a hidden Electron process (which is based on Chromium, so WebRTC support is great!) and communicates with that process to enable WebRTC in Node.js. This adds a lot of overhead, so we are looking forward to using a pure JavaScript implementation, like perhaps [Node-RTCPeerConnection](https://github.com/nickdesaulniers/node-rtc-peer-connection) when it's ready. - -To run this package on a headless server execute [the provided script](bin/prepareHeadless.sh) or follow [these instructions](https://github.com/mappum/electron-webrtc#running-on-a-headless-server). - ## Install To install WebTorrent: @@ -31,37 +27,6 @@ To install a `webtorrent-hybrid` command line program, run: npm install webtorrent-hybrid -g ``` -### OS X - -On OS X, this should Just Work™. - -### Linux - -The current version of `webtorrent-hybrid` requires a screen, since the headless Electron -instance expects one. If you're running in a screenless environment (like on a server), -you must use a virtual screen such as `xvfb`. You must install it before using -`webtorrent-hybrid`. - -#### For Debian / Ubuntu: - -```bash -sudo apt-get install xvfb -``` - -If you get an error about a missing .so file ("error while loading shared libraries"), use the search at the bottom of [packages.debian.org](https://packages.debian.org) to find out which packages in your release provide a given file. - -On server editions, the following additional packages should be installed since Electron depends on them: - -```bash -sudo apt-get install libgtk2.0-0 libxtst-dev libxss-dev libgconf2-dev libnss3 libasound2-dev -``` - -#### For CentOS / RHEL: - -```bash -sudo yum install xorg-x11-server-Xvfb -``` - ## Usage `webtorrent-hybrid` has the same command line interface (CLI) and module API as diff --git a/bin/prepareHeadless.sh b/bin/prepareHeadless.sh deleted file mode 100755 index 69d3b31..0000000 --- a/bin/prepareHeadless.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# Detect running X server, load Xvfb on headless systems and starts a virtual buffer - -if [ -z $(pidof X) ]; then - - if [ ! $(which "Xvfb") ]; then - # TODO: - # - check alternative package support - if VERB="$( which apt-get )" 2> /dev/null; then - sudo apt-get install xvfb - elif VERB="$( which yum )" 2> /dev/null; then - sudo yum install xorg-x11-server-Xvfb - else - echo "Could not determine your package manager. Please, check the instructions to install Xvfb in your enviroment" - exit 2 - fi - fi - - #Check if Xvfb was installed - if [ $(which "Xvfb") ]; then - running=$(pidof Xvfb) - if [ -z "$running" ]; then - kill running - fi - - export DISPLAY="0:99" - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & - echo "Xvfb runing" - else - echo "Xvfb is not installed in your system" - fi -fi diff --git a/lib/global.js b/lib/global.js index 082f890..1f6d163 100644 --- a/lib/global.js +++ b/lib/global.js @@ -1,5 +1,4 @@ var createTorrent = require('create-torrent') -var ElectronWebRTC = require('electron-webrtc') global.WEBTORRENT_ANNOUNCE = createTorrent.announceList .map(function (arr) { @@ -9,23 +8,6 @@ global.WEBTORRENT_ANNOUNCE = createTorrent.announceList return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0 }) -global.WRTC = function () { - var wrtc = ElectronWebRTC() +var wrtc = require('wrtc') - process.on('SIGINT', ensureCloseElectron) - process.on('SIGTERM', ensureCloseElectron) - - wrtc.on('error', function (err, source) { - if (err.message !== 'Daemon already closed') { - console.error(err, source) - } - }) - - function ensureCloseElectron () { - process.removeListener('SIGINT', ensureCloseElectron) - process.removeListener('SIGTERM', ensureCloseElectron) - wrtc.close() - } - - return wrtc -} +global.WRTC = wrtc diff --git a/package.json b/package.json index 74b403c..a687f32 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ }, "dependencies": { "create-torrent": "^3.23.1", - "electron-webrtc": "^0.3.0", "webtorrent": "0.x", - "webtorrent-cli": "^1.0.1" + "webtorrent-cli": "^1.0.1", + "wrtc": ">=0.1.6" }, "devDependencies": { "standard": "*" From d2437addec03b12a1eb7682beb8912ee2b8fbb67 Mon Sep 17 00:00:00 2001 From: Taylor Sarrafian Date: Fri, 26 Oct 2018 15:04:25 -0700 Subject: [PATCH 2/2] Upgraded dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a687f32..5088d6c 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "url": "https://github.com/webtorrent/webtorrent-hybrid/issues" }, "dependencies": { - "create-torrent": "^3.23.1", - "webtorrent": "0.x", - "webtorrent-cli": "^1.0.1", - "wrtc": ">=0.1.6" + "create-torrent": "^3.33.0", + "webtorrent": "^0.102.4", + "webtorrent-cli": "^1.12.3", + "wrtc": "^0.2.1" }, "devDependencies": { "standard": "*"