Proper way to integrate WebRTC to Electron app?


#1

I’m trying to develop a peer-to-peer desktop app with Electron and WebRTC which transfers only JSON data betwen peers. I ran into many libraries such as PeerJs, node-crt and electron-webrtc but I’m not sure what’s the best way to properly integrate that, any ideas? thanks


#2

same question.
Who can show us a best-practice?


#3

The WebTorrent desktop app built on Electron and WebRTC might be one place to start looking.


#4

To get started using WebRTC in Electron, you don’t need to do much.

WebRTC is built into Chromium, so Electron has WebRTC automatically in all renderer processes. You can just start writing code that uses the WebRTC APIs (RTCPeerConnection, etc.)

I gave a talk about how we used Electron to build WebTorrent Desktop (https://webtorrent.io/desktop/), a WebRTC-powered torrent app that can connect to WebRTC browsers!

You can watch my talk from the Signal Conference

All the code for WebTorrent Desktop is open source on GitHub if you want to see how to use it.

If you’re looking for a library to make WebRTC easier to use, you can use any of the libraries that work in the browser: simple-peer, peerjs, etc., etc. I prefer simple-peer which is the one that I wrote for use in WebTorrent.


#5

@feross Can confirm WebRTC works in Electron, however it considers custom protocols to be insecure, like my-app://home, and so navigator.mediaDevices.getUserMedia fails. It works over the file protocol though. Do you know if there’s a workaround for this? I’ve tried passing webPreferences: { webSecurity: false } to BrowserWindow to no avail, and wouldn’t be ideal anyway.


#6

Ah I can answer my own question! Other visitors may find this useful:

Electron allows you to make a custom protocol secure like this:

protocol.registerStandardSchemes(['my-app'], { secure: true });

#7

Can we block webrtc in electron
If yes then how.
Issue is webrtc is leaking my original IP even though I am in proxy


#8

Hi Sir,
I am using WebRTC in Electron JS but onopen event is not working please let me know if you have any solution