FIXED: Websocket DAT not receiving all/full messages

I’ve been banging my head about this for a couple of weeks now, really hoping someone can help me find the cause.

I’m using a lovely app called Streamer.Bot to subscribe to events that happen on our Twitch channel (eg. subscriptions, bit donations, etc).
All of these events come in fine EXCEPT for bit donations over 200 bits. Those only come in sporadically, and only up to about 300 bits, sometimes 400 bits. Anything larger, and the Websocket DAT simply ignores it (nothing shows up in the table)

UPDATE: newer version of TD now receives the messages, but they’re truncated to 1016 characters. See further down.



Here’s an example of a message that arrives without problem. It is from a 169 bit donation:

{"timeStamp":"2022-05-24T21:08:05.8983488-07:00","event":{"source":"Twitch","type":"Cheer"},"data":{"message":{"msgId":"21605e47-16d2-4496-8001-509438e1b41c","userId":441952335,"username":"dandidoesit","role":1,"subscriber":true,"displayName":"DandiDoesIt","channel":"dandidoesit","message":"Cheer100 Cheer69","isHighlighted":false,"isMe":false,"isCustomReward":false,"isAnonymous":false,"isReply":false,"bits":169,"hasBits":true,"emotes":[],"cheerEmotes":[{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":0,"endIndex":7,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":69,"color":"#979797","type":"CheerEmote","name":"Cheer","startIndex":9,"endIndex":15,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/1/4.gif"}]}}}

Here’s an example of a message that does not arrive to the DAT. It is from a 1000 bit donation:

{"timeStamp":"2022-05-24T21:09:25.420042-07:00","event":{"source":"Twitch","type":"Cheer"},"data":{"message":{"msgId":"21605e47-16d2-4496-8001-509438e1b41c","userId":444739367,"username":"bleachedblond","role":1,"subscriber":true,"displayName":"BLEACHEDblond","channel":"dandidoesit","message":"Cheer100 Cheer100 Cheer100 Cheer100 Cheer100 Cheer100 Cheer100 Cheer100 Cheer100 Cheer100","isHighlighted":false,"isMe":false,"isCustomReward":false,"isAnonymous":false,"isReply":false,"bits":1000,"hasBits":true,"emotes":[],"cheerEmotes":[{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":0,"endIndex":7,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":9,"endIndex":16,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":18,"endIndex":25,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":27,"endIndex":34,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":36,"endIndex":43,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":45,"endIndex":52,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":54,"endIndex":61,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":63,"endIndex":70,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":72,"endIndex":79,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"},{"bits":100,"color":"#9c3ee8","type":"CheerEmote","name":"Cheer","startIndex":81,"endIndex":88,"imageUrl":"https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/100/4.gif"}]}}}

The only thing that stands out to me about bigger bit donation messages is that they’re longer. Does the websockets DAT have some kind of length/size limitation? Why does it like the first message but ignores the second one? The reason I know the second message is being sent is that when using a generic js websocket listener in an html page to test, the message shows up fine.

Does anyone have any hints?

Hey @matijaerceg

I just gave it a try (in 2022.24200) with that second longer message from one machine to the other, using WebSocket, and the message went through.

Which build are you using?

Best,
Michel

Hi @JetXS

I upgraded, and the messages started appearing in the websockets DAT (thanks for the suggestion), but now it would appear they’re being truncated:

They are all 1016 characters long. Not only that, but after a few of these test messages, the Websocket DAT stops responding, and I have to toggle the Active parameter. This is a bug, right?

Does it have to do with using the websocket c# library, per .net - How to disable forced continutation frames using websocket-sharp in C# - Stack Overflow

?

They are only being truncated in the row, if you add a select and convert your cell to text and then beautify using the JSON DAT, you can see it is not truncated.

I’m unable to reproduce that. Could be that your system is unstable and you lose the connection for some reason? Or some rate limitation somewhere that throttle the sending API?

Not quite sure to follow here. C# is not involved in TouchDesigner.

Still getting a truncated message with select + convert, and then the json after that spits out an error:

Furthermore, in my websocket callbacks I use json.loads(message) and that gives an error also:

json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 956 (char 955)

To add more info, the attached HTML listener that uses javascript always receives the full message, while TouchDesigner only receives/shows the truncated message. This is with the same event from the websocket server that both the .html and TD are listening to.

HTML file in zip: cheertest.zip (790 Bytes)

So I know that my websocket server is sending out a full message, but somewhere along the way, before showing up in the websocket DAT’s table, it seems to be getting cut short.

Why would this HTML file receive and display the whole message, but TD only the first 1016 characters?

It should be just visually truncated. If you add the JSON DAT after the Conver DAT, what do you see?

In your WebSocket DAT callback, do you use onReceiveText or onReceiveBinary?

As mentioned, the JSON DAT after Convert DAT gives an error “Failed to parse DAT as JSON”

In the callback, I use onReceiveText.

Here’s how my test html file sees the message/event:

And here’s what the exact same message/event looks like in TD after a select, convert to text:

It’s being truncated at exactly 1016 chars.

Does the message come in okay through the callback?

Can you share your project so we can try to reproduce? So far I haven’t been able to reproduce the issue locally.

It doesn’t come in okay anywhere in TD.

Here’s a new .toe file that exhibits the same issue when listening to Streamer.Bot v0.1.7.

matija-websocket.toe (4.7 KB)

Let me know if you’d like help setting up Streamer.Bot to test, it’s pretty straightforward to turn on its Websocket server.

Thanks, just wanted to verify. I’ll take a look.

Thanks - if you want to create these twitch events easily, in Streamer.Bot just click on Settings > Events > Cheers and then put in a number like 500:

That’ll give you a nice long message over 1016 characters.

Additional info, if I connect to Streamer.Bot’s websocket server using Online Websockets Tester - Debug Client Tool and subscribe to events with

{
		"request":"Subscribe",
		"id":"1234",
		"events":{
			"Twitch":[
				"Follow",
				"Cheer",
				"Raid",
				"Host",
				"FirstWord",
				"ChatMessage",
				"Sub",
				"ReSub",
				"GiftSub",
				"GiftBomb",
				"HypeTrainStart",
				"HypeTrainUpdate",
				"HypeTrainLevelUp",
				"HypeTrainEnd",
				"RewardRedemption"
			],
			"StreamElements":[
				"Tip"
			]
		}
	}

I also receive the full event message untruncated. So it would seem the glitch is on TD’s end.

Thanks, I was able to reproduce with that. I’ve implemented a fix which will be in the next official build we release, 2022.24270+.

Thank you Eric! Is there any chance at all I would be able to get my hands on a build in the meantime? We’re supposed to launch a show this Friday with this functionality.

Yeah I can do that. I’ll send you one once it’s available.

1 Like

Hey @matijaerceg

Here is a link to the build with the fix if you want to give it a try: Dropbox - File Deleted - Simplify your life

Best,
Michel

1 Like

@eric.b @JetXS thank you very much for the fast fix! It’s working now, and messages are coming in at full length!

I and the streamer.bot dev are curious whether it was a library issue, or a setting issue, or something else (in case other people/apps ever have issues receiving messages from streamer.bot’s websocket server)?

I and the streamer.bot dev are curious whether it was a library issue, or a setting issue, or something else (in case other people/apps ever have issues receiving messages from streamer.bot’s websocket server)?

The bug was on our end and was with the handling of fragmented WebSocket messages.

1 Like