Suggestions

close search

Back to Text Chat Overview

Text Chat Step 1: Set up text chat with the signalling API

  1. 1
    Text Chat Step 1:
    Set up text chat
  2. 2
    Text Chat Step 2:
    Implementing text chat
  3. 3
    Text Chat Step 3:
    Text Chat UI improvements

To see the code for this sample, switch to the signaling.step-1 branch of the learning-opentok-android repo:

git checkout signaling.step-1

This page shows the difference between this branch and the basics.step-6 branch, which this branch builds from.

The OpenTok signaling API lets clients send text messages to other clients connected to the OpenTok session. You can send a signal message to a specific client, or you can send a message to every client connected to the session.

In this branch, the following code is added to the initializeSession() method:

mSession.setSignalListener(this);

This sets the ChatActivity object as the implementor of the SubscriberKit.SignalListener interface. This interface defines the onSignalReceived(session, type, data, connection) methods. This method is called when the client receives a signal from the session:

@Override
public void onSignalReceived(Session session, String type, String data, Connection connection) {
    Toast toast = Toast.makeText(this, data, Toast.LENGTH_LONG);
    toast.show();
}

This app uses an android.widget.Toast object to display received signals.

In the onConnected(session) method, the following code sends a signal when the app connects to the session:

mSession.sendSignal("", "Hello, Signaling!");

This signal is sent to all clients connected to the session. The method has two parameters:

  1. 1
    Text Chat Step 1:
    Set up text chat
  2. 2
    Text Chat Step 2:
    Implementing text chat
  3. 3
    Text Chat Step 3:
    Text Chat UI improvements