Building an interactive application? There’s more than one WebRTC programming language like Python that can fit your needs.
Last time I’ve written about WebRTC programming languages it was some two years ago. My focus then was how programming languages fit to different WebRTC components. That article is still relevant, so I suggest you read it as well.
This time, I want to focus on something slightly different. In recent months I’ve had the pleasure of watching as well as consulting teams of developers who are using programming languages that don’t always make sense to me when it comes to WebRTC. And yet, once they explained their reasoning, the decision and path they took would be one I couldn’t just dismiss if I were in their shoes.
Instead of doing this one by component, lets do it by language:
There are two main places where you see JaveScript in WebRTC apps today: client side as well as signaling server.
Client side is simple enough. It is due to the fact that this is how you use WebRTC in browsers, but it can also be seen in cross platform mobile development (though not that much) or when using Electron for WebRTC.
Signaling servers is about Node.js. And yes, the guest article from 2013 (!) is as relevant now as it was then. Twelephone (mentioned in that article) is long dead, and Chris has moved on to IOT and later decentralized networks. But the use of Node.js as a signaling server for WebRTC is going strong. If you take that route, just make sure to pick a popular framework.
I’ve seen Node.js being used in media servers as well:
- mediasoup for example, is an open source SFU that was built as a Node.js module to fit into a larger application
- SwitchRTC, a commercial SFU that got acquired by YouNow, was a combination of C/C++ and Node.js
- appear.in’s SFU (available for their PRO accounts) was built using Node.js
I’ll be using C and C++ together here, as I don’t see a huge distinction between the two (and in most cases, those that develop code in C create C++ abstractions, and those developing in C++ end up writing C code anyways).
C/C++ is a kind of a lowest common denominator. My guess is that a lot of the languages here have their compilers/interpreters written in C/C++ anyways. It is also a language that is available everywhere, though not always accessible directly.
Go to webrtc.org and you’ll find out that the code WebRTC that Google open sourced is written in C++. The easiest thing to do if you want to support WebRTC on an embedded device is probably to start by taking that code and hammering it until it fits your device.
It isn’t the only way to get WebRTC into a device but it sure is a popular one.
Signaling with C++ isn’t common. Where you will find it is when SIP meets WebRTC.
Interestingly, all main open source SIP servers are written in C/C++: Asterisk, OpenSIPS and FreeSWITCH.
I am assuming this is because they are older than other WebRTC signaling implementations that tend to use higher languages.
NAT traversal servers are written today in C/C++.
Not all of them. But the most popular one is (coturn).
Media servers need to be highly performant, which is why most of them also end up being written in C/C++ – at least the parts that matter for performance.
- Janus, a popular media server is written in C
- SwitchRTC mentioned in relation to Node.js has a C++ component to it handling all media networking
- Kurento’s core is written in C/C++
- CPaaS vendors are using C/C++ in their media servers – at least those that I know the programming languages that they use
Java is the most popular language based on the TIOBE index.
I don’t like Java that much, probably due to its verbosity and all the pain that its garbage collection causes to real time apps. But I don’t get to decide what others use 🙁
Java is probably one of the most popular programming languages also in WebRTC backend development, but not only there.
Android requires Java, which means Android native development with WebRTC also requires Java coding.
Besides this obvious option, there’s also the part of writing WebRTC clients in Java from scratch.
While you won’t find any open source Java client for WebRTC, I know of two separate WebRTC client implementations that use Java.
There are many signaling servers out there that end up using Java when it comes to WebRTC. You’ll find it in enterprise software but not only.
A few of them are also open sourced, though there isn’t a specific one that is widely popular or highly recommended as far as I can tell.
If you need some training on how to get WebRTC signaling working, then I suggest the WebRTC Codelab course. It makes use of Node.js but its focus is on understanding why things are done they way they are, so you can translate the teachings there to any language you use.
Several of the media servers out there use Java. Either for everything or for the higher level abstractions.
Here are two of them:
- Jitsi is written in Java
- OpenVidu, an SFU implemented on top of Kurento by the Kurento maintainers is written in Java
If Java is needed for development of WebRTC in Android, then Swift is what you need for iOS.
Unless you’re fine with using Objective-C and not adopt Swift.
Other than iOS, I haven’t seen Swift used anywhere else when it comes to WebRTC implementations (or otherwise for that matter).
As a higher level language, Python gets high marks. I’ve been introduced to it about a decade ago and loved it since, though I can’t say I used it too much myself.
When it comes to WebRTC, Python has its role in signaling servers, as many other higher level languages.
The most notable Python project related to WebRTC is [matrix]. Its open source Synapse server implementation is written in Python.
There are others using Python for their signaling. My guess is that this is just because of familiarity with the language.
You can’t mention Python without mentioning Ruby.
I am guessing that Ruby can fit in signaling servers just as well as Python. Only difference is that I know of no one that is doing that.
If someone is making use of a Windows based development stack, he is more likely to use C# than anything else.
In such cases, you will see the use of C# for all aspects of WebRTC – from native WebRTC client implementations, through signaling, to NAT traversal and media servers.
I am not a big fan of backend development on Windows, but if you are one of those who need it, then know you are not alone.
Having such huge market share means more haters, especially when the language itself isn’t the most modern one out there.
What surprised me (it shouldn’t, but it did), was that there are companies who use PHP for their signaling server when it comes to WebRTC. I would never have thought that would be the case, but it is.
If you want to use PHP for your signaling server, then go for it. Just make sure you understand the limitations and implications of it.
We’re getting into the more exotic alternatives.
Erlang is such a programming language to me. Created by Ericsson and open sourced ages ago, Erlang offers some interesting capabilities (go read Wikipedia).
There are a few projects out there that make use of Erlang for signaling and one for NAT traversal. I am not aware of anyone using Erlang in a production service, though I am sure there is.
Elixir is built on top of Erlang (or at least on its virtual machine).
Only one I know who makes use of it for WebRTC is Slack.
In last year’s Kranky Geek event, Slack shared their plans of migrating from their Janus implementation to an in-house developed Elixir media server. You can watch that here:
Go is a programming language created by Google. It is somewhere between C and C++ as much as I can tell (never been an expert in Go).
This one came to my attention with the recent implementation of STUN/TURN in Go – Pion TURN.
Not sure how popular is Go with WebRTC developers.
Where do these languages fit?
I tried taking the information above and placing it in an easy to use table, to give a quick summary of the state of WebRTC programming languages.
- Green indicates a popular choice
- Orange indicates an alternative that I’ve seen being used in the wild (or in production)
- Gray is something I haven’t seen used at all
Which language should you use?
I am sure I missed a language or two. And I am also sure some people are using WebRTC programing languages differently than I’ve described here. Feel free to share in the comments for this article or by emailing me about it – I’d love to learn more.
What programming language should you use?
That’s a different question. I’d say it depends on several factors:
- What is it you are implementing and for which devices?
- What do your current developers know and are comfortable with?
- What is your operational envelope for the service?
- Are there any popular open source or commercial products for WebRTC in that language?
- How easy will it be to find experienced developers for that language? How about developers who know both this language and WebRTC?