Chrome Extension - XMLHttpRequest

Hello, This is my first post here. But i decided to ask a question before I will publish my chrome extension on Chrome Web Store.

My extension is checking is stream online by XMLHttpRequest and GET method. I have a streamer ID and client ID from my Twitch panel which i generated. And now i need to sending query each second is stream live or not.

Do you have any idea to replace setInterval function because it looks little risky. When i will publish my extension 50 people can generating a lot of XMLHttpRequest each second. Twitch can understand it as DDOS or spam and ban IP adress? Dose API have any socket to minimize this spam or allows it?

I used documentation from here: https://dev.twitch.tv/docs/v5/reference/streams/#get-stream-by-channel
And all Twitch API requests are in v5.

If you want some code feel free to ask about it. I don’t really know which pieces of code may of interest to you

The API is cached so it doesn’t sense to check whether a streamer is live or not every second - delaying it to once every 3-5 minutes would probably be best because you’re exactly right, if your app is checking every second and 50 people are using it, then your clientID has 50 polls/second on it which is huge.

As I predicted. I tested earlier this refreshing Twitch API and saw this ‘delay’ with updating informations in API. My stream was live in about 2 or 3 minutes and it was still offline in API. Thanks for answer!

Of course 50 users is an example value i hope it will be much more users. But now I can make ‘delay’ and avoid DDOS and ip banned.

Yeah - ultimately, the ideal way to do it would be to have a server set up where your extension routes through, and the server gives the response to the extension but also caches it - so if any other extensions make the same call within next few minutes, they get it straight from your server, rather than polling Twitch API again.

Something along those lines would help as even if you have, say, 500 users, you can start running into the same problems.

I don’t run anything large scale though so my insight is limited to regurgitation :slight_smile:

You may be right BUT.
On server you have limits too so if you will redirect traffic you can be in the same sittuation. You only lengthening the way of request. But I don’t know really to. Maybe it’s the best solution.

Still waiting for someone else reply but thanks a lot :slight_smile:

There’s no need to worry about it too much. Limit the requests to one every few minutes (since more often than that is useless anyway). As long as you’re not actually trying to abuse the API, you should be fine. I do more requests than that alone in my personal applications.

I hope it so but still need a confirmed answer by the Twitch Staff… maybe

@3ventic is Twitch Staff.

Admin, not dev success

I would stay within the 1 requests/second rule for your integration. Agree with @3ventic that you should just limit the requests to one every few minutes, cache the result, and request info from cache or update based on your last cached time. That’s going to be the best way to approach it.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.