Using Pure JS under Wordpress doesn’t work well.
To call the API requires a token.
And to get a token you are either a server, or you are logging the user in.
You don’t want to have to login a user just to get a Live Stream status.
So heres what I would do
- Use EventSub to collect Stream Up/Down into wordpress options/config table.
- Feed that to the frontend to display as needed
Or
- Generate a Client Credentails token https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow
- Store that in wp options
Then either
-
Long Poll the streams API and cache that data into options using WPCtron
-
Use a WP action callback to call the API using the token at page load time to lookup the streams you are interested in. And cache that too
-
Front end calls your Wordpress backend vai an API/Cron Style