Search code examples
javascriptwebrtc

Is WebRTC without createOffer/Answer possible on a local network?


Is it possible to establish a WebRTC connection between two browsers on a local area network without calling createOffer/Answer and instead by manually creating local and remote descriptions?

The browsers are not behind NAT with respect to each other and they have signaled their IP addresses somehow (say via a local HTTP server).

Would it be possible to do something in the spirit of:

const myIp = '192.168.0.1'; 
const peerIp = '192.168.0.2';

const c = new RTCPeerConnection();
c.setLocalDescription(MAGIC_createLocalDescriptionFor(myIp));
c.setRemoteDescription(MAGIC_createRemoteDescriptionFor(peerIp));

Solution

  • Yes! If you are using Chrome. Check out offline-browser-communication

    You have three points of state you need to deal with.

    • IP/Port. You can setup your network in a way that this is stable. Or attempt to do some guessing?

    • ufrag/pwd. You can set this via SetLocalDescription so you can control these.

    • DTLS Certificate. Use GenerateCertificate this means you will only have to signal it once.