Java

Subscribing to other client streams

We want clients to be able to subscribe to (or view) other clients’ streams in the session:

  1. Add a subscriber property to the MainActivity class (after the declaration of the publisher property):

The Subscriber class is defined in the Android SDK. It defines an object that a client uses to subscribe to (view) a stream published by another client.

  1. Modify the implementation of the onStreamReceived(session, stream) method (one of the SessionListener callbacks) to include code to subscribe to other clients’ streams the session:
  1. To log events Add subscriberListener property below sessionListener of the MainActivity:

When another client publishes a stream to a session, this method is called, and a Stream object is passed in. The Stream class is defined in the Android SDK, and it represents an audio-video stream in the session.

The code initializes an instance of the Subscriber class, defined in the Android SDK. The Subscriber.Builder() constructor takes two parameters:

  • The Android application context associated with this process.
  • The Stream object (for the stream you want to view)

The Session.subscribe(subscriber) method subscribes to the stream that was received.

subscriberViewContainer.addView(subscriber.getView()) places the new subscribed stream's view on the screen.

  1. Modify the implementation of the onStreamDropped(Session session, Stream stream) method (another one of the SessionListener callbacks):

subscriberViewContainer.removeAllViews() removes a subscriber's view once the stream has dropped.