Skip to main content

Android Precompiled WebRTC Library

Introduction

The Telnyx Android Precompiled WebRTC Library is a pre-compiled version of the WebRTC framework specifically optimized for Android development. This library provides the core WebRTC functionality needed to build real-time communication applications on Android without having to compile the WebRTC source code yourself.

Unlike the full Telnyx Android WebRTC SDK, which provides a complete solution for integrating with Telnyx outbound, inbound voice call services, the precompiled library focuses solely on providing the WebRTC foundation. This gives developers more flexibility to build custom WebRTC implementations while still benefiting from Telnyx's optimized WebRTC build.

Key Differences

WebRTC Precompiled Library by Telnyx

  • Provides only the core WebRTC functionality
  • Requires manual implementation of signaling and connection management
  • Offers more flexibility for custom implementations
  • Suitable for developers who need fine-grained control over WebRTC behavior
  • Requires more development effort to integrate with Telnyx services

Telnyx Android WebRTC SDK

  • Complete solution for Telnyx voice services
  • Includes signaling, authentication, and call management
  • Simplified API for making and receiving calls
  • Handles WebRTC complexities automatically
  • Recommended for most developers integrating with Telnyx

API Documentation

For detailed information about the available classes and methods in the precompiled library, refer to the auto-generated API documentation:

WebRTC Android API Documentation

Integration Guide

Adding the Library to Your Project

Using Gradle

Add the following to your project's root build.gradle file:

allprojects {
repositories {
mavenCentral()
}
}

Then, add the dependency to your app module's build.gradle file:

dependencies {
implementation 'com.telnyx.webrtc.lib:library:1.0.1'
}

Using Maven

Add the JitPack repository to your pom.xml file:

<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

Then add the dependency:

<dependency>
<groupId>com.telnyx.webrtc.lib</groupId>
<artifactId>library</artifactId>
<version>1.0.1</version>
</dependency>

Required Permissions

Add the following permissions to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" /> <!-- If using video -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Basic Usage Example

Here's a basic example of how to establish a peer connection using the precompiled WebRTC library:

import com.telnyx.webrtc.lib.*;

public class WebRTCExample {
private PeerConnectionFactory peerConnectionFactory;
private PeerConnection peerConnection;
private MediaStream localMediaStream;
private VideoTrack localVideoTrack;
private AudioTrack localAudioTrack;

public void initializeWebRTC(Context context) {
// Initialize PeerConnectionFactory
PeerConnectionFactory.InitializationOptions initOptions =
PeerConnectionFactory.InitializationOptions.builder(context)
.setEnableInternalTracer(true)
.createInitializationOptions();
PeerConnectionFactory.initialize(initOptions);

// Create PeerConnectionFactory
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
peerConnectionFactory = PeerConnectionFactory.builder()
.setOptions(options)
.createPeerConnectionFactory();

// Create MediaConstraints
MediaConstraints constraints = new MediaConstraints();
constraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
constraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));

// Create PeerConnection
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(
Arrays.asList(
PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer()
)
);

peerConnection = peerConnectionFactory.createPeerConnection(
rtcConfig,
new PeerConnection.Observer() {
@Override
public void onIceCandidate(IceCandidate iceCandidate) {
// Send ice candidate to remote peer via signaling
}

@Override
public void onAddStream(MediaStream mediaStream) {
// Handle remote media stream
}

// Implement other required methods...
}
);

// Create local media stream
localMediaStream = peerConnectionFactory.createLocalMediaStream("local_stream");

// Add audio and video tracks (if needed)
AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
localAudioTrack = peerConnectionFactory.createAudioTrack("audio_track", audioSource);
localMediaStream.addTrack(localAudioTrack);

// Add stream to peer connection
peerConnection.addStream(localMediaStream);
}

public void createOffer() {
MediaConstraints constraints = new MediaConstraints();
constraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
constraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));

peerConnection.createOffer(new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
peerConnection.setLocalDescription(new SdpObserver() {
@Override
public void onSetSuccess() {
// Send offer to remote peer via signaling
}

@Override
public void onCreateSuccess(SessionDescription sessionDescription) {}

@Override
public void onSetFailure(String s) {}

@Override
public void onCreateFailure(String s) {}
}, sessionDescription);
}

@Override
public void onSetSuccess() {}

@Override
public void onCreateFailure(String s) {}

@Override
public void onSetFailure(String s) {}
}, constraints);
}
}

When to Use the Precompiled Library vs. Telnyx SDK

Use the Precompiled Library When:

  • You need complete control over the WebRTC implementation
  • You're building a custom signaling solution
  • You're implementing specific WebRTC features not available in the Telnyx SDK
  • You're migrating from another WebRTC implementation and want to maintain your architecture

Use the Telnyx Android WebRTC SDK When:

  • You want to quickly integrate with Telnyx voice services
  • You need a complete, ready-to-use solution
  • You don't want to manage WebRTC complexities
  • You need features like call management, authentication, and signaling
  • You want to minimize development time and effort

GitHub Repository

For more information, examples, and to access the source code, visit the GitHub repository:

Telnyx WebRTC Android Precompiled Library

Additional Resources