I’m building a simple extension that gets the game currently played before matching it with an external API to show other info about it.
When the extension loads for the first time, it tries to get the game played from twitch.ext.onContext, but it’s always undefined.
After that, when the streamer updates the game currently played, in the stream option, the callback happens properly and I get the game name, so all good here. My issue is with the initial failure in getting the game name.
I don’t use the rig and here are relevant part of code (I think):
You need to set your onContext top level. Not inside a function. It will fire once when it first loads but you miss that opportunity if you leave it in a sub function.
Thanks @WLG3R, I’ve tested adding it directly in a script tag on the index.html page (I’m on local test right now, so script tags do fire properly), but no success, I get the exact same result.
Do you reckon this is the correct way of getting the game currently played, on page load?
Thanks Barry, I’ve just tried understanding what’s up with your test kit.
As some of my earlier testing showed, context.game is just an empty string (until the streamer updates the game played in the stream setting).
Any idea where to go from here? Do you have to authenticate in any way before being able to access this data? Would seem weird, as all other data get passed easily.
Seems I am also suffering from this. onContext always has an empty string for game for me. At least if the stream is started with the same game as before. Such as someone playing the same game every day. Even over 30min later it was still firing back an empty string. It seemed to only return the correct game if the game was switched while live.
That’s not a bad Idea. I was trying to think a way to use EventSub so my backend could just get notifications of the streamer being live and changing games and storing and then sending a pubsub /broadcast to the specific channel when it changes. but I just found out that this wasn’t working right when I was ready to submit. I had tested onContext but it was while live and just assumed the game field was correct. Then I found out it wasn’t. If they have some changes for me to make I will look into implement using the helix token to do an API call when first loading the UI. that isn’t a bad solution. It’s always nice to get the notifications automatically but it will work. Since it doesn’t seem like this issue is going to be fixed any time soon.