0

The application that i m developing is mixture of both multiparty and broadcasting. There will be a single particular admin/host who's stream is subscribed by all the subscribers(Broadcasting). Both the host/publisher as well as all the subscribers will be able to see all the participants in the session(sort of multiparty). On event from the host/publisher such as button click etc, the publisher will now stop publishing his/her stream and all the subscriber will view the stream from a particular subscriber in the session that the host selects. Since my application uses android SDK and does not have moderator token. How can i succeed creating the application i desire.( (note: I have already completed Basic audio,video chat ) Can you provide me with necessary methods and sample code to pull it off.

I used the following codes:

private HashMap<String, Stream> mStringStreams = new HashMap<String, Stream>();
 @Override
    public void onStreamReceived(Session session, final Stream stream) {

        Log.d(LOG_TAG, "onStreamReceived: New Stream Received " + stream.getStreamId() + " in session: " + session.getSessionId()+" Stream name: "+stream.getName());

           if(stream.getName().equalsIgnoreCase("Main_stream"))
            {
                    mSubscriber = new Subscriber.Builder(SuscriberActivity.this, stream).build();
                    mSession.subscribe(mSubscriber);
                    mSubscriberViewContainer.addView(mSubscriber.getView());

            }
        if (mSubscribers.size() + 1 > MAX_NUM_SUBSCRIBERS ) {
            Toast.makeText(this, "New subscriber ignored. MAX_NUM_SUBSCRIBERS limit reached.", Toast.LENGTH_LONG).show();
            return;
        }
        if(stream.getName().compareTo("Main_stream")!=0)
        {

            final Subscriber subscriber = new Subscriber.Builder(SuscriberActivity.this, stream).build();
            mStringStreams.put(stream.getStreamId().toString(), stream);
            mSession.subscribe(subscriber);
            mSubscribers.add(subscriber);
            mSubscriberStreams.put(stream,subscriber);
            int position = mSubscribers.size() - 1;
            final int id = getResources().getIdentifier("subscriberview" + (new Integer(position)).toString(), "id", SuscriberActivity.this.getPackageName());
            FrameLayout subscriberViewContainer = (FrameLayout) findViewById(id);
            subscriber.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
            subscriberViewContainer.addView(subscriber.getView());
        }

 @Override
   public void onSignalReceived(Session session, String s, String s1, Connection connection) {
stream = mSubscriberStreams.get(s1).getStream();
          Stream stream= mStringStreams.get(s1);
             Subscriber mSubscriber1 = new Subscriber.Builder(SuscriberActivity.this, stream).build();
            mSubscriber1.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
            mSubscriberViewContainer.removeView(mPublisher.getView());
            mSubscriberViewContainer.addView(mSubscriber1.getView().getRootView());

        }
    }

1 Answers1

0

If I understand correctly, you're trying to enable participants to subscribe to a different stream when the publisher(main host) clicks on a button. To accomplish this, you can use the OpenTok Signaling API to send a signal with the streamId as the data to all participants so they can subscribe to that specific user.

Manik
  • 1,495
  • 11
  • 19
  • After Sending the streamID to all the clients, what methods should i use to subscribe to that stream as the streamID is a string and the API requires stream to build a subscriber. In other words , how do i use the streamId to subscribe to that stream? – Ribesh Mhrzn Feb 09 '18 at 07:54
  • You can map the `streamId` to it's corresponding `event.stream` data each time a `streamCreated` event is fired. This way when anyone gets a signal with `streamId` as the data, they should be able to subscribe to the stream as long as they have the `streamId`:`event.stream` in the hashMap – Manik Feb 10 '18 at 17:10
  • i have added codes to my question/post. Can you please review it. the code is not working but doesn't show any error while building app. – Ribesh Mhrzn Feb 11 '18 at 05:28