Serverless WebRTC, continued —
Around a year ago, in WebRTC without a signaling server, I presented an simple app that can start a chat session with another browser without using a local web server (i.e. you just browse to file:///
), and without using a signaling server (instead of both going to the same web page to share “offers”, you share them manually, perhaps via IM).
It’s been a busy year for WebRTC! When I released serverless-webrtc, Chrome didn’t support datachannels yet, so the code only worked on Firefox. Now it works in stable releases of both browsers, and is interoperable between the two, for both reliable (TCP-like) and unreliable (UDP-like) transfers. And I’ve just added Node to the mix (so you can do Node—Node / Node—Chrome / Node—Firefox) as well, with the first release of the serverless-webrtc NPM package. Here’s how to try it out:
$ git clone git://github.com/cjb/serverless-webrtc $ cd serverless-webrtc $ npm install $ firefox serverless-webrtc.html & $ node serverless-webrtc.js <paste firefox's offer into node, hit return> <paste node's answer into firefox, click ok> <you're connected!>
And here’s a screenshot of what that looks like:
I’m able to do this thanks to the wrtc NPM module, which binds the WebRTC Native Code Package (written in C++) to Node, and then exposes a JS API on top of it that looks like the browser’s WebRTC JS API. It’s really impressive work, and the maintainers have been super-friendly.
Next I’d like to unwrap the JS from the node client and make a pure C++ version, because the Tor developers would like “to have two C++ programs that are capable of chatting with each other, after being given an offer and answer manually”, to help investigate WebRTC as a method of relaying Tor traffic.
Finally, a link that isn’t related to this project but is too cool not to mention – Feross Aboukhadijeh has a WebTorrent project to port a full BitTorrent client to the browser, also using WebRTC in a serverless way (with trackerless torrents, and peer-to-peer node introductions).
What would it mean if the next Wikipedia or GitHub (see Yurii Rashkovskii’s GitChain project!) didn’t have to spend tens of millions of dollars each year for servers and bandwidth, and could rely on peer-to-peer interaction? I’d love to find out, and I have a feeling WebRTC is going to show us.
Pingback: Survey results: and the WebRTC developers say... | webrtcHacks
Hi, Chris!
Thanks for sharing!
I checked out the example and it sounds really inspiring that even local server is unnecessary for WebSocket connection.
But I tried the examples on Chrome for Android and both sides are always loading… Any guess how is this happening? My Android version is 4.1.2 and Chrome for Android is 36.0.1985.135.
Hi Wenli — I actually hadn’t tried out Chrome on Android so I’m not sure why it’s failing. Let me know if you figure anything out, thanks!
Hi Chris,
Thank you for your amazing work!
I am trying to build a LAN webrtc instant message application. It seems to me it can only do 1 on 1 connection cause there is no option to add new client after connecting with the first one? Is it possible to do a group chat?
Thanks!
I love this! I am new to WebRTC and have been looking for a solution without a signalling server. Your code is a gawd send.
I do have a couple of questions:
1. I would like to jump on Xiang Li’s request for how to do a 1-to-many or group chat type communications.
2. I am using Firefox on my desktop and your application works beautifully. I would like to be able to communicate to my Android, which is using Opera Mobile for Android v29… but cannot get this to work. Are there any tricks/tips for using your application with Opera?
I just made similar demo also as an Android app. It’s compatibile with your demo.
Check it out there:
https://github.com/wojta/serverless-webrtc-android
Oh that’s so cool! I’ll put a link to it in the README. Nice job!
This is really cool but I’m wondering if you have any idea how you can have a fixed offer?
So for example if I wanted to set up two clients to communicate only once, and store their offers, so that each time they came on-line they could connect without doing the “handshake”.
No, it’s not possible. Part of generating the offer involves doing a “holepunch” in the NAT so that there’s actually an open port on the client’s router that will get to them, and as I understand it that holepunch will expire (when the client goes offline or even sooner).
Ah OK, that makes sense. Thanks for getting back to me!