Search code examples
opentok

Multiple publishers in a session, how subscribe to just one?


I have an application that has multiple publishers and I want to go from one to the other, subscribe for a few seconds, and move on.
I put a unique id in the Data property when I created the tokens.

How can I select a specific stream from the session object?... or just how to I select the desired stream?


Solution

  • I think I have the answer but I'm not sure it's the best way.

    On the publisher streamCreated event, I capture the event.stream from the event in a hash table with the key set as the person's id. Then I call the subscribe method on session object and pass in the stream from the hash table and set the target to that of the publishing person's video.

    Seems to work fine but I've done so much guessing, I'm not sure if it's luck or correct!