Native WebRTC Development A Guide to libWebRTC and Alternatives

WebRTC enables developers to build powerful web-based real-time communication applications. While typically implemented in web browsers, you can also integrate this functionality into native applications by embedding the WebRTC standard into the application’s codebase. This is usually done using libWebRTC, an open-source project maintained by Google that provides a comprehensive implementation of the WebRTC protocols and APIs. 

In this post, we provide an overview of the process of building a native video chat application using libWebRTC along with best practices to follow. We also explore alternatives to libWebRTC from Google like React Native WebRTC and Flutter WebRTC, as well as independent ones such as Pion, WebRTC.rs and aiortc. 

WebRTC: Standard, Technology, and Developer Ecosystem

When talking about WebRTC, it’s important to understand that the term refers to a standard, a technology, and a developer ecosystem.

  • WebRTC as a standard refers to the work of organizations, like the Internet Engineering Task Force (IETF) and the World Wide Web Consortium (W3C), that define the ways for enabling real-time communication capabilities in the browser.
  • WebRTC as a technology refers to the Application Programming Interfaces (APIs) that you use to set up media streams and establish connections with other peers and servers.
  • WebRTC as developer ecosystem refers to the multiple vendors and libraries available to build real-communication applications.

In the same way, WebRTC as a technology refers to the implementation of the standard. There are multiple implementations but the most important one, given its presence and size as a project, is libWebRTC. 

libWebRTC is an open source project mainly maintained by Google, along with other companies such as Meta and Microsoft. It is written in C++/C. It is compatible with Windows, macOS, and Linux applications. It also has Java and Objective-C bindings for Android and iOS.

This is what you find in most web browsers. It is likely the one you end up using in web applications every time you call the getUserMedia method or instantiate RTCPeerConnection objects. 

As mentioned earlier, while it is usually implemented in web browsers, nothing prevents you from making your own copy of libWebRTC and adding it to your native application in order to enable real-time communication capabilities just as if you were in the browser. In fact, this is the approach followed by most Android and iOS applications that implement such features.

Also, vendors and CPaaS providers build their SDKs and libraries either based on libWebRTC or matching its capabilities and features.

What Does Building a WebRTC Native Application Look Like?

Getting started with the libWebRTC involves cloning the source, installing Google’s Depot Tools, and using gn and ninja for building the binaries. After that, you can package and add it as a library to your application codebase in order to use its features. 

From here on in, the process is similar to building web-based applications. The main difference is that you have full control over the inner workings. You can adapt them to your specific use case, rather than just relying on the browser’s implementation. 

Also, it’s up to you to decide which WebRTC release to use and how often you want to update.

However, this also comes with extra burden. For instance, you won’t be getting bug fixes or new features that are added upstream until you update or manually add these to your codebase. 

libWebRTC Best Practices 

By following some best practices, you can build the most reliable and high-performing native application using libWebRTC, while also contributing to the continuous improvement of the WebRTC ecosystem.

Some of the best practices you can follow are:

  • Maintain a separate libWebRTC codebase that serves as a starting point for local improvements and customizations
  • Control upgrade planning
  • Revisit upstream fixes and optimizations periodically
  • Contribute local fixes and improvements back to the upstream project

Alternatives to libWebRTC

libWebRTC provides a mature, well-tested implementation of the WebRTC standard. However,  in some scenarios it might not be the best option for building your native application. 

You may want to consider an alternative to libWebRTC when:

  • You are using a software stack that is not supported
  • You only need some of the features provided by the implementation
  • You don’t have the manpower to clone and maintain a libWebRTC implementation

In these cases, consider an implementation made by a different provider. For instance, the Pion WebRTC project provides a modular Golang implementation of the WebRTC API that you can use in your Go applications, while WebRTC.rs caters the same to Rust developers.

There are also options like the react-native-webrtc module or the flutter-webrtc plugin, which provide a managed implementation based on libwebrtc that frees you from the hassle of maintaining it.

Let’s explore a few of these in more detail.

React Native WebRTC

React Native WebRTC is a powerful module that enables developers to integrate real-time communication capabilities into their React Native applications. It supports various platforms, including Android, iOS, tvOS, and web, allowing developers to build cross-platform video and audio conferencing, data channels, and screen sharing features.

It offers a range of features, including audio and video communication, data channels, screen capture, and support for x86_64 and ARM architectures. 

Getting started with the react-native-webrtc module is as simple as installing the so-called npm package and following the instructions for the corresponding platform. The project provides detailed installation instructions and platform-specific guides to help developers get started quickly and easily.

Flutter WebRTC

Flutter WebRTC is a robust plugin that allows developers to integrate real-time communication capabilities into their Flutter applications across various platforms such as Android, iOS, Web, macOS, Windows, Linux, and even embedded systems.

It supports a wide range of features, including audio/video communication, data channels, screen capture, end-to-end encryption, and more. This ensures comprehensive functionality for building interactive communication applications.

Non-Google Implementations

The above alternatives build upon the libWebRTC official implementation by Google. Now, let’s take a look at some independent ones.

Pion

Pion WebRTC is a pure Go implementation of the WebRTC API. It provides a comprehensive set of features, including support for sending and receiving audio and video, data channels, ICE, STUN, TURN, and SRTP. It is easy to use and integrate with other Go projects, and it is supported on a wide range of platforms, including Windows, macOS, Linux, FreeBSD, iOS, Android, and WASM.

This implementation can be used for a wide variety of projects, including video conferencing applications, remote control systems, and streaming media players. It is a powerful tool for building real-time communication applications in Go.

WebRTC.rs

WebRTC.rs is a pure Rust implementation of the WebRTC stack, which rewrites the Pion stack in Rust. This project is still in active and early development, with a roadmap to track major milestones and releases. Examples provide code samples to show how to use webrtc-rs to build media and data channel applications.

The minimum supported Rust version is 1.65.0, and the project uses dual licensing under both MIT and Apache-2.0, which is the currently accepted standard by the Rust language community.

Aiortc

aiortc is a Python library for Web Real-Time Communication (WebRTC) and Object Real-Time Communication (ORTC) built on top of asyncio, Python’s standard asynchronous I/O framework. It provides a Pythonic API that closely follows its JavaScript counterpart, using coroutines instead of promises and emitting events using pyee.EventEmitter.

This implementation offers a simple and readable approach that serves as an excellent starting point for programmers seeking to understand WebRTC’s inner workings or experiment with its internals.

Enable Real-Time Communication Beyond the Browser

While WebRTC has gained prominence in the realm of browser-based applications, you’ve seen here how its capabilities can extend well beyond the web. By leveraging WebRTC in native applications, developers can create powerful, real-time communication experiences across a wide range of platforms and devices, opening up new opportunities for innovation and collaboration.

Our team at WebRTC.ventures has plenty of experience building both web-based and native WebRTC applications. Contact us today and let’s make it live!

Recent Blog Posts