Hacker News new | past | comments | ask | show | jobs | submit login
WebRTC Samples (webrtc.github.io)
176 points by simonpure on Sept 14, 2020 | hide | past | favorite | 42 comments



The term 'WebRTC' is overloaded, it can mean the protocol or the API. These samples only cover in the browser. This repo is also kind of dead https://github.com/webrtc/samples/issues/1350

If you are interested in WebRTC out of the browser there are lots of implementations and servers! I am also working on a book 'WebRTC for the Curious'[0] that tries to explain the protocol and the history behind it.

[0] https://webrtcforthecurious.com/


Isn't the protocol more or less "just" SDP, DTLS-SRTP and ICE, or in other words a normal SIP stack without the SIP part?

Or is the WebRTC subset/combination of these standards sufficiently different better described as its own protocol?


Yea pretty much! The only other thing is SCTP.

One nice thing is that the protocol is less flexible. The clients are expected to support NACK, Congestion Control and some other stuff.

I haven't done SIP stuff in 10 years. I just remember you had lots of variety between who you interacted with. Maybe this has gotten better!



Thanks for providing this valuable resource.

Out of curiosity: It seems like the communication protocol that's used is RTP and RTCP. And it seems that these work quite well for video and audio streaming. However what if I want to do real time streaming of a custom binary protocol? Like, say, accelerometer data from a robot or similar.

Would the best bet be to attempt to make the protocol RTP and RTCP conformant or would it be possible to make a custom fork of WebRTC which supports custom protocols at the communication layer?


WebRTC has "DataChannels" which you can use for arbitrary data.


This blog post from 2018 from Discord indicated that the browser implementation of WebRTC wasn't as good: https://blog.discordapp.com/how-discord-handles-two-and-half...

Is this still the case? Would you still hypothetically see better audio performance of something like Discord in a standalone app?


One big issues was poor crypto performance. I managed to convince Google to turn AES-GCM on with SRTP! https://bugs.chromium.org/p/chromium/issues/detail?id=713701...

I am sure there are other issues as well. The WebRTC implementation in Chromium is controlled by Google (they have all the commit bits). If they don't agree with your change it isn't going to land. It's a tough position to be in for other businesses and Open Source projects even.


Still pretty bad. Firefox can't freely select audio devices per stream. Chrome has some kind of unbeatable adaptation that makes latency fluctuate.


Do you have more details on the Firefox problem? I have a WebRTC project that is currently in standby (priorities changed) and one issue that I have not been able to troubleshoot was an inability to send audio from Firefox while it somehow worked on Chrome.


It works fine in Firefox (send and receive) as long as you don't need to play on multiple output devices. Currently you can enable a feature flag, use enumerateDevices() and play audio files on specific devices, but you can't hook up WebRTC streams to the devices.

enumerateDevices() should enumerate audio output devices (feature behind pref): https://bugzilla.mozilla.org/show_bug.cgi?id=1152401

Enable by default setSinkId pref: https://bugzilla.mozilla.org/show_bug.cgi?id=1498512

Alex Chronopoulos: "We keep it off because it does not work for everything. It works when we playback a file but not for webaudio or WebRTC. We want to add those too and we keep it off till then."


Thanks for your answer, I only have two devices connected so my problem must be caused by an unrelated mistake. I'll find out eventually :).


Share GitHub repo with latest code, love to play around


The project I work on is https://github.com/pion/webrtc. https://github.com/pion/awesome-pion is a list of interesting projects that use it, my favorite thing to share :)

For other WebRTC implementations check out.

* https://github.com/aiortc/aiortc

* https://github.com/shinyoshiaki/werift-webrtc

* https://github.com/rawrtc/rawrtc

* https://gstreamer.freedesktop.org/documentation/webrtc/index...

There is also https://github.com/node-webrtc/node-webrtc this takes Google's WebRTC implementation (used in Chromium) and throws a node.js API on top of it!


For those in the know, if I'm running something on my own that may only at any given moment see in the few hundreds of people using it, what's the best approach in terms of server-side infrastructure to support WebRTC apps? Is there any SaaS offering that has a meaningful product?


We use Janus Gateway, and it works really well:

https://github.com/meetecho/janus-gateway

We have upwards of 100 simultaneous users on it every day, and at the moment it seems to be 100% reliable.


Mizu gateway also does the job:

https://www.mizu-voip.com/Software/WebRTCtoSIP.aspx

It has a nice config wizard and built-in STUN and TURN server.


A few hundred people should be fine! For fun I made https://github.com/pion/rtsp-bench and was doing 14k people before I saw my first hiccup.

You just need watch CPU Usage and Network attributes (loss, congestion etc...) Getting this right will take a little bit of WebRTC knowledge. Happy to answer any specific questions :)

There are also lots of hosted options as well! Real world WebRTC has a few different parts though, https://bloggeek.me/webrtc-server/ is a good intro I think.


Thank you for these resources -- I'll check them out!


Check out Vonage Video: https://www.vonage.com/communications-apis/video/ Their tech is based on a company they acquired, Tokbox. I used Tokbox’s services for large-scale real-time streaming; but their pricing is friendly for small-scale usage too. Solid service, with all the helpful extras you’ll likely need (recording videos, handling differences in browsers, etc.).


Depends a lot on what kind of app it is. There are orders of magnitude differences in requirements between apps that use data channels for relatively meager amounts of data (eg multiplayer games), or audio, or video, or video with server side realtime per participant transcoding etc.


Using Xirsys TURN servers happily (be careful some of their "getting started" examples are wrong). I tried to use Twilio, but failed, they did not recognize my mobile phone number. Even after begging 3 times to become their customer and paying for it, I could not succeed.


I had the same issue with Twilio, they couldn't send anything to my number because of the prefix. After many emails, they finally got it working - then two weeks later it was broken again and I simply gave up.


We have been using Twilio and we're sending them hundreds of dollars a month. I'm about to drop it because of their 2FA requirement. Either they accept customers that know how to manage passwords or they don't. I don't give my phone number to ANYONE any more.


You can use PubNub for reliable signaling and XirSys for TURN. I made an OS example of this a while back. https://github.com/ajb413/pubnub-js-webrtc


I've been using the Twilio Video product and have been pretty happy with it. They do the orchestration on the server so that you can have all of the users connect via WebRTC. It's very easy to use.


There is also https://janus.conf.meetecho.com/screensharingtest.html just to have more resources to check


If you want to build a multiple session (multiple people) connecting to a website with their camera and audio on, would you use WebRTC or WebSocket + getUserMedia ? Why ?


WebRTC is going to be better for most users (IMO). WebRTC provides congestion control so video stays real-time. It works pretty well with very little effort.

Some companies have decided to roll their own, https://webrtchacks.com/zoom-avoids-using-webrtc/ is a cool read.


how about if you want to integrate real time chat, can webRTC data channel accomplish that or one needs WebSockets for that?


Go do your own homework


suggest you read this (on the frontpage today): https://nedbatchelder.com//blog/202009/how_to_be_helpful_onl...


One to one video/audio is fine and securely end-to-end encrypted with vanilla WebRTC.

But for group conversation this won't scale because with p2p (mesh network) WebRTC, each client has to encode and decode for all users (which might be too much processing to do for the client).

For that reason many group video conf apps use a centralized router when there are several people.

Privacy then becomes an issue, and all group video conf such as Zoom, Skype, etc. are basically unencrypted (not end-to-end) and they can see & log everything (your face, your voice, chat, files exchanged, etc.) because the centralised router routes non-encrypted streams.

Jitsi is going to be an exception by adding a layer of encryption using insertable streams (https://jitsi.org/blog/e2ee/).

So in summary I'd say :

- for 1-to-1 or a few more people go with normal p2p WebRTC.

- for multiple people session, host your own Jitsi server (or rent one from 8x8 or other providers) & use the jitsi SDK/API to integrate it in your app


WebRTC includes things like NAT traversal, peer-to-peer.

IMO, don't forget to look at things like TokBox (Vonage), Twilio, and Agora. If you're just trying to get an MVP/POX, it's a lot easier to start with someone's API, then dig deeper into the details when you're ready.

WebRTC has some difficult-to-debug corner cases that these and APIs already handle for you. (Today I had to convince the boss to try one of the APIs for an MVP because I hit a bug where Chrome and Edge just stopped listening to the microphone. Thanks to these samples, I learned it wasn't our code.)


My favorite sample by far: https://webrtc.github.io/samples/src/content/devices/input-o...

I routinely hit it to validate my camera/audio options and confirm the audio is sounding good.


That was extremely loud from feedback amplifying. Are you doing this with headphones on?


Yup. Sorry probably shoulda noted that. :D


If I want to add WebRTC capabilities to an existing server, what's the simplest way of doing that? This is for a game, all I need is an unreliable RTCDataChannel


I used simple-peer [1] for sending coordinates between clients in a canvas painting game [2].

[1] https://github.com/feross/simple-peer

[2] https://github.com/justo-rivera/dibujio-client

Ps. Be sure to use a turn server besides a stun one, that was a big headache to get it working on mobile data


Awesome!!

I’m glad people are using the data channel for games; I always see people say “well we could have better networking but browsers only support TCP sockets” but that is not the case.

The most complicated bit is you will need TURN servers for some symmetric NAT cases; either host your own or use something like https://xirsys.com/


What language is the server in? You just need a WebRTC implementation and you should be good to go!


Any reason why this requires both Python and Nodejs?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: