Example of video conference client for Android

This example can be used to participate in video conference for three participants on Web Call Server and allows to publish WebRTC stream.

On the screenshot below the participant is connected, publishing a stream and playing streams from the other two participants.

Input fields required for connecting to WCS server and joining conference

Three videos are played

Volume control is located between the video elements.
Below are located controls for muting/unmuting audio and video for the published stream, input field for a text message and messages log.

Work with code of the example

To analyze the code, let's take class ConferenceActivity.java of the conference example version with hash 4ed4c6d77, which can be downloaded with corresponding build 1.0.1.3.

Unlike direct connection to server with method createSession(), , RoomManager object is used for managing connection to server and conference. Connection to server is established when RoomManager object is created, and method RoomManager.join() is called for joining a conference.
When joining, Room object is created for work with the "room". Participant objects are used for work with conference participants.
All events occurring in the "room" (a user joined/left, or sent a message), are sent to all users connected to the "room".

For example, in the following code, a user joins to a "room" and gets the list of already connected users.

room = roomManager.join(roomOptions);
room.on(new RoomEvent() {
    public void onState(final Room room) {
        for (final Participant participant : room.getParticipants()) {
    ...


ParticipantView (SurfaceViewRenderer + TextView - line 613) is assigned for each of the other participants, to display the name and video stream of that participant (Bob and Cindy on the screenshot above).

1. Initialization of the API. line 98

Flashphoner.init(this);


For initialization, object Сontext is passed to the init() method.

2. Connection to server.

RoomManager object and session for connection to server are created when Connect button is clicked. line 145

roomManager = Flashphoner.createRoomManager(roomManagerOptions);


RoomManager object is created with method createRoomManager(), to which RoomManagerOptions object (line 139) with the following parameters is passed

Callback functions, which make appropriate changes in controls of the interface, are added for session events (line 150)

roomManager.on(new RoomManagerEvent() {
    public void onConnected(final Connection connection) {
        .....
    }
    public void onDisconnection(final Connection connection) {
        .....
    }
});


3. Joining a conference. line 145

After establishing connection to the server, method connection.join() is used to join the conference.
To join, name of the conference room is passed to the method. (The name can be specified as parameter in the URL of the client page; otherwise, random name will be generated.)

The user joins a conference when Join button is clicked.
To join, method RoomManager.join() is called. RoomOptions object (line 240) with the name of the conference room is passed to the method.

room = roomManager.join(roomOptions);


Callback functions for conference room events are added (line 254)

In callback function onState(),

room.on(new RoomEvent() {
    public void onState(final Room room) {
        .....
    }
    public void onJoined(final Participant participant) {
        .....
    }
    public void onLeft(final Participant participant) {
        .....
    }
    public void onPublished(final Participant participant) {
        .....
    }
    public void onFailed(Room room, final String info) {
        .....
    }
    public void onMessage(final Message message) {
        .....
    }
});


4. Video streaming. line 479

Video stream publication is started when Publish button is clicked.

stream = room.publish(localRenderer);


Method Room.publish() is called to publish a stream. SurfaceViewRenderer to be used to display video from the camera is passed to the method.

Callback function for processing stream statuses is added. (line 484)

publishStream.on(new StreamStatusEvent() {
    @Override
    public void onStreamStatus(final Stream stream, final StreamStatus streamStatus) {
        runOnUiThread(new Runnable() { 
            @Override 
            public void run() { 
                if (StreamStatus.PUBLISHING.equals(streamStatus)) {
                    .....
                }
        }
    }
});


5. Playback of video stream. line 376

When one of the conference participants starts publishing, method Participant.play() is used to start playback of that stream.
SurfaceViewRenderer, in which the video will be displayed, is passed to the method.

participant.play(participantView.surfaceViewRenderer);


6. Stop of streaming. line 518

The following method is called to stop video streaming when Unpublish button is clicked.

room.unpublish();


7. Leaving conference room. line 416

Method room.leave() is called for leaving conference room when Leave button is clicked.
Handler for processing response from server-side REST application is passed to the method.

room.leave(new RestAppCommunicator.Handler() {
    public void onAccepted(Data data) {
        ......
    }
    public void onRejected(Data data) {
        ......
    }
});


8. Disconnection. line 213

Method RoomManager.disconnect() is called to close connection to the server.

roomManager.disconnect();


9. Mute/unmute audio and video of the published stream. line 533, line 548

The following methods are used to mute/unmute audio and video

10. Sending text message. line 599

Method Participant.sendMessage() is used for sending text message to other participants. Message text is passed to the method.

When Send button is clicked,

for (Participant participant : room.getParticipants()) {
    participant.sendMessage(text);
}


11. Adjusting the volume line 100

The following methods are used to adjust the volume