You can use WebRTC facilities in Android Environment with the help of Native Android WebRTC SDK.

This SDK,  simplified and adapted version of famous AppRTC project, provides peer to peer WebRTC communication between Android devices and browsers by using Ant Media server as a signaling server. This document describes first how to run the Demo App and then gives more detailed information about SDK.

How to Use WebRTC SDK in Native Android App? 1

Run the Demo App


In order to use WebRTC Android SDK, you need WebRTC Android SDK for sure and Ant Media Server Enterprise Edition. Please contact us at  We can provide Enterprise Edition for trial.

Start the Ant Media Server Enterprise Edition

Extract the Android Media Server Enterprise Edition and start the server with command in the terminal

cd /path/to/ant-media-server


Open the WebRTC Android Demo in Android Studio

  • Open the project in Android Studio
  • Install the Android Demo App to your Device
  • Click Settings button on the right top

WebRTC WebSocket

  • Scroll Down to Screen until you see Room server URL and click that item

How to Use WebRTC SDK in Native Android App? 2

  • Enter the Ant Media Server Enterprise Edition Server IP to the dialog and Click OK

How to Use WebRTC SDK in Native Android App? 3


  • Close the app and go to the App Permissions from System’s Application Manger and give all permissions to Android AppRTC App

How to Use WebRTC SDK in Native Android App? 4

  • Open the AppRTC app again and Enter a room name like “room1” and press phone icon

How to Use WebRTC SDK in Native Android App? 5

  • AppRTC should connect to the Ant Media Server and waits for the other peer to connect


  • The other peer should connect to same room in order to create a peer to peer connection.
    You may install the AppRTC to any other android device and connect to room1 or
    you may go to the http://SERVER_IP:5080/WebRTCAppEE/peer.html, write “room1” in the textbox and click “join”  on the web page.


  • Peer to Peer Connection should be established and you should see and talk to other peer.

More Information about Android WebRTC SDK

Take a look at the CallActivity class to see the sample usage of the Android SDK.


There are 3 types of broadcast scenarios, therefore, operating modes.

  • Peer Connection (Two nodes connect to each other, 1-1 connection)
  • Publish (One node publishes, 1-N connection)
  • Play (Other nodes play broadcast from publisher,1-N connection)

According to the projects or needs, the developer can implement one or all modes in their applications.

Configuration Parameters

In order to create WebSocket connection, two groups of parameters should be implemented successfully. These are minimal and mandatory configurations to establish a connection.
Except them, the developer can set other optional functional and GUI parameters.

Such as:

setCam2 (param); //boolean

setVideoResolution (param);

setVideoCodec (param);

Signaling Parameters

The first group of parameters is signaling parameters. These parameters consist of below variables;

public SignalingParameters(List iceServers, boolean initiator,
                     String clientId, String wssUrl, String wssPostUrl, 
                     SessionDescription offerSdp,List iceCandidates) {
   this.iceServers = iceServers;
   this.initiator = initiator;
   this.clientId = clientId;
   this.wssUrl = wssUrl;
   this.wssPostUrl = wssPostUrl;
   this.offerSdp = offerSdp;
   this.iceCandidates = iceCandidates;

In fact, the developer does not need to define any of these parameters. The SDK creates and defines required parameters for connection in the backend.

The only parameter that developer may need to define is Stun Server parameter. This parameter is set as “” by default, if it is needed to set this value, just call the below method:


Connection Parameters

The second group of parameters is Connection Parameters which are;

  • streamId (Broadcast name)
  • url (WebSocket Url of Server)
  • mode (Operating Modes)

WebSocket server URLs may change according to communication medium, for example in secure environment, URL starts with “wss” instead of “ws” also port number changes to “8082” by default it is “8081”

Also “join”,”publish”,”play” mode values should be used for Peer, Publish and Play Operating modes.

WebRTCClient Implementation

First, you need to create a webRTCClient instance in your application:

 public WebRTCClient(boolean loopback, String roomId, IWebRTCListener webRTCListener, Context context) 
       this(loopback, roomId, webRTCListener, context);   }

 webRTCClient = new WebRTCClient(loopback, roomId, this, Activity.this);

loopback: Should be false in the default application
roomId: This is stream id
this: IWebRTCListener object
Activity.this: Your application activity

Then, create UI elements in your activity.


 SurfaceViewRenderer pipRenderer = findViewById(;  //This is for your own display
 SurfaceViewRenderer fullscreenRenderer = findViewById(;  //This is for your remote display

 callFragment = new CallFragment();
 hudFragment = new HudFragment();

 webRTCClient.setVideoRenderers(pipRenderer, fullscreenRenderer);


 FragmentTransaction ft = getFragmentManager().beginTransaction();
 ft.add(, callFragment);
 ft.add(, hudFragment);

Finally, start the stream.

webRTCClient.startStream(url, roomId, mode);

url: WebSocket URL
roomId: Stream Id
mode: Peer, Publish or Play

We hope this tutorial will be helpful for you, if you have any question, just send an email to 🙂

Categories: Tutorial