Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a node.js application a PEER with WebRTC

So, I have a web app that generates large buffers of color information that I want to send to a node application running on another machine in my local network. Web Sockets doesn't seem to be fast enough for me. I was looking to use UDP and it seems WebRTC is the only way to do that from a browser. The caveat, it seems, is WebRTC is only PEER to PEER (browser to browser). I figured, I could use node webkit to emulate being my other "PEER". In my node app I could handle the "signaling" and have it set itself up in a RTCPeerConnection to my web app. Therefore, I could send my data from my web app to my node app (local network). For some context, I have one computer running native software to drive a light fixture and I want to use a web app to control the lights.

To boil the question down, how can I make a RTCPeerConnection from a browser to a node webkit app?

Any help would greatly appreciated.

Thank you!

-Jake

like image 885
Jake Lampack Avatar asked Apr 01 '16 01:04

Jake Lampack


2 Answers

Update 2019

Currently, the best and easiest way to solve this problem is to use webrtc module. Check samples for inspiration. This module does what you were looking for, implemented with N-API and using Canvas module to compose new video from the client stream. Hopefully this will help those who face this problem in the future.

like image 118
Michael Zelensky Avatar answered Sep 29 '22 12:09

Michael Zelensky


Node-RTCPeerConnection is an attempt (current WIP) to create a spec compliant implementation of RTCPeerConnection for Node.js entirely in JavaScript with no native C or C++ code. This enables browser-peers to speak to non-browser (Node.js) peers.

But you can not use it for production yet.


Then we also have wrtc (node-webrtc) that provides a native module for NodeJS that supports a subset of standards-compliant WebRTC features. Specifically, the PeerConnection and DataChannel APIs.

Too many people are having problems with wrtc. Since it has to download lots of source and build it only to find out that it fails after a long while on certain platforms. Unfortunately it doesn't come with any prebuilt packages described in this issue


You can use either the google implementation of webrtc or a more recent implementation (by Ericsson) called openWebrtc. The developers of openWebRTC are very proud of running their implementation on various pieces of hardware like raspberry pi and iOS devices.


The one that worked best for me was electron-webrtc (which in turn uses 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.

It is intended for use with RTCDataChannels, so the MediaStream API is not supported.


Other resources:
https://github.com/webrtcftw/goals/issues/1

like image 28
Endless Avatar answered Sep 29 '22 13:09

Endless