Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC on isolated LAN without ice/stun/turn server

Tags:

webrtc

On an isolated LAN, is there any way that a WebRTC connection can be made simply with the IP addresses assigned by the DHCP server?

I understand that I can accomplish this with Node.js and Socket.io - but I was really hoping to avoid setting up that kind of server with my limited skill set. I'm a science teacher who dabbles in programming, so feel free to keep it simple. Thank you!

UPDATE

Alex, you are correct that I can avoid using a STUN server if all of the computers are on the same local network. Although I had to bite the bullet and install Node.js on my laptop, it was really wasn't complicated. I then tried a whole bunch of 'working examples' that didn't work for me, until I found this one and his GitHub files.

After running the server script in Node, I had a DataChannel connection between two browser windows on the same machine, but not between different computers. I edited the .html files to point to my local server IP address instead of localhost and I could then connect with multiple computers. Then came the real test - could I use this without an internet connection? I found the line that specified using Google's STUN servers and changed it from

var config = {"iceServers":[{"url":"stun:stun.l.google.com:19302"}]};

to just

var config = {"iceServers":[]};

It worked. :-)

like image 824
brainBanter Avatar asked Jun 09 '15 20:06

brainBanter


2 Answers

Omit the iceServers list:

const pc = new RTCPeerConnection(); 

Either omit the iceServers list from the RTCPeerConnection constructor, or make it the empty list [].

From RTCPeerConnection docs:

iceServers | optional

An array of RTCIceServer objects, each describing one server which may be used by the ICE agent; these are typically STUN and/or TURN servers. If this isn't specified, the connection attempt will be made with no STUN or TURN server available, which limits the connection to local peers.

webrtc/samples demo

The WebRTC project has a Trickle ICE sample that you can use to see how changes in iceServers effect the candidate address that are gathered. The specific sample you want to look at is.

  1. Run it with defaults set by pressing the Gather candidates button at the bottom of the page. This will return a list of addresses which include the address of the public side of your NAT.

    Default ICE Servers

  2. Now remove all the ICE servers from the list and press Gather candidates again, this time you should only see local network addresses.

    No ICE Servers

Notice that, on my network, the 2 public IPv4 addresses (beginning with 98.) only appear when I'm using the default ICE servers. When I use an empty ICE server list, my public IPv4 addresses are no longer discovered. My IPv6 addresses, on the other hand, are the same in both tests because they aren't subject to NAT.

Here is a link to the source code that sets up iceServers and PeerConnection.

like image 109
Doug Richardson Avatar answered Sep 19 '22 02:09

Doug Richardson


Alex, you are correct that I can avoid using a STUN server if all of the computers are on the same local network. Although I had to bite the bullet and install Node.js on my laptop, it was really wasn't complicated. I then tried a whole bunch of 'working examples' that didn't work for me, until I found this one and his GitHub files.

After running the server script in Node, I had a DataChannel connection between two browser windows on the same machine, but not between different computers. I edited the .html files to point to my local server IP address instead of localhost and I could then connect with multiple computers. Then came the real test - could I use this without an internet connection? I found the line that specified using Google's STUN servers and changed it from

var config = {"iceServers":[{"url":"stun:stun.l.google.com:19302"}]};

to just

var config = {"iceServers":[]};

like image 20
brainBanter Avatar answered Sep 18 '22 02:09

brainBanter