PubSub silently drops connection right after getting any message


When I’m trying to connect to PubSub, everything works smoothly until I try to send any message over the websocket.
If I don’t send anything, websocket stays connected for about 15 seconds (or a little longer) and than drops (which is expected, as PubSub should drop connection if I don’t start listening to any topics).

Issue is, if I try to send any message - whether it is “LISTEN” or “PING” - PubSub instantly drops connection silently, without response or error. Just disconnects.

I couldn’t find any topic on google or this forum mentioning such an issue, so I’m posting this question here.

For reference, messages I send are looking like this:


   "type": "PING"


   "type": "LISTEN",
   "nonce": "1234",
   "data": {
      "topics": ["whispers.183987760"],
      "auth_token": "*********************************"

auth token is correct (just censored here for safety) and I know it, as I have 2nd websocket connecting to Twitch chat and it works like a charm.

I formatted code above adding only newlines and spaces for readability.

Any help or ideas what might be causing this will be greatly appreciated!

PS: To not open new topic, and somewhat by the way:
Is there a full list of possible topics to listen to in PubSub? Looked for it around but couldn’t find it, closest to it I found on PubSub docs site, but list there is just list of “topics requiring special scope” and same article mentions that ONLY SOME topics require special scopes, indicating list is much bigger. It might be just bad wording, but I prefer to ask to be sure - is there a full list of pubsub topics out there?

That wording is just out of date, as it predates some of the changes to the API in general.
There are no pubsub topics that require no scopes.

All pubsub topics require a relevant scope

The full list of topics available to third parties can be found at PubSub | Twitch Developers

You are JSON encoding and sending a string? Not an Object?

This example might help, written in nodeJS twitch_misc/pubsub at main · BarryCarlyon/twitch_misc · GitHub

That’s all I needed to know, thanks! I don’t need more scopes, just was confused by docs.

That’s the exact same link I’ve sent you… Anyhow, just needed to know if that’s a full list. Thanks!

Yes, I am JSON encoding the object, what I’ve sent here is string generated by it (just without quotation marks at the beginning and end of string and few extra spaces and newlines for readability).
I’m sending packet with encoded JSON string transcribed to UTF8.

Your example doesn’t help here much sadly (even though I’ll keep it open, as it’s much clearer than any other examples I’ve seen), as I did my portion of research and know how to connect and request - and it’s hard to compare any code taken I’m using Gdscript, not javascript.

As I said before, biggest issue is that pubsub drops the connection without any answer, which is behaviour I don’t recall seeing mentioned anywhere.

I wonder if it’s a problem with the game engine instead then.

In my example, you can change pubsub.on('close', function() { to pubsub.on('close', function(code, reason) {

And log the code/reason information checking against

Issue seems to be resolved! It was a small miss on my side, I forgot to set websocket write mode to WRITE_MODE_TEXT.
Leaving the message I wrote tho, just in case if some lost Godot soul would encounter similar issues.
Thank you for your help, despite this being such stupid newbie mistake.


That was my thoughts exactly. But it seems strange to me, that all other websocket connection works (like chat, for that matter), but this one doesn’t.

Sorry for the long time to response, had some stuff to do - but in the meantime I went deep into Godot code… and after finding code for websocket, it came out that:

  1. Despite Godot being written in C++, it uses javascript for websockets;
  2. Interestingly, onclose never fires. It’s not like it is ignored by godot, it just never actually gets called.
  3. Only way I found this in theory could be possible (although logically shouldn’t still happen), is if connection closes during polling, but it’s quite unclear. After all, no matter when connection is closed, it should fire onclose function.