Tried connecting to wss://irc-ws.chat.twitch.tv:443 but still same result.
I tried using this for testing and it seems to works fine (spent around 30 minutes without anything going wrong): https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo?hl=en
So yeah, I’m absolutely clueless what is going wrong. Some websocket clients are able to maintain a stable connection (like the google chrome extension I linked, and Ankhbot), and a friend of mine is able to maintain a stable connection using my code, but I’m having zero luck with my code. Unless someone has anything else I can try, I’ll give up on the websocket protocol and see how it goes connecting to Twitch chat using the IRC protocol.