npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ca9io/electron-webrtc-relay

v0.2.0

Published

Use WebRTC in Electron Main Process, compatible with WebTorrent

Downloads

13

Readme

Use WebRTC in the Main Process in your Electron project.

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.

This module started as a fork of electron-webrtc but removed the broken, unsafe and old electron dependencies of electron-eval and implemented some pending pull requests.

Status

This module is compatible with simple-peer and passes its tests [compatible but tests need an update ;)].

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

Usage

npm install @ca9io/electron-webrtc-relay

// call exported function to create Electron process
var wrtc = require("@ca9io/electron-webrtc-relay")({
  debug: false, //(optional) defaults to false
  preload: string, //(optional) absolute path to your preload script. Using secure context if active (TODO: add example implementation)
  webrtcPolicy:  "default" | "default_public_interface_only" | "default_public_and_private_interfaces" | "disable_non_proxied_udp" // (optional) default: "default". Read More: https://www.electronjs.org/docs/latest/api/web-contents#contentssetwebrtciphandlingpolicypolicy
});

// IMPORTANT: WHEN YOUR APP IS LOADED CALL
wrtc.init()

// 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);
});

Configuration

  • debug - Enables output log and rendered Electron Window with devtools enabled
  • preload - You can link your custom preload script. Since Webpack will just remove our script we can not do that. You have to add the ipcRenderer Module to the window object in your script.
  • webrtcPolicy - Define how to handle WebRTC within your project. If default is active, local connections in your network are not possible (please verify this)
  • maxWindows - Chromium only allows for a certain amount of WebRTC connections per Window. With maxWindows you can allow the creation of more than one window to improve performance in performance heavy applications

Methods

var wrtc = require('@ca9io/electron-webrtc-relay')([opts])

Calling the function exported by this module will create a new hidden Electron Window.

An optional opts object may contain specific options.

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.init()

Tells the relay to start a Browser window. It is important that you call this once.

wrtc.close()

Frees some resources.

Events

- error

Emitted by RTCPeerConnection or RTCDataChannel when daemon.eval() evaluates code that throws an internal error.

Related Modules