Socket
Socket
Sign inDemoInstall

@constl/electron-webrtc-relay

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@constl/electron-webrtc-relay

Use WebRTC in Electron Main Process, compatible with WebTorrent


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Electron Webrtc Relay

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.

Keywords

FAQs

Package last updated on 20 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc