Hi, I’m looking to start building a Streamelements widget that helps the Broadcaster choosing a random subscriber that is currently watching the stream. I didn’t find anything into the documentation, but I’ve seen widgets that are working with current viewers so there must be something somewhere.
How can I retrieve a list of current viewers? If not possible via official Twitch APIs, is there another method?
There are no API endpoints to see who is watching the stream. There are some apps that use the list of chatters and assume they are viewing the stream, but really that list only represents users connected to chat and logged in to Twitch, it does not mean that they are actually watching the stream as they could be connected to chat through a 3rd party chat client, or Twitch’s popout chat, or have the stream paused, or even be a bot and not capable of watching the stream at all.
No Just “user x last sent a message at time y” then when you want to pick a user
Grab all users whom have a time > z stored.
Or just keep a list of recent chatters and remove people from the list whose last message was x time ago.
It works “properly” what I meant was that a subscriber could write a message in chat.
Then leave the stream.
So why would you want to pick a subscriber whom “appears” to not be there as they have not paticipated in chat.
No point picking Fred 1 hour into the stream if Fred only said hello at the start of the stream. Fred probably left, so Fred might never see that Fred got picked. As Fred then “dies on stream” at 2 hours in the Fred starts watching the strem at 3 hours in (and writes messages in chat) Then Fred is unhappy as Fred missed Fred’s character being played on stream.
Mechanically it works fine.
But depending on your “how long ago someone wrote a message” window is, you could still theoretically pick a user whom has left the stream. So 5/10/15 minutes is a good rule of thumb for victim selection based on last message sent to chat.