Check out our Amazon Connect solution! Learn More

How to Integrate with the AppRTC Android Demo

By callstats on November 29, 2018

AppRTC is a WebRTC demo created by Google and Mozilla. It enables browsers to “talk” to each other using the WebRTC API. They make the source code for AppRTC readily available on Github, so you can try deploying it yourself.  

AppRTC demos are very popular among WebRTC developers in general, and many new and aspiring WebRTC developers start their journey with AppRTC. There is a particular propensity to implement AppRTC for Android, which makes sense given there were 178.1 billion mobile app downloads worldwide in 2017.

Even better, WebRTC developers that use AppRTC love to integrate with for WebRTC monitoring and analytics. But how exactly do they do it? Read on to find out.

Prerequisites for Using for Android

As of the time of this writing, in order to implement, you need to have a minimum SDK version of 21. You also need several libraries, including:

  1. WebRTC Native

  2. Android

  3. Autobanh Websocket

  4. JSON WebToken

  5. Spongy Castle

  6. EventBus

Collecting Credentials for

Once you have registered for an account with, it’s important to collect the credentials needs to properly monitor and analyze your application. Without the proper credentials, the application will not run.

Get a application id, key id, and token, The token may be hardcoded, or you may use a third-party to generate it and the authentication. Using a third-party can be daunting if you have not done it before, but this blog post can walk you through a breakdown of third-party authentication using JWT tokens.

Add the application id, key id, and token data to

Integration Steps:

  1. Clone or download the WebRTC Analytics Library for Android. This library includes an integration with the demo application and documentation on how to integrate the library with any WebRTC application.

  2. Add to your gradle dependencies.  

    implementation "io.callstats:callstats:<version>"

  3. Add the Google WebRTC prebuild library from JCenter to your gradle dependencies.

    implementation 'org.webrtc:google-webrtc:<version>'

  4. Add EventBus to your gradle dependencies.

    implementation 'org.greenrobot:eventbus:<version>'

    This step is optional, but recommended. EventBus is an android library that simplifies communication between activities, threads, and other services in your Android application. When your project is big, and you have several activities, threads, or services that you want to communicate between, you need to be careful in your implementation. Using the EventBus library minimizes development efforts and can simplify your process.  You can achieve the same goal without EventBus library, but we recommend it to save time and effort.

  5. Create a Callstats object.

    callstats = new Callstats(    context,    appID, // Application ID from Callstats    localID, // current user ID    deviceID, // unique device ID    jwt, // jwt from server for authentication    alias, // user alias    clientVersion, // user version    callstatsConfig) // Callstats config parameter
  6. Start a callstats session with a unique identifier. The appRTC room number room may serve as the unique identifier.

  7. Initiate a fabric setup event. Once the fabric setup is complete, is able to send data.

    // peerConnection - of type WebRTC peer connection// peerId - of type string - application specifc identifier for this peer connectioncallstats.addNewFabric(peerConnection, peerId)
  8. Send WebRTC Session Data

    1. WebRTC ICE Connection State Change

      callstats.reportEvent(peerId, new OnIceConnectionChange(newState))

    2. WebRTC ICE Gathering State Change

      callstats.reportEvent(peerId, new OnIceGatheringChange(newState))

    3. WebRTC Signaling State Change

      callstats.reportEvent(peerId, new OnSignalingChange(newState))

    4. On Add New Stream

      callstats.reportEvent(peerId, OnAddStream.INSTANCE);

    5. On Audio Mute and Unmute

      callstats.reportEvent(peerId, new OnAudio(isMuted, deviceId))

    6. On Video Play and Pause

      callstats.reportEvent(peerId, new OnVideo(isPaused, deviceId))

    7. On Fabric Hold

      callstats.reportEvent(peerId, OnHold.INSTANCE);

    8. On Fabric Resume

      callstats.reportEvent(peerId, OnResume.INSTANCE);

    9. To Send Custom Message

      // message - of type string// level - of type io.callstats.LoggingLevel// loggingType - of type io.callstats.LoggingTypecallstats.log(message, level, loggingType);

  9. Stop session monitoring when the AppRTC PeerConnection session ends.


Build and Run Your Android Application

  1. Build and run your Android application. In the demo, give your room a name and dial.

  2. Open a browser and join the same room from

  3. Check your dashboard for output from the WebRTC session.

You can find the most up-to-date integration instructions directly on the WebRTC Analytics Library for Android Github page.

If you have additional questions, check out our help center.

Visit our Help Center

Interested in learning more about Check out our product tour.

Try our Product Tour

Tags: WebRTC, AppRTC,, Android