Skip to main content

Installing the watchRTC Android SDK

watchRTC requires you to integrate an SDK with your own running code. For that purpose, you will need to add the watchRTC Android SDK to your Android application.


The SDK has been designed to be as efficient as possible and use minimal device resources. However, a mobile application can affect the SDK’s ability to collect stats and send events. With this in mind, there are a few things that you, as the developer, should consider before installing the SDK.

  1. Network connectivity: If the device is not connected to the internet, the SDK may not be able to send events or send them with delay.
  2. Implementation: If the SDK is not implemented correctly with any 3rd party web RTC libraries that are being used, it will hinder our ability to collect data.

To start using the watchRTC Android SDK library to collect WebRTC-related data from your Android app, you must first perform a few basic tasks. Then you can begin to log and analyze your data.

For integration with the SDK, you will first need to have a watchRTC API key. If you haven’t already done so, please make sure to create a watchRTC API key before you continue.

Install the SDK

Note: SDK support and requirement – Release – 1.0.0 (see changelog)
  • The minimum android version supported by the SDK is Android-7 (API Level 24)
  • SDL requires an Internet permission
  • Kotlin version 1.7.21

You will first need to add a remote binary as a dependency to your Android application. To do that, follow these steps:

  1. In your Android project, open the build.gradle file for the app module and add the binary as a dependency in the dependencies block.
    dependencies {implementation 'com.spearline:testrtc-watchrtc-sdk:1.0.0'}
  2. In the project-level build.gradle file, add the URL of the binary’s download location as a repository in the repositories block. This will typically look like this:
    repositories {mavenCentral()}
  3. Save your changes to the build.gradle file and then sync your project with Gradle. This will download the binary and add it as a dependency to your project.
  4. Once the binary has been added as a dependency, you can use it in your app by importing the appropriate package or classes and calling the relevant methods or functions.
Note: In general, you will need to add a dependency and a repository when you want to include a remote binary or library as a dependency in your Android project. This is because the dependency specifies the binary or library that your project depends on, and the repository is the location where Gradle can find the binary or library so it can be downloaded and added to your project.

Initialize the SDK

Once you have added the remote binary as a dependency to your Android application, you will now need to initialize the SDK. Before using any WebRTC APIs, you must add the following setup code to your application.

  • Implement the RtcDataProvider protocol
    private val rtcDataProvider = object : RtcDataProvider {
    override fun getStats(callback: GetStatsCallback) {
    // get stats report and call callback.onStatsAvailable(com.spearline.watchrtc.model.RTCStatsReport)
  • Initialize WatchRTCConfig with your API Key, Room ID, and Peer ID

    The watchRTC config must contain your API Key, Room ID, and Peer ID. The rest is optional.

    val config = WatchRTCConfig(
                "<keys>" //(optional)


  • Create WatchRTC object
    val watchRTC = WatchRTC(config, rtcDataProvider)
  • Connect to watchRTC’s servers.

    The connect() function may throw an IllegalStateException if a valid config is not set and you call this function.

    * The connect() method should be called only once the peer connection is active
    * The watchRTCConfig parameter is optional and should be passed only if an updated configuration is desired, or if it was not passed during the object's construction..
    watchRTC.connect(context, watchRTCConfig?)
  • Disconnect the call
    //Please call disconnect() once the call has been disconnected.watchRTC.disconnect()
  • Log WebRTC events to the watchRTC server.

    To publish events to the watchRTC server you can use the watchRTC.trace() function. This is a function that returns a Boolean value and takes two arguments: a String value and an optional Any value.

    1. The string value is the type of event that you want to send to WatchRTC’s backend.
    2. The Any value is used to send additional data related to the event to WatchRTC’s backend.
    watchRTC.trace(event, data)

    Here is the sample app code. This function may throw ConnectionException when facing an issue connecting to the server. Please handle this exception.

WatchRTC SDK sample applications

Some things to remember:

Was this article helpful?

0 out of 0 found this helpful