@Override
  protected void onStreamDropped(Stream stream) {
    MySubscriber p = mSubscriberStream.get(stream);
    if (p != null) {
      mSubscribers.remove(p);
      mSubscriberStream.remove(stream);
      mSubscriberConnection.remove(stream.getConnection().getConnectionId());
      mPagerAdapter.notifyDataSetChanged();

      presentText("\n" + p.getName() + " has left the chat");
    }
  }
 @Override
 public void setPrimaryItem(ViewGroup container, int position, Object object) {
   for (MySubscriber p : mSubscribers) {
     if (p == object) {
       if (!p.getSubscribeToVideo()) {
         p.setSubscribeToVideo(true);
       }
     } else {
       if (p.getSubscribeToVideo()) {
         p.setSubscribeToVideo(false);
       }
     }
   }
 }
  @Override
  protected void onSignalReceived(String type, String data, Connection connection) {

    if (type != null && "chat".equals(type) && connection != null) {
      String mycid = this.getConnection().getConnectionId();
      String cid = connection.getConnectionId();
      if (!cid.equals(mycid)) {
        MySubscriber p = mSubscriberConnection.get(cid);
        if (p != null) {
          presentMessage(p.getName(), data);
        }
      }
    }
  }
  @Override
  protected void onStreamReceived(Stream stream) {
    MySubscriber p = new MySubscriber(mContext, stream);

    // we can use connection data to obtain each user id
    p.setUserId(stream.getConnection().getData());

    // Subscribe audio only if we have more than one player
    if (mSubscribers.size() != 0) {
      p.setSubscribeToVideo(false);
    }

    // Subscribe to this player
    this.subscribe(p);

    mSubscribers.add(p);
    mSubscriberStream.put(stream, p);
    mSubscriberConnection.put(stream.getConnection().getConnectionId(), p);
    mPagerAdapter.notifyDataSetChanged();

    presentText("\n" + p.getName() + " has joined the chat");
  }
 @Override
 public void destroyItem(ViewGroup container, int position, Object object) {
   MySubscriber p = (MySubscriber) object;
   container.removeView(p.getView());
 }
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   MySubscriber p = mSubscribers.get(position);
   container.addView(p.getView());
   return p;
 }