Inconsistent PubSub Broadcast Behavior, MESSAGE missing from Frames

Issue:
I am experiencing an issue where
twitch.ext.listen("broadcast", function(){})
fails to fire ~80% in my app after an update to EBS.

Details:
Using the network tab of the developer tools, I deduced (hopefully correctly) that my EBS broadcast function, request('https://api.twitch.tv/extensions/message/${channelId}'), is responsible for causing the GET wss://pubsub-edge.twitch.tv/v1 requests to occur. And I believe the requests wss://pubsub-edge.twitch.tv/v1 are what causes the twitch.ext.listen function to sometimes fire.

It seems like the 20% when twitch.ext.listen("broadcast", function(){}) successfully fires, the “Frames” tab of the GET wss://pubsub-edge.twitch.tv/v1 request looks like this, where MESSAGE is included as a list item:

However, when twitch.ext.listen("broadcast", function(){}) fails to fire, the Frames" tab of the GET wss://pubsub-edge.twitch.tv/v1 request looks this (note MESSAGE is missing):

Anybody know what the issue is here? I notice that the MESSAGE takes a lot more time to complete/fire. Is there a way I can “wait” for it somehow or speed up its response time? Thanks.



More Information on my Extensions: (not sure if this info is necessary.)
In my frontend code, in App.js, I set up the listener in componentDidMount like so
(It is almost identical to the one used here in extensions-boilerplate):

componentWillMount() {
    if (this.twitch) {
      this.twitch.listen("broadcast", function(){})
    }
  }

After making any update calls to my backend, I make sure to call my sendBroadcast function so I can get the listener to run.

Here is what my EBS sendBroadcast function looks like (It is almost identical to the one used here in extensions-hello-world):

function sendBroadcast(channelId) {
  // Set the HTTP headers required by the Twitch API.
  const headers = {
    "Client-ID": clientId,
    "Content-Type": "application/json",
    Authorization: bearerPrefix + makeServerToken(channelId)
  };

  // Create the POST body for the Twitch API request.
  const body = JSON.stringify({
    content_type: "application/json",
    message: store[channelId],
    targets: ["broadcast"]
  });

  // Send the broadcast request to the Twitch API.
  request(
    `https://api.twitch.tv/extensions/message/${channelId}`,
    {
      method: "POST",
      headers,
      body
    });
}

twitch.ext.listen is fired just once on componntDidMount call. What is fired after update to EBS is function(){}.

The v1 connection you are refering to is a websocket to pub/sub. It’ll receive all messages from channel that your app registered to. This means that you’ll start getting all "brodcast" messages if you fired twitch.ext.listen("broadcast", ...) at least once (and of course didn’t cancel it by firing twitch.ext.unlisten).

On the first sight your code looks ok, and there isn’t enough detail to determine what is the cause. I se are two potential reasons:

  • there is a bug in your backend service that fails to publish new messages to PUB/SUB
  • this.twitch is not available when you try to call this.twitch.listen in the componentDidMount. How do you inject twitch lib to your component?