Edit: This was indeed a silly mistake on my end
I’m running into a little trouble using the provided JS Helpers. What I’m trying to do is unbind a PubSub topic listener when the video has been paused, and then rebind a listener when the video is unpaused.
What happens with the code below is:
- Refresh the channel page, and I can see onContext() fire in the console; its first
changed
contents include “isPaused” but the matching context value isfalse
. At this point I can send a PubSub message from mylive_config
and it’s received as expected on the channel page. - The video is paused, and I can see the appropriate changed/context values. I send another PubSub message, but it isn’t received. So far so good.
- The video is unpaused, the appropriate changed/context values are seen. Another PubSub message is sent, but now it’s being received four times. If the video is paused/unpaused again, and another message sent, it is received eight times in total, and so on.
What am I misunderstanding, or how can I help troubleshoot more?
const broadcastListener = (target, contentType, message) => {
console.log("PubSub received:", message);
};
window.Twitch.ext.onContext((context, changed) => {
if (changed.includes("isPaused") && context.isPaused) {
window.Twitch.ext.unlisten("broadcast", broadcastListener);
} else if (changed.includes("isPaused") && !context.isPaused) {
window.Twitch.ext.listen("broadcast", broadcastListener);
}
});