As part of a larger project, our team at WebRTC.ventures had the opportunity to develop a native Android SDK to expand SignalWire’s WebRTC capabilities beyond its existing React Native solution. This SDK provides a platform-specific implementation tailored to Android, allowing us to address mobile-specific challenges, such as handling variable network conditions and optimizing real-time performance. 

In this post, we’ll share how we approached the project, from selecting Kotlin as the development language to overcoming technical challenges and achieving robust, mobile-first functionality.

About SignalWire

Founded by the creators of the open-source project FreeSWITCH, SignalWire is a communications platform that provides APIs for voice, video, and messaging applications, commonly used by developers like us at WebRTC.ventures for real-time communications and contact center solutions. SignalWire is a great choice for building communications features due to its flexibility and developer-friendly ecosystem, with strengths in:

  • Scalability: Designed to handle high volumes of simultaneous communications, SignalWire supports scaling effortlessly from a few users to tens of thousands.
  • Cost-Effectiveness: SignalWire’s transparent pricing model helps developers predict and manage costs, paying only for what they use as their app grows.

Project Context: Creating a Native Android SDK

SignalWire’s existing Relay Mobile SDK, developed for React Native, served as our reference point. Our goal was to create a native Android SDK that maintained the core Relay SDK features while optimizing for mobile use, particularly in low-bandwidth and satellite communication environments.

Here’s how we approached the project:

  1. Reverse Engineering: We analyzed SignalWire’s JavaScript and React Native SDK to accurately reproduce its functionality in Kotlin.
  2. Platform Migration: The React Native implementation was translated into a native Android architecture.
  3. Specialized Use Cases: We focused on optimizing the SDK for low-bandwidth and satellite communication, retaining the original SDK’s specialized performance characteristics.

Key Development Challenges

Creating a native Android SDK involved overcoming several unique challenges:

1. Feature Replication

We aimed for complete feature parity with SignalWire’s existing React Native SDK, ensuring the new SDK supported the same functionalities while providing mobile-specific optimizations.

2. Optimizing for Low-Bandwidth Environments

To ensure call clarity and stability in constrained network scenarios, we implemented Android-specific optimizations, particularly for satellite and limited connectivity environments.

3. Security

Protecting user data was a top priority. We integrated security measures such as encryption to keep calls private and user data secure.

WebRTC Basics: The Foundation of Our SDK

Building this SDK required a deep understanding of WebRTC’s essential components:

  • Signaling: Responsible for setting up calls, we designed a signaling manager to handle messages like connection requests and call setups efficiently.
  • Network Layer: We configured STUN and TURN servers to ensure robust connectivity, even in challenging network conditions.
  • Session Management: We implemented a session controller to handle audio and video connections, supporting actions like muting and call termination smoothly.

Why We Chose Kotlin

We chose Kotlin as the primary language for this SDK due to its suitability for Android development:

  • Performance: Kotlin provides better control and lower latency than React Native, essential for smooth WebRTC experiences.
  • Customization: Building in Kotlin allows for Android-specific features and enhancements, such as optimizing video quality and stream processing.
  • Quick Updates: Kotlin allows developers to easily integrate new Android features as they’re released, ensuring SDK updates are timely.

Structuring the SDK for Usability and Efficiency

A well-structured SDK helps developers integrate and maintain it easily. Here’s the module structure we created:

  • API Module: Manages communication with SignalWire services, including WebSockets for signaling.
  • Service Module: Handles WebRTC connections, including STUN and TURN server setup.
  • Repository Module: Simplifies data fetching and interactions with SignalWire’s APIs.
  • Use Case Module: Contains business logic and calls functions from the repository.
  • ViewModel Module: Manages UI-related information and interactions.

Below is a sample of how we structured the SDK’s signaling session:

class CallRepository(private val signalingManager: SignalingManager) {

    // Start a signaling session
    fun startSignalingSession() {
        signalingManager.initializePeerConnection()
        signalingManager.sendOffer()
    }

    // Handle incoming signals
    fun handleIncomingSignal(signal: Signal) {
        when (signal.type) {
            SignalType.OFFER -> signalingManager.receiveOffer(signal.sdp)
            SignalType.ANSWER -> signalingManager.receiveAnswer(signal.sdp)
            SignalType.ICE_CANDIDATE -> signalingManager.addIceCandidate(signal.iceCandidate)
        }
    }

    // End a signaling session
    fun endSignalingSession() {
        signalingManager.closePeerConnection()
    }
}

Connecting to the Signaling Server

Connecting to SignalWire’s signaling server through WebSockets enables real-time communication setup. Here’s how we configured it:

class SignalingManager(private val signalingServerUrl: String) {
    private lateinit var webSocket: WebSocket

    // Connect to the signaling server
    fun connectToSignalingServer() {
        val request = Request.Builder().url(signalingServerUrl).build()
        webSocket = OkHttpClient().newWebSocket(request, object : WebSocketListener() {
            override fun onOpen(webSocket: WebSocket, response: Response) {
                println("Connected to signaling server")
            }

            override fun onMessage(webSocket: WebSocket, text: String) {
                handleSignalingMessage(text)
            }
        })
    }
}

Enhancing Mobile Communication

This custom-built SignalWire SDK for Android demonstrates our team’s capability to extend real-time communication features in mobile applications tailored to client needs. Developed with a streamlined architecture in Kotlin and leveraging SignalWire’s WebRTC infrastructure, this SDK enables high-performance, mobile-first solutions that connect users seamlessly across devices.

For our client, this SDK provides a reliable, robust foundation within their Android application, harnessing SignalWire’s infrastructure to create a unique communication experience. This project showcases how we can design specialized, scalable solutions that open new possibilities in mobile real-time communication.

The WebRTC.ventures team is here to help you unlock the full potential of a native Android solution tailored to your specific needs. Contact us today to explore how we can create a high-performance SDK that seamlessly integrates real-time communications into your mobile platform.

Recent Blog Posts